#!/usr/bin/perl ############################################################## # BumbleBeeWare.com 2006 # server monitoring with perl # program to access each server/website and give status response ############################################################## # setup array of servers/websites to check @sitestocheck = ('mywebsite.com','mywebsite2.com'); # the relative url of the website response script in each site $responseprogram = "/cgi-bin/mystatus2.cgi"; # refresh time in seconds 5 minutes is 300 seconds $refreshtime = 300; # path to the log file with the response data $statusfile = "/pathto/statuslog.txt"; ############################################################### # End Configuration ############################################################### # main program use LWP::UserAgent; # print page print "Content-type: text/html\n\n"; print " Server Status "; # now check each url in your array foreach $sitetocheck (@sitestocheck){ $ua = new LWP::UserAgent; $req = new HTTP::Request 'GET',"http://$sitetocheck$responseprogram"; $res = $ua->request($req); if ($res->is_success) { if ($res->content =~ /I AM WORKING/i){$response = $res->content."$sitetocheck
\n";} else {$response = "WARNING! There appears to be a problem, FIX ME!
\n";} } else { $timestamp = localtime; $response = "UNABLE TO CONNECT TO $sitetocheck on $timestamp"; } print "$response"; print "
\n"; # write server status to the log file open(FILE,">>$statusfile"); flock(FILE, 2); print FILE "$response\n\n"; flock(FILE, 8); chmod 0777, $statusfile; # keep the file writeable } print ""; exit;