19.4.3 Setting of the event monitor function
This section describes how to use eventmonitor module to register, remove, and receive events.
Eventmonitor module supports the function to notify the scripts that are starting status changes (events) of the monitored target in combination with monitoring of the status of the device and the network. The following table lists the functions related to the event monitor facility.
Capability |
Function Name |
Description |
---|---|---|
Event Registration |
regist_sysmsg |
Register operation messages to be monitored. |
regist_cron_timer |
Register cron timer. |
|
regist_interval_timer |
Register interval timer. |
|
Delete Event |
event_delete |
Delete the registered event. |
Event reception |
event_receive |
An event is received when an event occurs. |
- <Structure of this section>
(1) Script File Example
(a) Example of monitoring operational messages as events
The following is an example of registering an event that monitors operational messages as events.
import sys import extlib.eventmonitor ..1 try: event_sysmsg=extlib.eventmonitor.regist_sysmsg(event_level="E7", message_id=0xabcd1234,message_text="(Error|error)") ..2 except Exception as e: ..3 print('ERROR!! regist_sysmsg()',e) sys.exit() while 1: dict = extlib.eventmonitor.event_receive(extlib.eventmonitor.BLOCK_ON, 0) ..4 if dict['event_id']== event_sysmsg: ..5 print('EVENT OCCURRED!!') |
-
Import the module.
-
Register the event. Monitors the output of operation messages that satisfy the following conditions:
-
Event-Level E7
-
Message identifier abcd1234
-
The message text contains the string "Error" or "error"
-
-
Checks whether the event has been registered. If registration fails, output the log and exit.
-
Calls an event reception function.
-
Check the return value to see if it was intended.
(b) Monitoring Events with cron Timer
The following shows an example of registering an event for monitoring an event by cron timer.
import sys import extlib.eventmonitor ..1 try: event_cron_timer = extlib.eventmonitor.regist_cron_timer('0 23 * * *') ..2 except Exception as e: ..3 print('ERROR!! regist_cron_timer ()',e) sys.exit() while 1: dict = extlib.eventmonitor.event_receive(extlib.eventmonitor.BLOCK_ON, 0) ..4 if dict['event_id']== event_cron_timer: ..5 print('EVENT OCCURRED!!') |
-
Import the module.
-
Registers events that occur every day at 23:00.
-
Checks whether the event has been registered. If registration fails, output the log and exit.
-
Calls an event reception function.
-
Check the return value to see if it was intended.
(c) Monitoring Events with interval Timer
The following shows an example of registering an event for monitoring an event by interval timer.
import sys import extlib.eventmonitor ..1 try: event_interval_timer = extlib.eventmonitor.regist_interval_timer(1800) ..2 except Exception as e: ..3 print('ERROR!! regist_interval_timer()',e) sys.exit() while 1: dict = extlib.eventmonitor.event_receive(extlib.eventmonitor.BLOCK_ON, 0) ..4 if dict['event_id']== event_interval_timer: ..5 print('EVENT OCCURRED!!') |
-
Import the module.
-
Registers events that occur every 1800 seconds.
-
Checks whether the event has been registered. If registration fails, output the log and exit.
-
Calls an event reception function.
-
Check the return value to see if it was intended.
(d) Example of deleting registered events
The following is an example of deleting registered events.
import sys import extlib.eventmonitor ..1 try: event_cron_timer = extlib.eventmonitor.regist_cron_timer('0 23 * * *') ..2 except Exception as e: ..3 print('ERROR!! regist_cron_timer ()',e) sys.exit() try: result_dict = extlib.eventmonitor.event_delete(event_cron_timer) ..4 print('EVENT DELETE!!') except: ..5 print('ERROR!! event_delete()') |
-
Import the module.
-
Register the event.
-
Checks whether the event has been registered. If registration fails, output the log and exit.
-
Specifies the monitoring event ID of the registered event, and stops monitoring.
-
If the stop fails, the log is output.
(e) Example of receiving events
The following example shows how to receive an event:
import sys import extlib.eventmonitor ..1 try: event_cron_timer = extlib.eventmonitor.regist_cron_timer('0 23 * * *') ..2 except Exception as e: ..3 print('ERROR!! event_cron_timer()',e) sys.exit() dict = extlib.eventmonitor.event_receive(extlib.eventmonitor.BLOCK_ON , 0) ..4 if dict['event_id']== event_cron_timer: ..5 print('EVENT OCCURRED!! ') |
-
Import the module.
-
Register the event.
-
Checks whether the event has been registered. If registration fails, output the log and exit.
-
Calls an event reception function. Received in blocking mode without receive timeout.
-
Check the return value to see if it was intended.
(2) Discarding notification information
If the monitoring event occurs frequently, it may be discarded before the event occurrence notification is notified to the script. The following figure shows the event generation notification flow. Discard occurs when the notification reception queues in steps 1 and 2 in the figure become full.
|
-
Queue overflow threshold of 1024 messages per priority
-
Queue overflow threshold is 1024 messages per script
The number of discarded events (discard) displayed in the operation-command show event manager monitor can be used to check whether discarding occurred or not.