Creating Your Own Hobbit / Xymon Tests
Over the years I’ve had to write plenty of Hobbit / Xymon scripts to monitor various different things within my employers systems. Since most all of our applications are custom there are not always built in tests that will work for us. For example, we use Xen for our development virtual machines and being able to track what was going on with those virtual machines is important and being able to identify a VM within Xymon at a moments glance is important to us, so we created a test that does just that. We have created in house scripts for MySQL Status, MySQL Running Queries, our in house distributed services, Lighttpd (as discussed earlier on this blog), Apache, Memcached, etc. This doesnt include the hundreds of different snmp tests we’ve added to Devmon for monitoring our network equiptment.
Since I’ve had to write quite a few of these I thought I’d share a simple recipe for getting started with these scripts. Most all our scripts are written in Perl, its just what I’m used too and what most people in our company is fluent in. Our older scripts (from when we actually ran Big Brother) are almost all shell scripts and I have written at least one in Python since that particular service’s library was in python. For this example I’m going to use Perl default template:
#!/usr/bin/perl -w
#############################################################################
# $Id: $
#############################################################################
use strict;
## BB and related test constants
#############################################################################
use constant GREEN => 'green';
use constant YELLOW => 'yellow';
use constant RED => 'red';
## BB Global variables
#############################################################################
my $prev_run_log = "$ENV{BBTMP}/$ENV{MACHINE}.lighttpd.data";
my $bbtest = 'testname';
my $color = GREEN;
my $status = $bbtest . " OK";
## Main Program
#############################################################################
{
my $DATA = "";
## TEST STUFF HERE
## Send to Hobbit
#############################################################################
my $report_date = `/bin/date`;
chomp($report_date);
system("$ENV{BB} $ENV{BBDISP} 'status $ENV{MACHINE}.$bbtest $color $report_date - $status\n\n$DATA'\n");
}
This script by itself will send a test called ‘testname’, which is green and has the status of ‘OK’. Since we have not defined anything to test it won’t contain any data with it. To run this script you need to be within Xymon’s “shell”, which is basically sh, with some enviroment variables set. To get there, go to ’bin’ directory within your hobbit client installation, in my case this is: “/home/hobbit/client/bin”, you’ll need to run ‘bbcmd’, this will drop you to a prompt which looks something like this:
[rar@apollo bin]$ ./bbcmd 2009-05-09 10:10:35 Using default environment file /home/hobbit/client/etc/hobbitclient.cfg sh-3.2$
Lets change the test name to something else and gather some data from the system we are running on. To change the test name to say ‘modules’, just change the $bbtest to ‘modules’. How about testing what kernel modules are loaded – or basically just parse the output of ‘lsmod’. To do this we’d need to capture the output of the command, this is easy enough in perl, something like this would work just fine:
my $lsmod = `/sbin/lsmod`;
With the output of ’lsmod’ captured we can do whatever we want with it. Lets say we just want the modules, and no other info about them in an array:
my $lsmod = `/sbin/lsmod`;
my @modules = split(/\n/, $lsmod);
my @module_names;
foreach my $module (@modules){
my ($name, $junk) = split(/\s.+/, $module);
push @module_names, $name;
}
Now that we have our array created that we can easily loop through for tests, lets run a test on them to see if we have loaded any modules for ‘ext’ file systems:
foreach my $module (@module_names) {
if ($module =~ "ext"){
$color = RED;
$status = $bbtest . " NOT OK"
}
}
OK, since we’d like a list of modules that are loaded on our hobbit test page, we can add all those modules to the ‘$DATA’ variable, and finish off this example test. Within that last look we added, you’d just push that modules name into ‘$DATA’:
[...] $status = $bbtest . " NOT OK" } $DATA .= $module . "\n"; }
So what kindof output does this give us? If you want to just see what would be run in the system() call at the bottom of the script, just change ‘system’ to ‘print’, the output should be something like the following:
/home/hobbit/client/bin/bb hobbitserver.xipnet.net 'status apollo.modules red Sat May 9 10:35:18 EDT 2009 - modules NOT OK Module iptable_filter ip_tables rfcomm l2cap bluetooth af_packet nf_conntrack_netbios_ns ipt_REJECT nf_conntrack_ipv4 xt_state nf_conntrack ip6t_REJECT xt_tcpudp ip6table_filter ip6_tables x_tables ipv6 binfmt_misc dm_multipath parport_pc lp parport nvram evbug usbcore ext3 jbd mbcache evdev raid10 raid456 async_xor async_memcpy async_tx xor raid1 raid0 multipath linear md_mod dm_mirror dm_snapshot dm_mod fuse loop 8250 serial_core '
Now the test is red and has the status of “NOT OK” since we tested for any ext file system and I’m running ext3. To have the data sent to hobbit, simply set the print back to a system call and setup the approprate section within ‘clientlaunch.cfg’, for our example I’d use:
[modules] ENVFILE $HOBBITCLIENTHOME/etc/hobbitclient.cfg CMD $HOBBITCLIENTHOME/ext/bb-modules.pl LOGFILE $HOBBITCLIENTHOME/logs/hobbitclient.log INTERVAL 5m
I know this is a pretty basic example, but its a place to start – just let the imagination go from here on the millions of tests you could come up with. Keep in mind I’m sending this data in on the “status” channel in Xymon – there is also a “data” channel which won’t create a column and with the test approprately setup within hobbit to capture its data to rrd’s, you can create graphs that just show up in the “trends” column if alarming is not necessary.
nice writeup, I’m gonna save this link for future reference! It’s crazy how hard it is to find good resources with scripts for hobbit/xymon, in contrast to nagios or something.
Thanks Andrew,
I have installed Xymon and also the integraion with Devmon is done. Do you have any scripts which can help me to do the RMON monitoring via Hobbit or Devmon. Kindly share your views so that I can implement it properly. My email id is amanlamba83@gmail.com. Please share with me all the scripts and information related to hobbit/devmon.
Thanks & Regards,
Aman Lamba.
You can test modules also via file or dir statement by checking the contents of /sys/module/ on a linux machine. You will find all loaded moduels there, too. So you would not necessarily need to write your own test for this purpose.
My 2 cents,
Juergen
Juergen -
The purpose of the exercise was to demonstrate how to build a test in hobbit/xymon. I picked `lsmod` because I wanted a simple command to use as an example of how to parse and deliver data to hobbit/xymon. The example test was not meant to be useful or really used beyond being an example.
Andrew
Hey Andrew,
Thank you very much for the script.
Just for notice i tried to copy and work with the first empty script and it did not work.
the error was Use of uninitialized value in concatenation (.) or string at ext/bb-modules.pl line
after assigning value to $DATA it worked okay meaning line 26 should be like this my $DATA=”";
thanks any how
@Tzach Solomon
Thanks, I’ve updated the post.
Andrew