CheckSecureWebSite.pl
Subscribe

From OpenNMS

Jump to: navigation, search
#!/usr/bin/perl
# $Id: CheckSecureWebSite.pl 796 2006-03-16 21:13:02Z ski $ 
# $URL: http://svn/svn/sys/code/OpenNMS/CheckSecureWebSite.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 secure 
# 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::UserAgent;
use Getopt::Long;

# Variables
my $debug = 1; # set to 1 to write debugging to /tmp/CheckWebSite.log
my $timeout = 0;
my $result = 0;
my ($ua, $res, $req, $host, $url, $port_path, $grep_string);

open(LOG,">>/tmp/CheckSecureWebSite.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 = "https://".$host.$port_path;

$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET => "$url");
$res = $ua->request($req);
$page = $res->as_string;
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;