sub ckserv{
#Check the current server
$currentserver=@_[0];
#The first argument passed
$currentip=@_[1];
$found=0;
open (SP, "schedule.txt");
while (<SP>){
chomp;
s/((?:\w|-)+),(\w+) (\d+)\/(\d+)\/(\d+) (\d+):(\d+):(\d+) to (\d+)\/(\d+)\/
(\d+) (\d+):(\d+):(\d+)/ $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14/;
# $1 - servername
# $2 - ignore once|weekly|monthly
# $3 - begin month
# $4 - begin day
# $5 - begin year
# $6 - begin hour
# $7 - begin minute
# $8 - begin second
# $9 - end month
# $10 - end day
# $11 - end year
# $12 - end hour
# $13 - end minute
# $14 - end second
$timeb=timelocal($8,$7,$6,$4,$3-1,$5);
#full time of beginning of ignore (default time
# format in seconds since 1/1/1970)
$timee=timelocal($14,$13,$12,$10,$9-1,$11);
#full time of end of ignore
$timebdwk=timelocal($8,$7,$6,1,0,0);
#hour/min/sec portion of beginning of ignore in time format
$timeedwk=timelocal($14,$13,$12,1,0,0);
#hour/min/sec portion of end of ignore in time format
($secb,$minb,$hourb,$mdayb,$monb,$yearb,$wdayb,$ydayb,$isdstb)=localtime($timeb);
#split out the parts of the begin of ignore
($sece,$mine,$houre,$mdaye,$mone,$yeare,$wdaye,$ydaye,$isdste)=localtime($timee);
#split out the parts of the end of ignore
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
#split out the parts of the current time
$timeedwkn=timelocal($sec,$min,$hour,1,0,0);
#hour/min/sec portion of current time in time format
if ((($2 eq 'weekly' && $timeedwkn le $timeedwk && $timeedwkn ge
$timebdwk && $wdayb eq $wday)
||
($2 eq 'monthly' && $timeedwkn le $timeedwk && $timeedwkn ge
$timebdwk && $mdayb eq $mday)
||
($2 eq 'once' && time le $timee&& time ge $timeb))
&&
(($1 eq 'everybodydown')
||
($1 eq $currentserver))){
$found=1;
}
}
if(pf()){
# 10 pings has to fail 4 times before Mon Pages
open (PM,">> mon.txt");
print PM "10 pings to server ".$currentserver.", but router passed \n";
close PM;
printtime();
if(pf()){
open (PM,">> mon.txt");
print PM "20 pings to server ".$currentserver.", but router passed \n";
close PM;
printtime();
if(pf()){
open (PM,">> mon.txt");
print PM "30 pings to server ".$currentserver.", but router passed \n";
close PM;
printtime();
if(pf()){
if($found ne 1){
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$mon++;
my %mail = ( To => 'agatha@nospam.com',
From => 'pingmon@nospam.com',
Message => $text,
Subject => $currentserver." is down!",
SMTP => '16.4.23.4'
);
sendmail(%mail) or die $Mail::Sendmail::error;
open (PM,">> mon.txt");
print PM "Server down -- Sending Page\n";
close PM;
}
else{
my %mail = ( To => 'agatha@nospam.com',
From => 'pingmon@nospam.com',
Message => $text,
Subject => $currentserver." Scheduled Downtime",
SMTP => '16.4.23.4'
);
sendmail(%mail) or die $Mail::Sendmail::error;
open (PM,">>mon.txt");
print PM "Server down -- scheduled\n";
close PM;
}
}
printtime();
}
}
}
}
|