#!/bin/sh # A Hobbit script to examine specific Solaris 10 services. # Author: Martin Ward 19 Feb 2008. # Version: 1.0 - Initial version. # V1.1 Script now takes the list of services to monitor from the server # via the logfetch file. # SVCS is a list of services to examine the status of. Each name must be # specific enough to make it unique in the output from the 'svcs -a' command. # Separate each service with a | so that we can use ${EGREP} to search for them. # The services themselves are configured on the Hobbit server in the # ~hobbit/server/etc/client-local.cfg file. The line will look something like: # svc:/network/ssh:default|svc:/site/tftpd:default # Verify existence of the config file if [ ! -f $BBTMP/logfetch.$MACHINEDOTS.cfg ] then echo "Unable to retrieve services descriptions." exit 1 fi SVCS=`grep '^svc:' $BBTMP/logfetch.$MACHINEDOTS.cfg` # The name of the column in Hobbit COLUMN=smf # COLOUR defaults to green COLOUR=GREEN # When you modify a variable inside a while loop its value is local to that # loop. This means that when you reach the end of the loop the variable will # be the same value that it was before the loop was entered. For this reason # we have to store the services and colour in temporary files. SVCFILE=/tmp/svcs.$$ COLOURFILE=/tmp/svcs.colour.$$ # Set up the initial colour echo "WHITE" > $COLOURFILE # Get the svcs header line first MSGH=`svcs -a | head -1` # Scan through the svcs -a list. Use -a to ensure we get everything. svcs -a | ${EGREP} "${SVCS}" > $SVCFILE cat $SVCFILE | while read SVC do STATE=`echo ${SVC} | ${AWK} '{print $1}'` case "${STATE}" in 'uninitialized'|'offline'|'degraded') if [ "${COLOUR}" != "RED" ] then COLOUR="YELLOW" fi ;; 'maintenance'|'disabled') COLOUR="RED" ;; esac echo ${COLOUR} > $COLOURFILE done COLOUR=`cat ${COLOURFILE}` # Tell Hobbit about it $BB $BBDISP "status $MACHINE.$COLUMN $COLOUR `date` ${MSGH} `cat ${SVCFILE}` " rm -f ${SVCFILE} ${COLOURFILE} exit 0