#
# Built to determine time difference between node and node's gateway
#
@array = `ipconfig /all`;
foreach $line ( @array )
{
chomp $line;
if ( $line =~ "IP Address" )
{
$ipLine = $line;
if ( $ipLine =~ " 10." )
{
@ipLine = split(": ", $ipLine);
$ip = @ipLine[1];
$ndx = rindex($ip, ".") + 1;
$gateway = substr $ip, 0, $ndx;
$gateway = $gateway . "1";
}
}
}
@result = `w32tm /stripchart /computer:$gateway /dataonly /samples:1`;
foreach $timeLine ( @result )
{
chomp $timeLine;
if ( $timeLine =~ ", " )
{
@arrTime = split(", ", $timeLine);
if ( @arrTime[1] =~ "error: " )
{
print "@arrTime[1]\n";
$timeDiff = "ERR";
}
else
{
$timeDiff = @arrTime[1] / 60;
$timeDiff = round($timeDiff);
}
}
}
if ( $timeDiff eq "ERR" )
{
`opcmsg a=TimeCheck o=TimeCheck msg_t="Time check on node can not communicate with time server." s=critical`;
}
elsif ( $timeDiff >= 2 || $timeDiff <= -2 )
{
`opcmsg a=TimeCheck o=TimeCheck msg_t="Time is off by more than 2 minutes ( approx. difference: $timeDiff minutes ) on node" s=critical`;
}
sub round
{
my $number = $_[0];
return int($number + .5 * ( $number <=> 0));
}
Comments
You can follow this conversation by subscribing to the comment feed for this post.