Request an Inventory of Hardware Components Using Junos XML Protocol Perl Client Applications
The Junos XML protocol Perl distribution includes several sample
Perl scripts that 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. The output
is equivalent to issuing the show chassis hardware detail
operational mode command in the Junos OS command-line interface
(CLI). This topic describes the portion of the script that executes
the query.
After establishing a connection to the Junos XML protocol
server, the script sends the get_chassis_inventory
request 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 occur,
the script uses XSLT to transform the results. For more information,
see Parsing and Formatting Junos XML Protocol
Server Responses in Perl Client Applications.
# send the command and receive a XML::DOM object my $res = $jnx->$query( %queryargs ); unless ( ref $res ) { die "ERROR: $deviceinfo{hostname}: failed to execute command $query.\n"; } # Check and see if there were any errors in executing the command. my $err = $res->getFirstError( ); if ($err) { print STDERR "ERROR: $deviceinfo{'hostname'} - ", $err->{message}, "\n"; } else { # Now do the transformation using XSLT ... code that uses XSLT to process results ... }