Example: Request 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, switching, or security platform. It is equivalent to issuing
the show chassis hardware detail operational mode command in the
Junos OS CLI. This topic describes the portion of the script that executes the
query.
After establishing a connection to the NETCONF server,
the script sends the get_chassis_inventory request and includes the detail argument.
my $query = "get_chassis_inventory"; my %queryargs = ( 'detail' => 'True' );
When using the release-independent NETCONF Perl distribution, to include a fixed-form option when invoking a method, set the option equal to the value 1 (one).
The script sends the query and assigns the return value to the $res variable. The script first prints the RPC request
and response to standard output, then it prints the response to the
specified file. The script then checks for and prints any error encountered.
my $res; # Netconf server response
# 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 {
print "Server Response:";
print "$res";
}
# Disconnect from the Netconf server
$jnx->disconnect();