Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Use Event and Remote Execution Details in Event Scripts

Event policy actions can include executing one or more event scripts. When an event policy executes an event script, the event process forwards the event details to the script. These event details can be captured, evaluated, and sent to log files as required. In addition, any configured remote execution details are also forwarded to the event script.

Two types of event details are returned: triggered events and received events. Triggered events record the details of the event that triggered the policy. Received events record the details of events that happened before the triggering event. Trigger event details are always forwarded to event scripts. Received event details are only present when an event policy is triggered for correlated events.

Remote execution details, which include the hostname, username, and passphrase for one or more remote hosts, enable an event script to invoke remote procedure calls on remote hosts without encoding the connection information directly in the event script. You configure remote execution details at the [edit event-options event-script file filename remote-execution] hierarchy level. When you include remote execution details in the configuration instead of in the individual event scripts, the information is captured in a single location and the passphrase is encrypted. This is not the case in an event script file.

Event details and remote execution details are forwarded to SLAX and XSLT event scripts as XML in the following format:

For information about the <junos-context> element, see Global Parameters and Variables in Junos OS Automation Scripts.

Python event scripts must import the Junos_Trigger_Event and Junos_Received_Events objects to access details about the trigger event and received events. Junos_Trigger_Event and Junos_Received_Events are lxml.etree _Element objects and contain the same hierarchy and tag names as the <trigger-event> and <received-events> hierarchies in the SLAX and XSLT script input.

Python event scripts can extract the necessary event details from the objects using lxml methods such as xpath() and find(), findall(), and findtext(). For example:

Python event scripts must import Junos_Remote_Execution_Details to access the remote execution details configured at the [edit event-options event-script file filename remote-execution] hierarchy level. Junos_Remote_Execution_Details is a generator function that produces a sequence of remote devices, which makes it easy to iterate over multiple configured hosts. You can reference the hostname, username, and passphrase for a configured remote host by using the host, user, and passwd properties as in the following code: