When using model-driven configuration mode and the MD-CLI, EHS can trigger a Python application that is executed inside a Python interpreter running on SR OS. See the Python chapter for more information.
Python applications are not supported in classic configuration mode or mixed configuration mode.
When developing an EHS Python application, the event attributes are passed to the application using the get_event function in the pysros.ehs module.
To import this module, the Python application developer must add the following statement to the application:
from pysros.ehs import get_event
Use the get_event function call to obtain the event triggered the Python application to run. The following example catches the event and returns a Python object into the event variable:
event = get_event()
When using an EHS Python application, the operator can use the Python programming language to create applications, as required. See the Python chapter for information about displaying model-driven state or configuration information, performing transactional configuration of SR OS, or executing CLI commands in Python.
Common event parameters (group one) are available in Python from the object created using the get_event function, as shown in the following table (the functions assume that the EHS event object is called event).
Function call | Description | Example output | Python return type |
---|---|---|---|
event.appid |
The name of the application that generated the event |
SYSTEM |
String |
event.eventid |
The event ID number of the application |
2068 |
Integer |
event.severity |
The severity level of the event |
minor |
String |
event.subject |
The subject or affected object of the event |
EHS script |
String |
event.gentime |
The formatted time the event was generated in UTC |
The timestamp in ISO 8601 format (consistent with state date/time leaves) that the event was generated. For example, 2021-03-08T11:52:06.0-05:00 |
String |
event.timestamp |
The timestamp that the event was generated (in seconds) |
1632165026.921208 |
Float |
The variable parameters (group two) are available in Python in the eventparameters attribute of the event object, as shown in the following table. They are presented as a Python dictionary (unordered).
Function call | Description | Example output | Python return type |
---|---|---|---|
event.eventparameters |
The event specific variable parameters |
<EventParams> When calling keys() on this object the example output is: ('tmnxEhsHandlerName', 'tmnxEhsHEntryId', 'tmnxEhsHEntryScriptPlcyOwner', 'tmnxEhsHEntryScriptPlcyName', 'smLaunchOwner', 'smLaunchName', 'smLaunchScriptOwner', 'smLaunchScriptName', 'smLaunchError', 'tmnxSmLaunchExtAuthType', 'smRunIndex', 'tmnxSmRunExtAuthType', 'tmnxSmRunExtUserName') |
Dict |
In addition to the variables, the format_msg() function is provided to output the formatted log string from the event as it would appear in the output of the show log command. The following is an example usage.
print(event.format_msg())
The following shows an example output of the format_msg() function.
Launch of none operation failed with a error: Python script's operational status is not 'inService'.
The script policy "test_ehs" created by the owner "TiMOS CLI" was executed with cli-user account "not-specified"