#!/usr/bin/ksh
# /usr/local/scripts/em-errpt.ksh
# Version 2.0
# Updated: September 2, 2005
# * Crontab initiated *
# root crontab should look like this.
###########################################
# Create alerts for any new lines in the errpt
###########################################
#0,5,10,15,20,25 * * * * /root/scripts/em-errpt.ksh > /dev/null 2>&1
#30,35,40,45,50,55 * * * * /root/scripts/em-errpt.ksh > /dev/null 2>&1
#
# Version 1.0
# The purpose of this script is to send any errpt messages to Enterprise
# Monitoring. Check every five minutes for new messages and send all new
# lines (subject and time only) to Enterprise Monitoring with a custom
# sendtrap.
# Version 2.0
# Alerts are now categorized based on severity.
#
###########
# ARRAYS - See below for how to populate these arrays
MINOR=
MAJOR=
CRITICAL=
###########
# Populating the MINOR array.
MINOR[1]="RECEIVER OVER-RUN ON INPUT"
MINOR[2]="ERROR LOGGING TURNED ON"
MINOR[3]="SOFTWARE PROGRAM ERROR"
MINOR[4]="The daemon is started."
MINOR[5]="UNABLE TO ALLOCATE SPACE IN FILE SYSTEM"
MINOR[6]="SOFTWARE PROGRAM ABNORMALLY TERMINATED"
###########
# Populating the MAJOR array.
MAJOR=[1]="JFS2 LOGGING IS BACK TO NORMAL"
MAJOR=[2]="JFS2 LOG RECORDS FORCED OVERWRITTEN"
MAJOR=[3]="DISK OPERATION ERROR"
MAJOR=[4]="ADAPTER ERROR"
MAJOR=[5]="I/O ERROR DETECTED BY LVM"
MAJOR=[6]="COMMUNICATION PROTOCOL ERROR"
###########
# Populating the CRITICAL array.
CRITICAL[1]="ENVIRONMENTAL PROBLEM"
# Functions
_snmptrap()
{
TRAPCOMMAND="/usr/local/bin/snmptrap -v 1 -c public [b][i]enterprise_monitoring_server[/i][/b] .1.3.6.1.4.1.8072"
TRAPFROM=`uname -n`
TRAPREQUIRED="6 1 '' .1.3.6.1.2.1.1.6 s"
TRAPDETAILSEPERATOR=".1.3.6.1.2.1.1.6 s"
${TRAPCOMMAND} ${TRAPFROM} ${TRAPREQUIRED} "${TRAPSUBJECT}" \
${TRAPDETAILSEPERATOR} $TRAPGROUP ${TRAPDETAILSEPERATOR} "${TRAPDETAIL1}" \
${TRAPDETAILSEPERATOR} "${TRAPDETAIL2}" &
}
# Move the previous errpt output to /tmp/em-errpt-old.txt. This will give us
# something to compare the new one to. If it doesn't exist, create a blank
# old one.
if [ -f /tmp/em-errpt.txt ] ; then
mv /tmp/em-errpt.txt /tmp/em-errpt-old.txt
else
touch /tmp/em-errpt-old.txt
fi
# Generate an errpt to /tmp/em-errpt.txt
errpt | grep -v IDENTIFIER > /tmp/em-errpt.txt
# Compare the new errpt output with the previous. Any new lines should
# generate alerts.
# Seperate files with "|". The first two fields are the timestamp and resource.
# The last field is a description. The description comes through with commas
# instead of spaces.
for ALERT in `diff /tmp/em-errpt.txt /tmp/em-errpt-old.txt \
| grep "< " | sed 's/\< //g' \
| awk '{ printf $2"|"$5"|"; \
for (i=6; i<=NF; i++) printf "%s,", $i; printf "\n" }'`
do
# Now that I have the alert, seperate the fields and send the trap.
DELIMITEDMESSAGE=`echo $ALERT | awk -F\| '{ print $3}'`
# This line converts all commas to spaces and removes the space
# from the end of the line.
DESCRIPTION=`echo $DELIMITEDMESSAGE | sed 's/\,/ /g' | sed 's/ $//g'`
RESOURCE=`echo $ALERT | awk -F\| '{ print $2 }'`
TIMESTAMP=`echo $ALERT | awk -F\| '{ print $1 }'`
# Assign the appropriate severity.
DEFINED=FALSE
COUNT=1
until [[ $COUNT = ${#MINOR[*]} ]] ; do
if [[ "$DESCRIPTION" = "${MINOR[$COUNT]}" ]] ; then
ASSIGNEDSEV=MINOR
DEFINED=TRUE
fi
(( COUNT = COUNT + 1 ))
done
if [[ $DEFINED != TRUE ]] ; then
COUNT=1
until [[ $COUNT = ${#MAJOR[*]} ]] ; do
if [[ "$DESCRIPTION" = "${MAJOR[$COUNT]}" ]] ; then
ASSIGNEDSEV=MAJOR
DEFINED=TRUE
fi
(( COUNT = COUNT + 1 ))
done
fi
if [[ $DEFINED != TRUE ]] ; then
COUNT=1
until [[ $COUNT = ${#CRITICAL[*]} ]] ; do
if [[ "$DESCRIPTION" = "${CRITICAL[$COUNT]}" ]] ; then
ASSIGNEDSEV=CRITICAL
DEFINED=TRUE
fi
(( COUNT = COUNT + 1 ))
done
fi
if [[ $DEFINED = FALSE ]] ; then
ASSIGNEDSEV=MAJOR
fi
export TRAPSUBJECT="$ASSIGNEDSEV: [b]team[/b]: `uname -n` $DESCRIPTION"
export TRAPGROUP="[b]Support team[/b]"
export TRAPDETAIL1="$RESOURCE"
export TRAPDETAIL2="$TIMESTAMP"
_snmptrap
done
exit 0