FW: HTTP Monitoring - looking for expected output / erroring on expected output

nagios at mm.quex.org nagios at mm.quex.org
Thu Oct 28 07:13:38 CEST 2004


On Wed, Oct 27, 2004 at 09:28:06AM -0500, Rodney Caston wrote:
> 
> 
> The expected output showed up in the ML wrong, it should look like
> this: (ignore the blank lines they don't show up like that in
> practice, they're just here to make sure the formatting is one entry
> per line for this email to the ML)

Actually it showed up fine in the mailing list.  If you look at
the top of the message preview/window in Outlook, you should see
some text that says "Extra line breaks in this message were
removed".  Click on it and you can tell Outlook to restore the
line breaks.

As for your problem...

> -----Original Message-----
> 
> We have a URL we need to monitoring across a large server farm, this URL
> when going to say a URL such as
> http://192.168.0.100/monitorfoo.cfm?test=all
> 
> The expected output will look like this:
> 
> CFUNSTUFF,INTWEB026,OK,N/A,0,2004-10-27 23:47:46
> INITIALJUNK4,INTWEB026,OK,N/A,125,2004-10-27 23:47:46
> JUNK10,INTWEB026,OK,N/A,1407,2004-10-27 23:47:48
> STUFF47,INTWEB026,OK,N/A,78,2004-10-27 23:47:48
> IISQUEUE5,INTWEB026,OK,N/A,31,2004-10-27 23:47:48

It's easy to write plugins for Nagios, so just do as someone
else suggested and write a simple script using wget & grep,
or a python/perl/php/whatever-your-favourite-language script
or program to retrieve the page and check it has the expected
number of lines that say "OK" in them.

The plugin just needs to output one line for Nagios to display,
and exit with 0 if everything's okay, 1 if something's bad,
2 if everything's bad, and some other value if it just has
no idea what's going on.

Something like the following completely untested code could
give you a start for a basic script:


#!/bin/bash

export PATH=/bin:/usr/bin:/sbin:/usr/sbin;

tmpfile=$(mktemp -t check.XXXXXX 2>/dev/null);
if [ $? -ne 0 ];
then
  echo "UNKNOWN: could not create temp file";
  exit 3;
fi

wget -O "$tmpfile" http://foo/bar >/dev/null 2>&1;
if [ $? -ne 0 ];
then
  echo "CRITICAL: could not retrieve URL";
  rm -f "$tmpfile";
  exit 2;
fi

count=$(wc -l "$tmpfile");
if [ $count -lt 20 ];
then
  echo "WARNING: only $count entries in the magic file.";
  rm -f "$tmpfile";
  exit 1;
fi

bad=$(grep -v ,OK, "$tmpfile" | wc -l);
if [ $bad -gt 0 ];
then
  echo "CRITICAL: found $bad bad entries in file.";
  rm -f "$tmpfile";
  exit 2;
fi

echo "OK: everything is fine.";
rm -f "$tmpfile";
exit 0;



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list