Differences

This shows you the differences between two versions of the page.

Link to this comparison view

monitors:smf.sh [2010/07/29 10:51] (current)
Line 1: Line 1:
 +====== Solaris 10 SMF service monitor ======
 +
 +^ Author | [[ martin.ward@colt.net | wardmw ]] |
 +^ Compatibility | Xymon 4.2 |
 +^ Requirements | Solaris 10 |
 +^ Download | None |
 +^ Last Update | 2010-07-29 |
 +
 +===== Description =====
 +
 +A small script that sits on the Solaris 10 clients and is executed from the clientlaunch.cfg configuration. Services to be monitored are configured on the Xymon server and passed to the client. This script then checks the status of the individual services are returns the following:
 +Green for '​online'​ services.
 +Yellow for '​uninitialized',​ '​offline'​ or '​degraded'​ services.
 +Red for '​maintenance'​ or '​disabled'​ services.
 +
 +===== Installation =====
 +
 +=== Client side ===
 +
 +1. Copy the script into the ''​client/​ext/''​ sub-directory of every client that you want to monitor.
 +
 +2. Edit the ''​client/​etc/​clientlaunch.cfg''​ of every client from step 1 and insert the following text:
 +
 +  # Service Monitoring
 +  [smf]
 +          ENVFILE $HOBBITCLIENTHOME/​etc/​hobbitclient.cfg
 +          CMD $HOBBITCLIENTHOME/​ext/​smf.sh
 +          LOGFILE $HOBBITCLIENTHOME/​logs/​smf.log
 +          INTERVAL 5m
 +
 +=== Server side ===
 +
 +3. Edit the server/​etc/​client-local.cfg file and insert a line similar to this for each client or section:
 +
 +  svc:/​network/​ssh:​default|svc:/​site/​tftpd:​default|svc:/​site/​apache2:​default
 +
 +All services for a specific server or group must be specified on a single line, separated with a pipe symbol. In the example above we are monitoring three different services, ssh, tftpd and Apache.
 +
 +===== Source =====
 +==== smf.sh ====
 +
 +<hidden onHidden="​Show Code ⇲" onVisible="​Hide Code ⇱">​
 +<code - smf.sh>
 +#!/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
 +</​code>​
 +</​hidden>​
 +
 +===== Known  Bugs and Issues =====
 +
 +None so far.
 +
 +===== To Do =====
 +
 +===== Credits =====
 +
 +===== Changelog =====
 +
 +  * **2010-07-29**
 +    * Initial public release
  
  • monitors/smf.sh.txt
  • Last modified: 2010/07/29 10:51
  • (external edit)