TEST_1,10.56.7.80 TEST_3,10.66.78.10 TEST_4,10.66.81.9 TEST_2,10.67.9.12 #### 01,TEST_1,10.56.7.80 02,TEST_3,10.66.251.9 03,TEST_5,10.66.81.9 #### use strict; use warnings; use feature qw(say); use autodie; use XML::Twig; use LWP::UserAgent; use HTTP::Headers; use HTTP::Request; use File::Slurp; use JSON -support_by_pp; use LWP 5.64; use MIME::Base64; use IO::Socket::SSL; use File::Slurp; my ($file_1, $file_2) = ('output1.csv', 'output2.csv'); open my $fh, '<', $file_1 or die "Can't open $file_1: $!"; my %first = map { chomp; split /\s*,\s*/ } <$fh>; open $fh, '<', $file_2 or die "Can't open $file_2: $!"; my %second = map { chomp; (split /\s*,\s*/)[1,2] } <$fh>; #Create a user agent object my $ua = LWP::UserAgent->new(ssl_opts=> { SSL_verify_mode => SSL_VERIFY_NONE(), verify_hostname => 0, }); foreach my $name (sort keys %first) { if (not exists $second{$name}) { say "Devices should be added: $name"; next; } if ($first{$name} eq $second{$name}) { say "Match found $name, $first{$name}"; } else { say "UPDATE need be done for $second{$name}"; #### open ( my $input_1, '<', 'output1.csv' ) or die $!; while ( <$input_1> ) { chomp; my ($name_1, $ip_1) = split /,/; (my $id, $first{$name}, $second{$name}) = split /,/; my $xml = XML::Twig -> new -> parsefile ( 'example.xml' ); $xml ->set_pretty_print('indented_a'); open ( my $input_2, '<', 'output2.csv' ) or die $!; while ( <$input_2> ) { chomp; $xml -> root -> set_att('name', $name_1); $xml -> get_xpath('//ipaddress',0) -> set_text($ip_1); my $uri="https://hostname:9060/ers/config/networkdevice/$id"; my $req = HTTP::Request->new('PUT', $uri, [Accept=>'application/vnd.com.cisco.ise.network.networkdevice.1.1+xml', Content_Type=>'application/vnd.com.cisco.ise.network.networkdevice.1.1+xml; charset=utf-8'], $xml->sprint); $req->content($xml->sprint); $req->authorization_basic("user", "user"); #Pass request to the user agent and get a response back #Pass request to the user agent and get a response back my $res = $ua->request($req); #Check the outcome of the response if ($res->is_success) { print $res->status_line, "\n"; } else { print $res->status_line, "\n"; } } } } } #### UPDATE need be done for 10.66.251.9 404 Not Found 404 Not Found 404 Not Found 404 Not Found 404 Not Found 404 Not Found Match found TEST_1,10.56.7.80 #### UPDATE need be done for 10.66.251.9 UPDATE need be done for 10.66.81.9 200 ok 200 ok Match found TEST_1,10.56.7.80 Devices should be added: Test2