Differences

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

Link to this comparison view

tutorials:devel [2009/02/01 03:09] (current)
Line 1: Line 1:
 +Anything that can be automated via a script or a custom program can be added into Xymon. A lot of extension scripts are available for Big Brother at the www.deadcat.net archive, and these will typically work without modifications if you run them in Xymon. Sometimes a few minor tweaks are needed - the Xymon mailing list can help you if you don't know how to go about that.
  
 +But if you have something unique you need to test, writing an extension script is pretty simple. You need to figure out some things:
 +
 +  * What name will you use for the column?
 +  * How will you test it?
 +  * What criteria should decide if the test goes red, yellow or green?
 +  * What extra data from the test will you include in the status message ? 
 +
 +A simple client-side extension script looks like this:
 +
 +<code bash>
 +#!/bin/sh
 +
 +COLUMN=mytest #​ Name of the column
 +COLOR=green #​ By default, everything is OK
 +MSG="​Bad stuff status"​
 +
 +# Do whatever you need to test for something
 +# As an example, go red if /​tmp/​badstuff exists.
 +if test -f /​tmp/​badstuff
 +   then
 +      COLOR=red
 +      MSG="​${MSG}
 + 
 +      `cat /​tmp/​badstuff`
 +      "
 +   else
 +      MSG="​${MSG}
 +
 +      All is OK
 +      "
 +   fi
 +
 +# Tell Xymon about it
 +$BB $BBDISP "​status $MACHINE.$COLUMN $COLOR `date`
 +
 +${MSG}
 +"
 +exit 0
 +</​code>​
 +You will notice that some environment variables are pre-defined:​ BB, BBDISP, MACHINE are all provided by Xymon when you run your script via hobbitlaunch. Also note how the MSG variable is used to build the status message - it starts out with just the "Bad stuff status",​ then you add data to the message when we decided what the status is.
 +
 +To run this, save your script in the ~hobbit/​client/​ext/​ directory (i.e. in the ext/ directory off where you installed the Xymon client), then add a new section to the ~hobbit/​client/​etc/​clientlaunch.cfg file like this:
 +
 +<​code>​
 +[myscript]
 + ENVFILE $HOBBITCLIENTHOME/​etc/​hobbitclient.cfg
 + CMD $HOBBITCLIENTHOME/​ext/​myscript.sh
 + LOGFILE $HOBBITCLIENTHOME/​logs/​myscript.log
 + INTERVAL 5m
 +</​code>​
 +
 +----
 +
 +**Server-side scripts** look almost the same, but they will typically use the bbhostgrep utility to pick out hosts in the bb-hosts file that have a special tag defined, and then send one status message for each of those hosts. Like this:
 +<code bash>
 +#!/bin/sh
 +
 +BBHTAG=foo ​          # What we put in bb-hosts to trigger this test
 +COLUMN=$BBHTAG #​ Name of the column, often same as tag in bb-hosts
 +
 +$BBHOME/​bin/​bbhostgrep $BBHTAG | while read L
 +   do
 +      set $L # To get one line of output from bbhostgrep
 +
 +      HOSTIP="​$1"​
 +      MACHINEDOTS="​$2"​
 +      MACHINE=`echo $2 | $SED -e'​s/​\./,/​g'​`
 +
 +      COLOR=green
 +      MSG="​$BBHTAG status for host $MACHINEDOTS"​
 +
 +      #... do the test, perhaps modify COLOR and MSG
 +
 +      $BB $BBDISP "​status $MACHINE.$COLUMN $COLOR `date`
 +
 +      ${MSG}
 +      "
 +   done
 +
 +exit 0
 +</​code>​
 +
 +:!: Note that for server side tests, you need to loop over the list of hosts found in the bb-hosts file, and send one status message for each host. Other than that, it is just like the client-side tests.
  • tutorials/devel.txt
  • Last modified: 2009/02/01 03:09
  • (external edit)