Event Handlers Configuration

The yangcli-pro program can access an event handler mapping configuration. An event-handler is a mapping between notification (or set of notifications) and an event handler script. A session-cfg can specify event-handlers to install when the session starts. The event-handler command can also be run in session mode to apply to the current session. These named event handler mapping configuration are saved in a configuration file. Use the --autoeventhandlers to suppress automatic loading of this file. The default is to load this file at start-up and save it upon exit.

By default, the event handlers configuration is saved in $HOME/.yumapro/yangcli_pro_event_handlers.conf. To override this file, set --autoeventhandlers=false and use the event-handler-cfg command to load a specific event-handlers configuration file.

Creating New Event Handlers

Use event-handler-cfg 'create' command to create a new event handler. The created event handler does not actually cause any event scripts to be invoked because there has to be a session-cfg mapping. The session-cfg command has a parameter ‘use-event-handler’.

> event-handler-cfg ?

brief          Show brief help text
create         An event-handler name to use to create a new event handler.
delete         Delete the specified event-handler from the saved event hand...
event-name     The event name for the event handler.
full           Show full help text
module-name    The module name for the event handler.
normal         Show normal help text
save           Save the specified event handler to the saved event handlers...
script         The yangcli script name to use for the event handler.
shell-script   The shell script name to use for the event handler.
show           Show the specified event-handler or the current event-handle…

> event-handler-cfg create=handler-ses-change module-name=ietf-netconf-notifications event-name=netconf-config-change shell-script=ses-change.sh.

A new event_handler is created: event_handler-id=handler-ses-change

Event Handler 'handler-ses-change'
   module-name=ietf-netconf-notifications
   event-name=netconf-config-change
   shell-script=ses-change.sh

> event-handler-cfg show=handler-ses-change
   Event Handler 'handler-ses-change'
   module-name=ietf-netconf-notifications
   event-name=netconf-config-change
   shell-script=ses-change.sh

> event-handler-cfg delete=handler-ses-change
Deleted saved event_handler 'handler-ses-change'

>

Multiple Event Handlers

Multiple event handlers can be active at once, however only one event script at a time can be invoked. This will be improved in a future release.

Saving the Configured Event Handlers

The event handlers configuration can be saved or loaded at run-time, if the --autoeventhandlers=true parameter is used (the default). The event-handlers-cfg save command is used to save this file.

> event-handlers-cfg save

Saved 3 event_handlers OK to '~/.yumapro/.yangcli_pro_event_handlers.conf'

>

To save the event handlers to a different file, simply provide the filespec in the 'event-handler-cfg save' command:

> event-handlers-cfg save myeventhandlers.conf

Saved 2 eventhandlers OK to 'myeventhandlers.conf'

>

Loading Additional Configured Event Handlers

Additional event handlers can be added to the configuration in memory with the 'event-handlers-cfg load' command. The named event handlers in the file cannot conflict with names already in use or the duplicate event handlers will be skipped.

session-A> event-handlers-cfg load myeventhandlers.conf

Loaded saved event_handlers OK from 'myeventhandlers.conf'

session-A>

Displaying the Configured Event Handlers

The event-handlers that are available can be displayed with the event-handlers-cfg 'show' command. The --brief and --full extensions are available for this command.

> event-handlers-cfg show

Saved event_handlers source: '~/.yumapro/.yangcli_pro_event_handlers.conf'

   Event Handler 'handler-ses-change'
      module-name=ietf-netconf-notification
      event-name=netconf-config-change
      shell-script=ses-change.sh
   Event Handler 'handler-ses-start'
      module-name=ietf-netconf-notification
      event-name=netconf-config-start
      shell-script=ses-start.sh
   Event Handler 'handler-ses-end'
      module-name=ietf-netconf-notification
      event-name=netconf-config-end
      shell-script=ses-end.sh

Event Handlers Variables

The event handler is passed 8 variables in the dollar parameters for the script

Parameter

Description

Example

$0

script name

test1.sh

$1

handler name being invoked

my-handler1

$2

module name of the event

ietf-netconf-notifications

$3

Event name

netconf-config-change

$4

eventTime field from the notification

2021-08-29T22:57:43Z

$5

XML file of the <notification> element

/tmp/yangcli-event-s2012.e32.xml

$6

session-name that received the event

my-session1

$7

IP address of the server that sent the event

192.168.0.204

The raw event filespec to XML file that contains the complete <notification> element for this event. This file will be deleted after the script is invoked.

Example XML File:

<?xml version="1.0" encoding="UTF-8"?>
<notification xmlns="urn:ietf:params:xml:ns:netconf:notification:1.0">
  <eventTime>2021-08-29T22:57:43Z</eventTime>
  <netconf-config-change xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-notifications">
    <changed-by>
      <username>andy</username>
      <session-id>3</session-id>
      <source-host>127.0.0.1</source-host>
    </changed-by>
    <datastore>running</datastore>
    <edit>
      <target xmlns:nacm="urn:ietf:params:xml:ns:yang:ietf-netconf-acm">/nacm:nacm</target>
      <operation>create</operation>
    </edit>
  </netconf-config-change>
</notification>