no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
| — | monitors:smf2.ksh [2010/08/03 05:56] (current) – created - external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== smf2.ksh ====== | ||
| + | |||
| + | ^ Author | [[ everett.vernon@gmail.com | Vernon Everett ]] | | ||
| + | ^ Compatibility | Xymon 4.2 | | ||
| + | ^ Requirements | Solaris 10 | | ||
| + | ^ Download | None | | ||
| + | ^ Last Update | 2010-08-03 | | ||
| + | |||
| + | ===== Description ===== | ||
| + | A somewhat more complex smf monitoring script, heavily inspired by Martin Ward's smf.sh on this site. | ||
| + | Some of the changes - | ||
| + | * switched to ksh to work around some loop " | ||
| + | * changed the config to a "one service per line model" with defined colours. | ||
| + | * allow you to monitor a service in any state - some services should be disabled | ||
| + | * added logic for when a service isn't there at all | ||
| + | * added a " | ||
| + | |||
| + | This script has evolved to the point where it is no longer a drop-in replacement for the Martin' | ||
| + | We can debate the merits of this, but I believe in choice. | ||
| + | |||
| + | Martin' | ||
| + | |||
| + | Mine is more complex, but can do more. | ||
| + | |||
| + | Pick your poison. | ||
| + | |||
| + | ===== Installation ===== | ||
| + | === Client side === | ||
| + | 1. Copy smf2.ksh to ~$HOME/ | ||
| + | |||
| + | 2. Edit the '' | ||
| + | |||
| + | # Service Monitoring | ||
| + | [smf] | ||
| + | ENVFILE $HOBBITCLIENTHOME/ | ||
| + | CMD $HOBBITCLIENTHOME/ | ||
| + | LOGFILE $HOBBITCLIENTHOME/ | ||
| + | INTERVAL 5m | ||
| + | |||
| + | === Server side === | ||
| + | 3. Edit the server/ | ||
| + | |||
| + | [myhost] | ||
| + | SVC: | ||
| + | SVC: | ||
| + | SVC: | ||
| + | SVC: | ||
| + | SVC: | ||
| + | SVC: | ||
| + | |||
| + | 4. See script comments for more options | ||
| + | |||
| + | ===== Source ===== | ||
| + | ==== smf2.ksh ==== | ||
| + | |||
| + | <hidden onHidden=" | ||
| + | < | ||
| + | # | ||
| + | |||
| + | # 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. | ||
| + | # V2.0 Updated - Vernon Everett 02 Aug 2010 | ||
| + | # - Switched to ksh to avoid annoying variable issues in loops | ||
| + | # - Changed how the client-local file worked to allow for single service per line | ||
| + | # - Allowed you to specify if the service should be enabled or disabled | ||
| + | # V2.1 Updated - Vernon Everett 03 Aug 2010 | ||
| + | # - Added a NOTINSTALLED option to make sure services shouldn' | ||
| + | # - Added logic to cater for services that are supposed to be there, but are not | ||
| + | # - Drove myself to drink getting my head around all thos bloody if statements. | ||
| + | # - If you think you can clean it up and make it better, please do. | ||
| + | |||
| + | # 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. | ||
| + | # The services themselves are configured on the Hobbit server in the | ||
| + | # ~hobbit/ | ||
| + | # SVC:/ | ||
| + | # SVC:/ | ||
| + | # SVC:/ | ||
| + | # SVC:/ | ||
| + | # SVC:/ | ||
| + | # SVC:/ | ||
| + | # One service per line | ||
| + | # By adding the green colour, it's listed at the top, but doesn' | ||
| + | # for somebody, to ensure the service is highly visible, at the top of the list) | ||
| + | |||
| + | # The name of the column in Hobbit | ||
| + | COLUMN=smf | ||
| + | |||
| + | SVCSCMD=/ | ||
| + | SVCFILE=/ | ||
| + | rm $SVCFILE.check >/ | ||
| + | SVCLIST=$SVCFILE.list | ||
| + | |||
| + | # Get a list of things to check for | ||
| + | grep " | ||
| + | $SVCSCMD -aH > $SVCLIST | ||
| + | # Make sure it's empty. | ||
| + | echo " " > $SVCFILE.out | ||
| + | |||
| + | # Set up the initial colour | ||
| + | COLOUR=green | ||
| + | |||
| + | # Check if we have services to keep tabs on | ||
| + | # If not, drop through, and just report a full list of services. Same as svcs -a | ||
| + | if [ -a ${SVCFILE}.check ] | ||
| + | then | ||
| + | while read SVCID EXPSTATE FCOLOUR | ||
| + | do | ||
| + | LCOLOUR=green | ||
| + | SVCLINE=$(grep $SVCID $SVCLIST) # Now find the service and start checking it | ||
| + | |||
| + | if [ -z " | ||
| + | then | ||
| + | if [ " | ||
| + | then | ||
| + | # This is bad | ||
| + | if [ -n " | ||
| + | then | ||
| + | # A colour was defined for this | ||
| + | | ||
| + | [ " | ||
| + | else | ||
| + | # No colour defined, assume "not there" is really bad. | ||
| + | | ||
| + | | ||
| + | fi | ||
| + | fi | ||
| + | | ||
| + | else | ||
| + | echo " | ||
| + | do | ||
| + | if [ " | ||
| + | then | ||
| + | if [ -n " | ||
| + | then | ||
| + | # It's there and it shouldn' | ||
| + | if [ -n " | ||
| + | then | ||
| + | # A colour was defined for this | ||
| + | | ||
| + | [ " | ||
| + | else | ||
| + | # No colour defined. Figure one out. | ||
| + | if [ " | ||
| + | then | ||
| + | LCOLOUR=" | ||
| + | COLOUR=" | ||
| + | else | ||
| + | LCOLOUR=" | ||
| + | [ " | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | else | ||
| + | if [ " | ||
| + | # it to trigger an alert. Kinda handy for keeping it easily visible. | ||
| + | then | ||
| + | if [ -z " | ||
| + | then | ||
| + | # We never defined an expected state. Assume it should be up or legacy_run | ||
| + | # and anything else is bad - or at least slightly bad | ||
| + | case " | ||
| + | ' | ||
| + | | ||
| + | if [ " | ||
| + | then | ||
| + | COLOUR=" | ||
| + | fi | ||
| + | ;; | ||
| + | ' | ||
| + | | ||
| + | | ||
| + | ;; | ||
| + | ' | ||
| + | LCOLOUR=" | ||
| + | esac | ||
| + | else | ||
| + | # We have defined an expected state, and probably the colour if it fails | ||
| + | if [ " | ||
| + | then | ||
| + | if [ -z " | ||
| + | then | ||
| + | | ||
| + | | ||
| + | else | ||
| + | | ||
| + | [ " | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | fi | ||
| + | done | ||
| + | fi | ||
| + | echo "& | ||
| + | done < ${SVCFILE}.check | ||
| + | fi | ||
| + | echo >> $SVCFILE.out | ||
| + | # Collect a full list of the services. | ||
| + | cat $SVCLIST | ||
| + | |||
| + | # Tell Hobbit about it | ||
| + | $BB $BBDISP " | ||
| + | # And clean up a little | ||
| + | rm -f ${SVCFILE} ${SVCFILE}.out ${SVCFILE}.check ${SVCFILE}.list > /dev/null 2>&1 | ||
| + | exit 0 | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Known Bugs and Issues ===== | ||
| + | None known, but let me know if you find any. | ||
| + | ===== To Do ===== | ||
| + | Fix any bugs reported to me | ||
| + | ===== Credits ===== | ||
| + | As stated above, this script was heavily inspired by the efforts of Martin Ward (see smf.sh) and I am grateful to him for showing me the way. | ||
| + | |||
| + | I guess a certain level of dubious gratitude should go to my colleague who kept wanting the script to do more, and making my life a pain. :-) | ||
| + | |||
| + | ===== Changelog ===== | ||
| + | |||
| + | * **2010-08-03** | ||
| + | * Initial release | ||