Xymon Mailing List Archive search

Generating alerts by non-xymon shell scripts

list Deepak Deore
Tue, 23 Sep 2014 10:31:33 -0700
Message-Id: <CABpN7iQ4McZYra5Sy-P7M9-wR=user-ad994f98c4e1@xymon.invalid>

Thanks for the ideas Jeremy (as always :-) ), will check with the first
option.

On Mon, Sep 22, 2014 at 11:47 PM, Jeremy Laidman <user-71895fb2e44c@xymon.invalid>
wrote:
On 23 September 2014 13:34, deepak deore <user-7b03b2a1ee70@xymon.invalid>
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