Using Nagios to check if a webpage is shown correctly


#1

At the moment I have Installed Nagios 2.9 correctly and it is able to check from different servers if there up and running, for example it checks of port 80 from a server is open for connection.
But now I would like to check if a website, that’s on the same webserver, is shown correctly, so I would like to check the content of the webpage. I have searched on the internet of a kind of plugin that can help me do this, but I haven’t found one yet.

So I hope that anyone can help me.


#2

Hi,

excellent question!
I have the same problem, and I didn’t really find a really good way to monitor this.

Anyway, if you can’t find better (if you do, please post it, I’m interested :)), here is what I did:
I installed wget
and I wrote this little script (sorry, some variable names are in french, but it should be ok anyway):

[code]#!/usr/bin/perl

use strict;
use IPC::Open3;

my $URL = $ARGV[0];
my $seuil = $ARGV[1];

my $path = “$ENV{NAGIOS_HOME}/libexec/wget”;

my $command = “time $path/bin/wget -x --no-cache -P $path/download/ -p --delete-after -nv -erobots=off --no-proxy --no-dns-cache --cache=off -H --header=‘Cache-Control: max-age=0, no-cache’ $URL”;

my $seconds = 60;
my $i = 0;
eval {
local $SIG{ALRM} = sub { die “TIMEOUT\n” };
alarm($seconds);
open3(*WRITEHANDLE, *READHANDLE, *ERRHANDLE, $command);
alarm(0); # cancel alarm (if code ran fast)
};
alarm(0); # cancel alarm (if eval failed)
if ( $@ eq “TIMEOUT\n” ) {
print “No response from server\n”;
exit 2;
}

my @result = ;

my $temps_de_recup;
my $previous_line;
my $temps_de_recup_sec;
my $temps_de_recup_milli;
my $temps_de_recup_min;

foreach my $result (@result) {
chomp($result);
if ( $result =~ /wget:(.*)$/ ) {
print “Error while getting the page $URL: $1\n”;
exit 2;
}
if ( ($result =~ /ERROR 404/ || $result =~ /not found/ ) && ( $previous_line!~ /favicon/ && $previous_line!~ /%5C%22/ ) ) {
print “Error 404 found on page $URL: $previous_line\n”;
exit 1;
}
if ( $result =~ /real\s+(\d+)m(\d+).(\d+)/ ) {
$temps_de_recup_min = $1;
$temps_de_recup_sec = $2;
$temps_de_recup_milli = $3;
}
$previous_line = $result;
}

$temps_de_recup = $temps_de_recup_min*60 + $temps_de_recup_sec + $temps_de_recup_milli/1000;

print “Time to get everything: $temps_de_recup sec (seuil: $seuil sec)\n”;
if ( $temps_de_recup > $seuil ) {
exit 1;
}
exit 0;[/code]

the script runs wget, which “gets” the page, and all its elements
So, if a gif is missing, or something like that, you’ll get a warning.

The problem is that wget doesn’t understand flash or javascript …
and it doesn’t take into account the global layout.

So, all it does is get the time it takes to load the page, and check that all your components are accessible.
It’s not much, but it’s better than nothing :slight_smile:


#3

Depends what you want to check. Is the page static? you could wget it then md5sum it. It’s probably not static though right? Loose’s script might be able to help you if you’re looking for missing page elements.

Otherwise if you need something a lot more powerful, have a look at WebInject. It is built specifically for this type of stuff:

webinject.org/

It is pretty pimped and should be able to do whatever you need it to. We use it to test if you can log in to a secured website.


#4

Okay, thank you for the advise, I have just read the website from webinject, but I can’t really find how to install the plugin for Nagios.
I have allready installed the extra packages from pearl, that are neede by WebInject, but I can’t find how to install webinject itself on my Linux server. Because I can only acces the Linux server through an terminal session with ssh from my XP machine.

So I hope you can tell me how to do that, or point me in a direction where I can find a tutorial or something about is.


#5

Have a look here:

webinject.org/plugin.html

It explains how to use webinject with Nagios. You don’t have to “install” webinject, it’s just a set of perl scripts and xml files. You just type “perl /path/to/webinject.pl …”

Read through the plugin examples on the link i just gave you, hopefully you can get what you want out of it, otherwise you’re going to have to run webinject in console mode and parse the output using a scripting language like shell, perl, or python


#6

Thanks, I got it working from the command line now, there I can type “./webinject.pl -c config.xml testcase.xml” and as result I get the message that all the testcases are passed succesfully.
But when I try to run it from Nagios, I get the error message with “(No Output!)”, but I can’t find the problem, because from the command line it really works.


#7

Hi,

First thing: the option “-c config.xml” is not required, as, by default, webinject will read this file.
Also, make sure you have the line:
nagios
in your config.xml file

but this should not really correct your “no output!” problem. For this, check your “event log” in the nagios web interface; it may help you…
Also, bear in mind that nagios may not have all the necessary environnment variables, so you may have to add some at the begining of weinject.pl


#8

What do you mean by “necessary environment variables”?
I also have the reporttype set to nagios, that’s what I found on the configuration page on webinject.org.

I also checked the permissions of the files in the webinject location, so that the would be the same as the plugins allready installed in Nagios, but I still get the same error message.


#9

(No Output!) is usually a permissions problem. Try switching to your nagios user (su - nagios) and running your webinject command again. If it gives some sort of error, you could try adding this to your sudoers file:
nagios ALL=(ALL) NOPASSWD: /path/to/webinject.pl