Listing 2 create_alert_file
#!/bin/ksh
# Listing 2:
# Program: create_alert_file
#
# Description:
#
# this utility, called by another program, generates, in the $NEW_ALERTS_DIR,
# an alert file with the file name based on host, date, priority, and class.
#***************************************************************************
# set the globals
. $(dirname $0)/setenv_monitor
UNDEFINED="<undefined>"
priority=$UNDEFINED
class=$UNDEFINED
subject=$UNDEFINED
host=$(uname -n)
while getopts p:c:h:s: OPTION
do
case $OPTION in
p) priority=$OPTARG ;;
c) class=$OPTARG ;;
h) host=$OPTARG ;;
s) subject=$OPTARG ;;
esac
done
case $priority in
i*|I*) priority=info ;;
l*|L*) priority=low ;;
m*|M*) priority=med ;;
h*|H*) priority=high ;;
esac
#======================================================
# if the alert is disabled by class id, host, or priority,
# exit without creating the alert.
#======================================================
if [[ -f $DISABLED_ALERTS_DIR/class/$class ]] \
|| [[ -f $DISABLED_ALERTS_DIR/host/$host ]] \
|| [[ -f $DISABLED_ALERTS_DIR/priority/$priority ]]
then
exit
fi
#========================================
# create the alert file with header info
#========================================
date_string=$(date '+%y%m%d.%H%M%S')
alert_file=$NEW_ALERTS_DIR/$host.$date_string.$priority.$class
#======================================================================
# if anything is piped into standard input, attach it to the alert file
#======================================================================
cat >> $alert_file
cat > $alert_file << EOF
$(date '+%y-%m-%d %H:%M:%S')
host=$host
priority=$priority
class=$class
subject: $subject
EOF
cat >> $alert_file
echo "created: $(basename $alert_file)" >> $MONITOR_LOGFILE
# End Listing 2
|