[Xymon] Generating alerts by non-xymon shell scripts

Jeremy Laidman jlaidman at rebel-it.com.au
Tue Sep 23 08:47:41 CEST 2014


On 23 September 2014 13:34, deepak deore <deepakdeore2004 at gmail.com> wrote:

> Do we need to source xymonclient.cfg into normal shell scripts so that $BB
> $BBDISP $MACHINE etc. variables will work?


Not absolutely required, but depending on how clever you want to be, they
can be helpful.

To give you an idea, this might do what you want, without setting any
variables:

#!/bin/sh

cp /path/to/access-file /path/to/access-file.backup
printf "allow him\ndeny her\nallow from all\n" > /path/to/access-file
if apachectl -t >/dev/null; then
    # is OK
    apachectl graceful
    /usr/lib/xymon/client/bin/xymon 10.1.2.3 "status `uname -n`.apachecheck
green `date` everything's fine with apache"
else
    # is failed
    cp /path/to/access-file /path/to/access-file.bad
    cp /path/to/access-file.backup /path/to/access-file
     /usr/lib/xymon/client/bin/xymon 10.1.2.3 "status `uname
-n`.apachecheck red `date` something's not right with apache"
fi

Now the problem arises when you add a second Xymon server, or if you change
IP addresses of the Xymon server.  The 10.1.2.3 is no longer suitable.  So
that's when you want to define $XYMSERVERS="10.1.2.3 10.4.5.6" and then
specify 0.0.0.0 as the server instead of 10.1.2.3, and then the xymon
client will post messages to both servers as listed in the $XYMSERVERS
environment variable.

Then let's say you want to run the script on another Apache server, but it
has its Xymon client installed in a different location.  So you need to
have two versions of the script, one using /usr/lib/xymon/client/bin/xymon
and another using /usr/local/xymon/client/bin/hobbit.

etc

The easiest way to do this is to make use of the variables, and then either
the script within a xymoncmd wrapper (which sets all of the variables you
need) or from tasks.cfg (which can also set the variables you need).  You
end up with something like this:

     $XYMON $XYMSRV "status $MACHINE.apachecheck red `date` something's not
right with apache"

This works on any of your Xymon clients, no matter how they're setup.

Here's another idea.  You can have your script create a log entry using
"logger" and then have Xymon's log watching code detect the anomaly and
warn accordingly.

J
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20140923/ae0e5201/attachment.html>


More information about the Xymon mailing list