Using 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_Received_Events objects to
access details about the trigger event and received events.
lxml.etree _Element objects and contain
the same hierarchy and tag names as the
in the SLAX and XSLT script input.
Python event scripts can extract the necessary event
details from the objects using lxml methods such as
findtext(). For example:
from junos import Junos_Trigger_Event from junos import Junos_Received_Events id = Junos_Trigger_Event.xpath('//trigger-event/id').text name = Junos_Trigger_Event.xpath('//trigger-event/process/name').text message = Junos_Trigger_Event.xpath('//trigger-event/message').text
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
as in the following code:
from junos import Junos_Remote_Execution_Details for remote in Junos_Remote_Execution_Details(): hostname = remote.host username = remote.user passphrase = remote.passwd