Listing 3 Temperature monitoring script
#!/usr/bin/ksh
##############################################
#11/20/2002
#
#temp monitoring script
#
#version 0.1
##############################################
# FILE NAME: temperature.sh
# FILE DESCRIPTION: crontab tester on the usensor command
#
# RETURN VALUE DESCRIPTION:
# 0 sucess
# 1 failure
# 2 no capability
#
# EXTERNAL PROCEDURES CALLED:
#
# OPERATIONS
#
# this is based on standard monitor from various sources
# script just control if there is limit violation on temperature
#
# CONTROL
# there is no control file
#
# USAGE add into crontab and configure parameters about once per hour
# in normal conditions
#
# QUIRCS
# on the paritined machine SENS does not work, goes trough powerfail
#
# FUNCTIONS
# actionSyslog
# actionLogfile
# actionEcho
# actionEmail
# walkTemperaure
#
############################################################
#Revison history
#0.1 just working with usensors
############################################################
#notification actions
#to syslog
actionSyslog ()
{
logger -p"$SYSLOG" "$MESSAGE"
}
#to logfile
actionLogfile ()
{
{
date
echo "$MESSAGE"
echo "###############################"
} >> "$LOGFILE"
}
#to to email
actionEmail ()
{
printf "$MESSAGE" ""| mail -s "TEMPERATURE OVER $MAXTEMP C $SUBJECT" "$TADMIN"
}
#to stdout
actionEcho ()
{
date
echo "$MESSAGE"
echo "###############################"
}
################################################
#walk trough sensor output and test conditions
#loop e
#sets the ACTION to 1 if there is any limit violation
#SENS format is described in man page, but built in
#kernel limits are unknown
################################################
walkTemperaure ()
{
$SENS -a| while read token index status val lcode
do
if test "$token" -eq 3 -a "$val" -gt "$MAXTEMP"
then
ACTION=1
MESSAGE=$MESSAGE"\n $lcode $val"
fi
done
######################################################
#store the latest event and one previous
######################################################
test -f "$EV" && mv "$EV" "$EVO"
touch "$EVO"
echo "$MESSAGE" > "$EV"
}
#######################
#main part
#configuration
export PATH=/bin:/usr/local/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/sbin
VERSION="0.1"
BASEDIR=/rootop
CONFDIR=$BASEDIR
LOGDIR=$BASEDIR/logs
##########################################################
# testing and creating directories nesecarry
# for script operation
##########################################################
for d in $CONFDIR $LOGDIR
do
if test ! -d "$d"
then
mkdir -p $d || exit 1
fi
done
#############################################################
HOST=$(hostname)
#############################################################
#event, or two last messages cretaed
#############################################################
EV=$LOGDIR/event.temp
EVO=$LOGDIR/event.temp.old
#############################################################
#Notification info
#############################################################
#logfile
LOGFILE=""
#email where report is sent
TADMIN="root"
#logger syslog level to log message
SYSLOG=""
#to dump message on stdout
ECHO=""
######################################################
#sensor control command on AIX
#if there is no capability just exit
######################################################
SENS="/usr/lpp/diagnostics/bin/uesensor"
test -x $SENS || exit 2
######################################################
# MAXTEMP - tigger value
######################################################
MAXTEMP=36
######################################################
#set the message and global action variable
#if ACTION is > 0 it means do action
######################################################
MESSAGE="$HOST :"
ACTION=0
#sensor part
walkTemperaure
#EVENTS are same - no sending messages just to AVOID flodding
diff "$EV" "$EVO" > /dev/null 2>&1 && exit 0
###################################
#conditions part
test "$ACTION" -eq 0 && exit 0
#remove \n form subjet line outlook problem ..
SUBJECT=$(echo "$MESSAGE"| sed 's/\\n/ /g')
#Action part
test -n "$SYSLOG" && actionSyslog
test -n "$LOGFILE" && actionLogfile
test -n "$ECHO" && actionEcho
test -n "$DFADMIN" && actionEmail
exit 0
# end temperature
|