Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?


Understanding the Junos XML Protocol Perl Distribution and Sample Scripts

Juniper Networks provides a Perl module JUNOS::Device to enable you to develop custom Perl scripts for configuring and monitoring Junos devices. The module implements a JUNOS::Device object that client applications can use to communicate with the Junos XML protocol server on a Junos device. The Perl distribution includes several sample Perl scripts, which illustrate how to use the module in scripts that perform various functions.


Starting in Junos OS Release 22.1R1 and Junos OS Evolved Release 22.1R1, we no longer provide the Junos XML protocol Perl client for download. To use Perl to manage Junos devices, use the NETCONF Perl library instead. For more information, see Understanding the NETCONF Perl Client and Sample Scripts.

The Junos XML protocol Perl distribution uses the same directory structure for Perl modules as the Comprehensive Perl Archive Network. This includes a lib directory for the JUNOS module and its supporting files, and an examples directory for the sample scripts.

Client applications use the JUNOS::Device object to communicate with a Junos XML protocol 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:

  •—Illustrates how to write scripts to monitor device status and diagnose problems. The sample script extracts and displays information about a device’s unestablished Border Gateway Protocol (BGP) peers from the full set of BGP configuration data. The script is in the examples/diagnose_bgp directory in the Junos XML protocol Perl distribution.

  •—Illustrates how to use a predefined query to request information from a device. The sample script invokes the get_chassis_inventory method with the detail option to request the same information as the Junos XML get-chassis-inventorydetail/get-chassis-inventory tag sequence and the command-line interface (CLI) operational mode command show chassis hardware detail. The script is in the examples/get_chassis_inventory directory in the Junos XML protocol Perl distribution.

  •—Illustrates how to change a device configuration by loading a file that contains configuration data formatted with Junos XML tag elements. The distribution includes two sample configuration files, set_login_class_bar.xml and set_login_user_foo.xml; however, you can specify a different configuration file on the command line. The script is in the examples/load_configuration directory in the Junos XML protocol 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 Perl distribution:

  •—Illustrates how to retrieve routing platform configuration information.

  •—Generates a set of Structured Query Language (SQL) statements for creating relational database tables.

  •—Populates existing relational database tables with data extracted from a specified XML file.

  •—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 Perl distribution.