From OpenNMS
#!/usr/bin/perl
# $Id: CheckWebSite.pl 795 2006-03-16 21:11:21Z ski $
# $URL: http://svn/svn/sys/code/OpenNMS/CheckWebSite.pl $
#
# Copyright (C) 2006 Ski Kacoroski <kacoroski@comcast.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# Script to be used with OpenNMS to check the page returned from a web
# site to verify everything is correct. Requires the GP Poller plugin.
# Set the GP Poller banner property to "Success". The first argument to
# GP Poller is the url path:
# /
# /password/index.pl
# :8080/wiki/TechWiki
#
# The second argument is the string to search for in the web page. This
# is in single quotes (') so spaces will be passed from GP Poller to
# this script. The quotes are stripped off in this script so you cannot
# search for quotes in a web page.
#
use LWP::Simple;
use Getopt::Long;
# Variables
my $debug = 1; # set to 1 to write debugging to /tmp/CheckWebSite.log
my $timeout = 0;
my $result = 0;
my ($port_path, $host, $grep_string, $url);
open(LOG,">>/tmp/CheckWebSite.log") if $debug;
GetOptions ("H|hostname=s" => \$host,
"t|timeout=i" => \$timeout);
$port_path = @ARGV[0];
$grep_string = @ARGV[1];
print LOG "|$grep_string|\n";
$grep_string =~ s/%20/ /g; #Replace %20 with spaces
$url = "http://".$host.$port_path;
$page = get("$url");
if ($page =~ /$grep_string/) {
print LOG "|$url|$grep_string|Success\n\n$page\n" if $debug;
print "Success";
}
else {
print LOG "|$url|$grep_string|Failure\n\n$page\n" if $debug;
print "Failure";
}
close LOG if $debug;
exit;