Overview of the JUNOS Perl Module and Sample Scripts
The JUNOScript Perl distribution uses the same directory structure for Perl modules as the Comprehensive Perl Archive Network (http://www.cpan.org/). This includes a lib directory for the JUNOS module and its supporting files, and an examples directory for the sample scripts.
The JUNOS module implements an object (JUNOS::Device) that client applications can use to communicate with a JUNOScript server. The library contains several modules, but client applications directly invoke only the JUNOS::Device object. All of the sample scripts use this object.
The sample scripts illustrate how to perform the following functions:
- diagnose_bgp.pl—Illustrates how to write scripts to monitor routing platform status and diagnose problems. The sample script extracts and displays information about a routing platform’s unestablished BGP peers from the full set of BGP configuration data. The script is provided in the examples/diagnose_bgp directory in the JUNOScript Perl distribution.
- get_chassis_inventory.pl—Illustrates how to use one of the predefined Perl methods to request JUNOS information from a routing platform. The sample script invokes the get_chassis_inventory method with the detail option to request the same information as the <get-chassis-inventory><detail/></get-chassis-inventory> tag sequence from the JUNOS Extensible Markup Language (XML) application programming interface (API) and the show chassis hardware detail command from the JUNOS command-line interface (CLI). The script is provided in the examples/get_chassis_inventory directory in the JUNOScript Perl distribution. For a list of all Perl methods available in a release of the JUNOS XML API, see the JUNOS XML API Operational Reference.
- load_configuration.pl—Illustrates how to change routing platform configuration by loading a file that contains configuration data formatted with JUNOS XML tag elements. The distribution includes two sample configuration files, set_login_user_foo.xml and set_login_class_bar.xml; however, you can specify another JUNOS XML configuration file on the command line. The script is provided in the examples/load_configuration directory in the JUNOScript Perl distribution.
The following sample scripts are used together to illustrate how to store and retrieve data from the JUNOS XML API (or any XML-tagged data set) in a relational database. Although these scripts create and manipulate MySQL tables, the data manipulation techniques that they illustrate apply to any relational database. The scripts are provided in the examples/RDB directory in the JUNOScript Perl distribution:
- get_config.pl—Illustrates how to retrieve routing platform configuration information.
- make_tables.pl—Generates a set of Structured Query Language (SQL) statements for creating relational database tables.
- pop_tables.pl—Populates existing relational database tables with data extracted from a specified XML file.
- unpop_tables.pl—Transforms data stored in a relational database table into XML and writes it to a file.
For instructions on running the scripts, see the README or README.html file included in the JUNOScript Perl distribution.