Link to home
Start Free TrialLog in
Avatar of bsa_jug
bsa_jug

asked on

errpt alert mails

Is there some method when a error is logged in errpt an mail can be generated sending that error to the admin mail
ASKER CERTIFIED SOLUTION
Avatar of woolmilkporc
woolmilkporc
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dfke
dfke

From the Managing AIX Server Farms redbook: http://www.redbooks.ibm.com/redbooks/pdfs/sg246606.pdf


#!/bin/ksh
#################################################################
#
# Program : hwalert
#
# Function : Send alerts for hardware Errors using the sendtrap script.
# This Program, once enabled, is called automatically every time
# a Permanent H/W Error is logged. This is achieved by inserting
# an entry into the odm which tells the system to run this script
# every time a particular error occurs.
#
# Parameters : hwalert {ENABLE | DISABLE | $* from odm}
#
# If you wish to exclude certain hardware alerts add the Error Label
# in the /etc/hwalert.exclude file.
# Any errors with that label will be ignored.
#################################################################
# This function actually changes the ODM entry.
# The ENABLE option will not remove any currently, then add the entry in.
function manipulate_odm
{
export ODMDIR="/etc/objrepos"
if [[ $1 = "ENABLE" ]] ; then
odmdelete -q "en_name=hwalert" -o errnotify > /dev/null
odmdelete -q "en_name=OPMSG" -o errnotify > /dev/null
odmdelete -q "en_name=custom" -o errnotify > /dev/null
# Add an ODM entry for PERM errors - this is a default entry
odmadd <<END__OF__ODM
errnotify:
en_pid = 0
en_name = "hwalert"
en_persistenceflg = 1
en_label = ""
en_crcid = 0
en_class = "H"
en_type = "PERM"
en_alertflg = ""
en_resource = ""
en_rtype = ""
en_rclass = ""
en_method = "$ROOT_PATH/hwalert \$1 \$2 \$3 \$4 \$5 \$6 \$7 \$8 \$9 \$10 \$11"
END__OF__ODM
errors=$(($errors+$?))
# Now add entries for other errpt events specified in config
if [[ -f /etc/errpt.alert ]] ; then
cat /etc/errpt.alert | \
# The following awk command must be one contiguous line.
awk -F: '!/^([ ]*#.*|[ ]*)$/{printf("errnotify:\nen_pid = 0\nen_name =\"custom\"\nen_persistenceflg = 1\nen_label = \"\"\nen_crcid = \"\"\nen_class =\"%s\"\nen_type = \"%s\"\nen_alertflg= \"\"\nen_resource = \"%s\"\nen_rtype =\"\"\nen_rclass = \"\"\nen_method = \"'$ROOT_PATH'/hwalert \$1 \$2 \$3 \$4 \$5\$6 \$7 \$8 \$9 \$10 \$11\"\n\n",$1,$2,$3);}' |\odmadd
fi
if [[ $errors -ne 0 ]] ; then
/usr/local/bin/sendtrap 4 "Failed to enable errpt /hardware
alerting - errpt/hardware alerting inoperable!"
fi
else
# Remove all errpt alerting
odmdelete -q"en_name=hwalert" -o errnotify > /dev/null 2>&1
odmdelete -q"en_name=custom" -o errnotify > /dev/null 2>&1
fi
}
# Main routine.
ROOT_PATH="/usr/local/bin"
if [[ $# -eq 0 ]] ; then
print "Usage: ${0} ENABLE | DISABLE"
exit 0
fi
# Check if it is running as root user.
if [[ $(id -u) -ne 0 ]] ; then
print "$0 must be run as root"
exit
fi
if [[ $1 = +(ENABLE|DISABLE) ]] ; then
manipulate_odm $1
exit 0
fi
Error_Seq=$1
Appendix B. Example scripts 317
Identifier=$2
Device=$6
Label=$9
# There may be some hardware errors we wish to exclude. Therefore,
# check that the error type received does not exist in the hwalert.exclude.
if [[ -e /etc/hwalert.exclude ]] && grep -q "^$Label$" /etc/hwalert.exclude
then
exit 0
fi
print "1 is $1 2 is $2 3 is $3 4 is $4 5 is $5 6 is $6 7 is $7" > /tmp/ping
Message="System error $Label on $Device - please investigate errpt for details"
# Send alert via sendtrap.
/usr/local/bin/sendtrap 2 "$Message"

Open in new window

Sorry I misread you asked for e-mail notification. This is for snmp sendtrap.
I have it this way a script
#!/bin/ksh
errpt | pg > errpt.txt
mail -s "errpt output" mel@mail < errpt.txt
Then save the script,  then added to crontab
0 8 * * * /error.sh

madunix
madunix,
is it really a good idea to send the complete errorlog once a day?
Avatar of bsa_jug

ASKER

Thx woolmilkporc , the suggestion worked good