HP-UX Event ManagerProgrammer's Guide

- the optional set_number is the number of the message set containing the explanation,
for example, cat:myprod.cat:3.
Each explanation in the catalog begins with the name of an event enclosed in braces, for
example, {myco.myprod.myapp.startup}.
The message catalog must be located according to normal I18N rules. To minimize search time,
group the explanations into sets and provide the set numbers in the reference data items of the
events. For information about procedures to generate a catalog file, see mkcatdefs(1) and gencat(1).
The Monitor Function
The monitor function is executed by the EVM channel manager. It is executed with an -init
argument when the channel manager starts. Each time the channel manager is reconfigured with
evmreload, execute the function without the -init argument. The execution period is controlled
with the mon_period channel value. This function is always executed as superuser and must
take appropriate security precautions.
The function must support the following invocation syntax:
function-name [init]
You can use the presence or absence of the Init argument to decide whether the function needs
to initialize any work files that it has to maintain. If required, you can pass additional arguments
to the function by including them on the command line in the channel configuration file.
NOTE: The init argument is always passed as the last argument.
There are no restrictions on the actions that can be taken by the monitor function, although its
job is to check the status and post events if it detects a change of state.
The function is invoked with no stdout and stderr assigned to the channel manager's log file.
If the function does not reassign stderr, any messages written to it must have the same format
as the channel manager's log entries and must be clearly identifiable as coming from your channel.
Alternatively, you can post error messages as EVM events. However, you must not report the
same condition unnecessarily each time the function in invoked.
Example 4-11 illustrates the monitor script that initializes itself by counting the number of lines
in a log file, and saving the count in a state file. On subsequent invocations, it compares the
number of lines in the file with the previous number, extracts each new line with the UNIX tail
command, and posts it as an EVM event with evmpost.
Example 4-11 Sample Monitor Script
#! /bin/shINIT=$1STATE=/tmp/mylog.stateLOG=/tmp/mylogEVENT_NAME=sys.unix.evm
# No log? Create one!
if [ ! -f $LOG ]then touch $LOGfi
# If we're initializing then save the current logfile state and exit:
if [ "$INIT" != "" ]then
# Count the lines in the demolog, and save the count in the state file:
wc -l $LOG | awk '{print $1}' > $STATE exitfi
# Find out how many lines there were in the file last time we checked:
OLDCOUNT=`cat $STATE`
# How many now?
NEWCOUNT=`wc -l $LOG | awk '{print $1}'`if [ $NEWCOUNT > $OLDCOUNT ]then
# Save the new line count to the state file:
echo $NEWCOUNT > $STATE
# What's the difference between the old and new counts?
diff=`expr $NEWCOUNT - $OLDCOUNT | awk '{print $1}'`
# Post an event for each new line:
tail -$diff $LOG | while read LINE do echo 'event { name '${EVENT_NAME} \ ' var {name msg type STRING value
"'$LINE'"} }' | evmpost donefi
The Cleanup Function
The cleanup function is executed daily by the EVM channel manager, at the time specified in
the channel configuration file, to perform housekeeping actions such as archiving and deleting
56 Sample EVM Programming Operations