Wednesday, March 5, 2008

Simple URL Monitoring. Is it Up or Down - that simple...

How many times have just wanted to know is the URL UP or Down? There are many great products available for purchase, but do so much more. While an all inclusive product is great, sometimes simpler is better.

Here is my simple URL Monitor written in PERL. The base Activestate PERL download includes all of the required modules for this code to run on Windows. This utility will be bundled with the 1.4 release of OpenESM. This monitor does not require any Tivoli resources.

#!c:/perl/bin/perl
use Time::HiRes;
use HTTP::Request;
use LWP::UserAgent;
use Time::localtime;
my $URLOUT="openesm_url_perfmon.txt";
my $URLLIST= shift;

open(IN, "$URLLIST");
while() {
chomp;
$URL = $_;
$now = ctime();
$s1 = Time::HiRes::time;
$ua = LWP::UserAgent->new;
#UNCOMMENT THE LINE BELOW AND INSERT YOUR PROXY NAME IF NEEDED
#$ua->proxy('http', 'http://xx.xx.xx.xx:8080/');
$request = HTTP::Request->new(GET => $URL);
$response = $ua->request($request);
$ucode = $response->code,;
$umess = $response->message,;
$s2 = Time::HiRes::time;
$resptime = ($s2 - $s1);
$OUTFILE = ">> $URLOUT";
open(OUT, $OUTFILE);
print OUT "$now,$URL,$resptime,$umess,$ucode";
#INSERT ALERTING LOGIC HERE
#SUCH AS WPOSTEMSG OR SNMPTRAP
}
close(OUT);

No comments: