Event handler overview

Event handler is a framework that enables SR Linux to react to specific system events, using programmable logic to define the actions taken in response to the events.

The event handler framework allows you to write custom scripts that are invoked when specific events occur, such as when a port goes operationally down. The scripts can generate a list of actions for the SR Linux device to execute. The actions can include updating the SR Linux configuration, changing the operational state of a group of ports, executing a tools command, or running another script.

SR Linux supports event handler via the event_mgr process, which operates as the srlinux user. The following diagram shows the interaction between the SR Linux management server, event handler (via the event_mgr process), and the script.

Figure 1. Event handler framework

The event handler framework operates in the following sequence:

  1. Event handler is configured to subscribe to a set of YANG paths, for example the operational state of a set of interfaces.

  2. The SR Linux management server publishes the state of the paths to which event handler is subscribed.

  3. In response to the state change, event handler invokes a MicroPython script, supplying path information and configured options for the script to use as input.

  4. The script processes the information supplied by event handler.

  5. The script returns a list of actions that is passed to event handler. Possible actions include setting an interface operationally down, running a tools command, or executing another script.

  6. Event handler processes the list of actions returned by the script.

  7. Event handler executes the actions on the SR Linux device, or runs another script if an action specifies to do so.

To configure event handler, you configure an event handler instance, which specifies the paths to monitor, the name of the script to run, and options to supply to the script. See Event handler configuration.

Event handler supplies input to a script as a JSON string. See Event handler scripts for details about how the script input is formatted, how it is processed by a script, and the actions that a script can return to event handler.

One possible use for event handler is the ability to change the operational state of one group of ports based on the state of another group of ports. This type of usage is known as operational groups. Operational groups overview describes this use case. Configuring event handler for operational groups provides an example configuration.