Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

Executing Event Scripts in an Event Policy

 

Event scripts are Extensible Stylesheet Language Transformations (XSLT) scripts, Stylesheet Language Alternative syntaX (SLAX) scripts, or Python scripts that an event policy can execute when it is triggered. Event scripts can perform any function available through Junos XML or Junos XML protocol remote procedure calls (RPCs). Additionally, you can pass to an event script a set of arguments that you define.

Event scripts can build and run an operational mode command, receive the command output, inspect the output, and determine the next appropriate action. This process can be repeated until the source of the problem is determined. The script can then report the source of the problem to you on the CLI or automatically change the device configuration.

You can configure an event policy that executes event scripts and uploads the output of those scripts to a specified location for analysis. To configure such a policy, include the following statements at the [edit event-options] hierarchy level:

In the events statement, you can list multiple events. If one or more of the listed events occurs, the eventd process executes the actions configured under the then hierarchy. The event policy actions can include executing one or more event scripts, which are configured by including the event-script filename statement. The eventd process runs the scripts in the order in which they appear in the configuration. The scripts that you reference in the event-script statement must be located in the /var/db/scripts/event directory on the device’s hard disk or the /config/scripts/event/ directory in flash memory Furthermore, the event scripts must be enabled at the [edit event-options event-script file] hierarchy level. For more information, see Storing and Enabling Scripts.

Note

If the scripts are located in flash memory, you must configure the load-scripts-from-flash statement at the [edit system scripts] hierarchy level.

Note

For detailed information about the requirements and restrictions when executing Python automation scripts on devices running Junos OS, see Requirements for Executing Python Automation Scripts on Devices Running Junos OS.

You can configure the arguments statement to pass arguments to an event script as name/value pairs. The argument values can include variables that contain information about the triggering event or other received events. The event script can then reference this information during execution. For detailed information about passing arguments to event scripts, see Configuring an Event Policy to Pass Arguments to an Event Script.

You can configure event scripts to write their output to a file. When the eventd process executes the scripts, it uploads the file with the script output to the location specified in the destination statement. In the destination statement, include a destination name that is configured at the [edit event-options destinations] hierarchy level. For more information, see Example: Defining Destinations for File Archiving by Event Policies.

In the output-filename statement, define a descriptive string that will be included in the filename. Each uploaded file also includes the hostname and timestamp in the filename to ensure that the each filename is unique. If a policy is triggered multiple times in a 1-second period, an index number is appended to the filename to ensure that the filenames are still unique. The index number range is 001 through 999.

Starting in Junos OS Release 14.1R3, the naming convention for a command output file generated by an event script is changed. When an event policy executes an event script and the script generates an output file, the name of the file depends on the version of Junos OS running on the device. Prior to Junos OS Release 14.1R3, the filename has the following naming convention:

Starting in Junos OS Release 14.1R3, the filename places the output-filename string after the timestamp.

For example, on a device named r1 running Junos OS Release 14.1R3 or a later release, if you configure the output-filename statement as ifl-events, and this event policy is triggered three times in 1 second, the files are named:

  • r1_20060623_132333_ifl-events

  • r1_20060623_132333_ifl-events_001

  • r1_20060623_132333_ifl-events_002

For the destination and output-filename statements, there are four configuration scenarios:

  • You can omit the destination and output-filename statements. This option makes sense when the event script has no output. For example, the event script might execute only request commands, which have no output.

  • You can include both the destination and output-filename statements. If you include the output-filename statement in the configuration, you must also include the destination statement in the configuration. In this case, the script output is redirected to the output file, and the file is sent to the destination specified in the configuration.

  • You can include the destination statement in the configuration. You can omit the output-filename statement in the configuration and specify an output filename in the event script instead. The script output is sent to the destination specified in the configuration. If you do not include the destination statement in the configuration, the script output is not uploaded.

    In this scenario, the event policy extracts the filename from the event script. The event script writes the output filename as STDOUT. The XML syntax to use in the event script is:

    The <event-script-output-filename> element must be the first child tag within the <output> parent tag.

    On a device named device2, configure an event script action with a destination host, and omit the output-filename statement. Define the destination host as ftp://user@device1//tmp.

    In the script1.xsl event script, write the following output to STDOUT:

    Configure the policy1 event policy as follows:

    In this example, the /var/cmd.txt file resides on device2 . The event policy uses the File Transfer Protocol (FTP) to upload this file to the /tmp directory on device1.

    The event policy reads the output filename /var/cmd.txt from STDOUT. Then the event policy uploads the /var/cmd.txt file to the configured destination, which is the /tmp directory on device1. The event policy renames the /var/cmd.txt file as device2_YYYYMMDD_HHMMSS_cmd.txt_index-number.

  • You can include the destination and output-filename statements and also specify an output filename directly within the event script. If you do this, the output filename specified in the configuration overrides the output filename specified in the event script.

The default and only format for event script output is Junos Extensible Markup Language (XML).

Note

Event script output is always emitted in XML format even if you configure the output-format text statement under the [edit event-options policy policy-name then event-script filename] hierarchy.

Release History Table
Release
Description
Starting in Junos OS Release 14.1R3, the naming convention for a command output file generated by an event script is changed.