Junos Automation Scripts Overview
Junos automation consists of a suite of tools used to automate operational and configuration tasks on network devices running the Junos® operating system (Junos OS). The Junos automation toolkit is part of the standard Junos OS available on all switches, routers, and security devices running Junos OS. Junos automation tools, which leverage the native XML capabilities of Junos OS, include commit scripts and macros, operation (op) scripts, event policies and event scripts, and SNMP scripts.
Junos automation simplifies complex configurations and reduces potential configuration errors. It saves time by automating operational and configuration tasks. It also speeds troubleshooting and maximizes network uptime by warning of potential problems and automatically responding to system events.
Junos automation can capture the knowledge and expertise of experienced network operators and administrators and allow a business to leverage this combined expertise across the organization.
Junos automation scripts can be written in the following scripting languages:
Extensible Stylesheet Language Transformations (XSLT)
Stylesheet Language Alternative syntaX (SLAX)
XSLT is a standard for processing Extensible Markup Language (XML) data and is designed to convert one XML document into another. SLAX is an alternative to XSLT. It has a simple syntax that follows the style of C and PERL, but retains the same semantics as XSLT. Programmers who are familiar with C often find it easier to learn and use SLAX. You can easily convert SLAX scripts into XSLT and convert XSLT scripts into SLAX. Python is a commonly-used, open-source programming language with extensive standard and community libraries. On devices running Junos OS, Python automation scripts can leverage Junos PyEZ APIs to simplify many operational and configuration tasks.
The following sections describe the different types of functionality for Junos automation:
Junos Configuration Automation: Commit Scripts
Junos configuration automation uses commit scripts to automate the commit process. Junos OS commit scripts enforce custom configuration rules. When a candidate configuration is committed, it is inspected by each active commit script. If a configuration violates your custom rules, the script can instruct Junos OS to take appropriate action. A commit script can perform the following actions:
Generate and display custom warning messages to the user
Generate and log custom system log (syslog) messages
Change the configuration to conform to the custom configuration rules
Generate a commit error and halt the commit operation
Commit scripts, when used in conjunction with macros, allow you to simplify the Junos configuration and, at the same time, extend it with your own custom configuration syntax.
Junos Operations Automation: Op Scripts
Junos operations automation uses op scripts to automate operational tasks and network troubleshooting. Junos OS op scripts can be executed manually in the CLI or upon user login, or they can be called from another script. Op scripts can process user arguments and can be constructed to:
Create custom operational mode commands
Execute a series of operational mode commands
Customize the output of operational mode commands
Shorten troubleshooting time by gathering operational information and iteratively narrowing down the cause of a network problem
Perform controlled configuration changes
Monitor the overall status of a device by creating a general operation script that periodically checks network warning parameters, such as high CPU usage.
Junos Event Automation: Event Scripts and Event Policy
Junos event automation uses event policies and event scripts to instruct Junos OS to perform actions in response to system events.
An event policy is an if-then-else construct that defines actions to be executed by the software on receipt of an event such as a system log message or SNMP trap. Event policies can be executed in response to a single system event or to correlated system events. For each policy, you can configure multiple actions including:
Ignore the event
Upload a file to a specified destination
Execute Junos OS operational mode commands
Execute Junos OS event scripts
Modify the configuration
Junos OS event scripts are triggered automatically by defined event policies in response to a system event and can instruct Junos OS to take immediate action. An event script automates network troubleshooting and network management by:
Automatically diagnosing and fixing problems in the network
Monitoring the overall status of a device
Running automatically as part of an event policy that detects periodic error conditions
Changing the configuration in response to a problem
Junos SNMP Automation: SNMP Scripts
Junos OS SNMP scripts provide the flexibility to support custom MIBs. SNMP scripts are triggered automatically when the SNMP manager requests information from the SNMP agent for an object identifier (OID) that is mapped to an SNMP script for an unsupported OID. The script acts like an SNMP subagent, and the system sends the return value from the script to the network management system (NMS).
You can map an SNMP script to one or more OIDs using the oid statement at the [edit system scripts snmp file script-name] hierarchy level.