Cover V04, I06
Article
Figure 1
Figure 2
Figure 3
Listing 1
Listing 10
Listing 2
Listing 3
Listing 4
Listing 5
Listing 6
Listing 7
Listing 8
Listing 9

nov95.tar


Listing 1: event_log.ksh--Event/Log Monitor

#!/bin/ksh
#==================================================
# "@(#)event_log.ksh"
#
# This scripts accesses all the NIS and Sybase
# servers to find out if there are
# any messages in the /var/adm/messages file.
# This script should be run from the
# server as user root.
#
# Parameters : None
#
# Calling mechanism :
#   Should be called from cron after every unit of
#   time equal to the reporting time. For example
#   if you want notifications to be sent every
#   15 minutes, then the cron entry should be
# 0,15,30,45 * * * * /usr/local/admin/bin/event_log.ksh
#
# Author :
#       Ravindra Nemlekar and Jeffery Soto
#
#==================================================

BASEDIR=/usr/local/admin/scripts
HOST_DIR=$BASEDIR/hosts
PATH=$PATH:/usr/5bin
HOST_LIST=/tmp/hosts.$$
TMPFILE=/tmp/file.$$
MAILFILE=/tmp/mail.$$
NIS_LIST=/usr/local/admin/scripts/NIS_SERVERS
SYBASE_LIST=/usr/local/admin/scripts/SYBASE_SERVERS

server_list=/tmp/list.$$
mask_list=/tmp/mask.$$

# Combined unique list of servers with comments
# stripped.
cat $NIS_LIST $SYBASE_LIST | grep -v '^#' | \
sort -u > $HOST_LIST

# Create a msg directory for each server if it
# doesn't already exist.
for host in `cat $HOST_LIST`
do
if [ ! -d $HOST_DIR/$host ]; then
mkdir $HOST_DIR/$host
chmod 777 $HOST_DIR/$host
touch $HOST_DIR/$host/EVENT_FILE
else
touch $HOST_DIR/$host
fi
done

# Check if the host is alive.
# If yes, then
#    grep for error messages
# else
#    page sa for at the most 3 times.
#
for host in `cat $HOST_LIST`
do
$BASEDIR/check_in_master_list.ksh $host \
$BASEDIR/MASTER_LIST
if [ 0 -ne $? ] ; then
# Host not in master list. Ignore it.
continue
fi
STATUS=`/usr/etc/ping $host | awk '{print $3}'`
count_file=$HOST_DIR/$host/countfile
if [ "$STATUS" != "alive" ]; then
sleep 3
STATUS=`/usr/etc/ping $host | \
awk '{print $3}'`
fi
if [ "$STATUS" != "alive" ]; then
# Have we beeped before
# If we have, increment the counter, beep
# up to 3 times, then suspend the beep
integer count=0
if [ ! -f $count_file ]
# Is it the first iteration?
then
echo "1" >  $count_file
else
# Just increment the count.
count=$(cat $count_file)
count=count+1
echo "$count" > $count_file
if (( count > 2 )) ; then
if (( count == 3 )) ; then
/usr/local/bin/beep sa \
"${host}: Host unreachable by event logger - Final"
fi
continue
fi
fi
/usr/local/bin/beep sa "${host}: Not \
reachable by event logger"
continue
fi
if [  -f $count_file ]; then
/usr/local/bin/beep sa "${host}: Host OK,\
reachable from event logger"
/bin/rm -f $count_file
fi

# Escape all the formatting characters from
# "rsh"
rsh -l root $host egrep -i "\(error\|bad\|\
panic\|fatal\|full\|REPEATED\ LOGIN\ FAILURES\|\
copyright\)" /var/adm/messages | fgrep -v sendmail\
> $TMPFILE
if [ $? -ne 0 ] ; then
continue ;	# rsh failed for some reason
fi
cat $HOST_DIR/$host/EVENT_FILE $TMPFILE | \
sort -u > /tmp/tmpfile.x
cat /tmp/tmpfile.x $HOST_DIR/$host/EVENT_FILE \
| sort | uniq -u >  $MAILFILE
mv -f $TMPFILE $HOST_DIR/$host/EVENT_FILE
/bin/rm -f /tmp/tmpfile.x
if [ -s $MAILFILE ]; then
cat $MAILFILE >> \
$HOST_DIR/$host/log.event
cut -f4- -d' ' $MAILFILE | sort | \
uniq -c | Mail -s "$host: Error condition reported" \
sa dba
/usr/local/bin/beep sa "${host}:\
`/usr/ucb/head -1 $MAILFILE `"
/bin/rm -f $MAILFILE
fi
done
/bin/rm -f $HOST_LIST $TMPFILE $MAILFILE
# End of File