Example: Requesting an Inventory of Hardware Components Using a NETCONF Perl Client Application
The NETCONF Perl distribution includes several sample Perl scripts
to perform various functions on devices running Junos OS. The get_chassis_inventory.pl
script retrieves and displays
a detailed inventory of the hardware components installed in a routing,
swtiching, or security platform. It is equivalent to issuing the show chassis hardware detail operational mode
command.
After establishing a connection to the NETCONF server, the script defines get_chassis_inventory as the request to send and includes the detail argument:
my $query = "get_chassis_inventory"; my %queryargs = ( 'detail' => 1 );
The script sends the query and assigns the results to the $res variable. It performs two tests on the results, and prints an error message if it cannot send the request or if errors occurred when executing it. If no errors occurred, the script uses XSLT to transform the results.
# send the command and get the server response my $res = $jnx->$query(%queryargs); print "Server request: \n $jnx->{'request'}\n Server response: \n $jnx->{'server_response'} \n"; # print the server response into xmlfile print_response($xmlfile, $jnx->{'server_response'}); # See if you got an error if ($jnx->has_error) { croak "ERROR: in processing request \n $jnx->{'request'} \n"; } else { # Transform the server response using XSL file my $res = new Net::Netconf::Transform(); print "Transforming ...\n"; my $nm = $res->translateXSLtoRelease('xmlns:lc', $xslfile, "$xslfile.tmp", $xmlfile); if ($nm) { format_by_xslt($nm, $xmlfile, ); } else { print STDERR "ERROR: Invalid XSL File $xslfile\n"; } } # Disconnect from the Netconf server $jnx->disconnect();