Funny that. About a year ago I discussed using that method with a colleague. <br>We never got that far, and I forgot all about it.<br><br>And excellent way to do it.<br><br>Have you considered posting your script on Xymonton?<br>
Here <a href="http://xymonton.trantor.org/doku.php/monitors">http://xymonton.trantor.org/doku.php/monitors</a><br><br>Cheers<br>    Vernon<br><br><br><br><div class="gmail_quote">On Wed, Jul 28, 2010 at 4:30 PM, Ward, Martin <span dir="ltr"><<a href="mailto:Martin.Ward@colt.net">Martin.Ward@colt.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">I have a script that is one step further than yours, the main difference<br>
being that I have defined the services to be monitored in the<br>
client-local.cfg file as you want:<br>
<br>
In client-local.cfg for example:<br>
<br>
[nmc-dhcp1]<br>
log:/var/adm/messages:10240<br>
svc:/network/ssh:default|svc:/site/network/dhcpd:default<br>
<br>
Data from this file is sent to the client (in this case a server called<br>
nmc-dhcp1) and stored in $BBTMP/logfetch.$MACHINEDOTS.cfg, so in the<br>
client-side script I have:<br>
<br>
SVCS=`grep '^svc:' $BBTMP/logfetch.$MACHINEDOTS.cfg`<br>
<br>
I was being lazy so have separated the services with the | symbol in<br>
client-local.cfg, this means I can then use the following code with no<br>
pre-processing:<br>
<br>
svcs -a | ${EGREP} "${SVCS}" > $SVCFILE<br>
<br>
The reason I store the 'svcs -a' output is because I include it in the<br>
data sent back to Xymon.<br>
<br>
Service states are checked using the following code:<br>
<br>
cat $SVCFILE | while read SVC<br>
do<br>
        STATE=`echo ${SVC} | ${AWK} '{print $1}'`<br>
<br>
        case "${STATE}" in<br>
'uninitialized'|'offline'|'degraded')<br>
                if [ "${COLOUR}" != "RED" ]<br>
                then<br>
                        COLOUR="YELLOW"<br>
                fi<br>
                ;;<br>
'maintenance'|'disabled')<br>
                COLOUR="RED"<br>
                ;;<br>
        esac<br>
        echo ${COLOUR} > $COLOURFILE<br>
done<br>
<br>
COLOUR=`cat ${COLOURFILE}`<br>
<br>
To be honest I don't know why I am storing the colour in a file and then<br>
re-reading it outside the loop, the value shouldn't change at the end of<br>
the while loop. This script was thrown together so it's likely I<br>
intended to remove it but forgot.<br>
<br>
Anyway, after that loop I call $BB and pass it all the parameters.<br>
<br>
It doesn't have the options that you want, but it does allow for<br>
different return colours depending on the return state. I coded it to<br>
return RED if a service is in a disabled state since I want to monitor<br>
specific services rather than all of them.<br>
<br>
The final code is here:<br>
<br>
----<br>
#!/bin/sh<br>
<br>
# A Hobbit script to examine specific Solaris 10 services.<br>
<br>
# Author: Martin Ward 19 Feb 2008.<br>
# Version: 1.0 - Initial version.<br>
# V1.1  Script now takes the list of services to monitor from the server<br>
#       via the logfetch file.<br>
<br>
# SVCS is a list of services to examine the status of. Each name must be<br>
# specific enough to make it unique in the output from the 'svcs -a'<br>
command.<br>
# Separate each service with a | so that we can use ${EGREP} to search<br>
for them.<br>
# The services themselves are configured on the Hobbit server in the<br>
# ~hobbit/server/etc/client-local.cfg file. The line will look something<br>
like:<br>
# svc:/network/ssh:default|svc:/site/tftpd:default<br>
<br>
# Verify existence of the config file<br>
if [ ! -f $BBTMP/logfetch.$MACHINEDOTS.cfg ]<br>
then<br>
        echo "Unable to retrieve services descriptions."<br>
        exit 1<br>
fi<br>
<br>
SVCS=`grep '^svc:' $BBTMP/logfetch.$MACHINEDOTS.cfg`<br>
<br>
# The name of the column in Hobbit<br>
COLUMN=smf<br>
<br>
# COLOUR defaults to green<br>
COLOUR=GREEN<br>
<br>
# When you modify a variable inside a while loop its value is local to<br>
that<br>
# loop. This means that when you reach the end of the loop the variable<br>
will<br>
# be the same value that it was before the loop was entered. For this<br>
reason<br>
# we have to store the services and colour in temporary files.<br>
SVCFILE=/tmp/svcs.$$<br>
COLOURFILE=/tmp/svcs.colour.$$<br>
<br>
# Set up the initial colour<br>
echo "WHITE" > $COLOURFILE<br>
<br>
# Get the svcs header line first<br>
MSGH=`svcs -a | head -1`<br>
<br>
# Scan through the svcs -a list. Use -a to ensure we get everything.<br>
svcs -a | ${EGREP} "${SVCS}" > $SVCFILE<br>
<br>
cat $SVCFILE | while read SVC<br>
do<br>
        STATE=`echo ${SVC} | ${AWK} '{print $1}'`<br>
<br>
        case "${STATE}" in<br>
'uninitialized'|'offline'|'degraded')<br>
                if [ "${COLOUR}" != "RED" ]<br>
                then<br>
                        COLOUR="YELLOW"<br>
                fi<br>
                ;;<br>
'maintenance'|'disabled')<br>
                COLOUR="RED"<br>
                ;;<br>
        esac<br>
        echo ${COLOUR} > $COLOURFILE<br>
done<br>
<br>
COLOUR=`cat ${COLOURFILE}`<br>
<br>
# Tell Hobbit about it<br>
$BB $BBDISP "status $MACHINE.$COLUMN $COLOUR `date`<br>
<br>
${MSGH}<br>
`cat ${SVCFILE}`<br>
"<br>
<br>
rm -f ${SVCFILE} ${COLOURFILE}<br>
<br>
exit 0<br>
----<br>
<br>
<br>
|\/|artin<br>
<br>
[Colt Disclaimer]<br>
The message is intended for the named addressee only and may not be disclosed<br>
to or used by anyone else, nor may it be copied in any way. The contents of<br>
this message and its attachments are confidential and may also be subject to<br>
legal privilege. If you are not the named addressee and/or have received this<br>
message in error, please advise us by e-mailing <a href="mailto:abuse@colt.net">abuse@colt.net</a> and delete the<br>
message and any attachments without retaining any copies. Internet<br>
communications are not secure and Colt does not accept responsibility for this<br>
message, its contents nor responsibility for any viruses. No contracts can be<br>
created or varied on behalf of Colt Technology Services, its subsidiaries,<br>
group companies or affiliates ("Colt") and any other party by email<br>
communications unless expressly agreed in writing with such other party.<br>
Please note that incoming emails will be automatically scanned to eliminate<br>
potential viruses and unsolicited promotional emails. For more information<br>
refer to <a href="http://www.colt.net" target="_blank">www.colt.net</a> or contact us on +44(0)20 7390 3900<br>
<div><div></div><div class="h5"><br>
<br>
To unsubscribe from the xymon list, send an e-mail to<br>
<a href="mailto:xymon-unsubscribe@xymon.com">xymon-unsubscribe@xymon.com</a><br>
<br>
<br>
</div></div></blockquote></div><br>