Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

monitoring NTP



Tom Metro <tmetro-blu-5a1Jt6qxUNc at public.gmane.org> asked:
> [ntpd monitoring script] needs to periodically check the the delta
> between itself and another server and complain when a threshold is
> exceeded.

I use the output of 'ntpdc -p' to verify that the local server is in sync with
at least one non-local one, which catches 99% of problems.

Below is a simple perl script which works with Nagios.

-rich

#!/usr/bin/perl  -w
# $Id: check_valid_time.pl,v 1.2 2009/05/13 18:37:43 rbraun Exp $

$ntpdc='/usr/sbin/ntpdc';
$awk='/bin/awk';

$warn_thresh=.75;
$crit_thresh=100;

$ok_exit=0;
$warning_exit=1;
$critical_exit=2;
$unknown_exit=3;
$fields='$1,$7';


my $cmd = "$ntpdc -p | $awk '/*/ {print $fields}'" ;
($auth_server,$offset)=split(' ',`$cmd`);

if ($auth_server =~ m/LOCAL/) {
print "$auth_server server untrusted for NTP check, offset $offset\n";
exit $critical_exit;
}

if ($auth_server eq "") {
print "No auth server exists\n";
exit $critical_exit;
}

$offset=abs($offset);

if ($offset =~ m/[A-Z]/ ) {
print "$offset from $auth_server could not be evaluated.\n";
exit $unknown_exit;
}
elsif ($offset =~ m/[a-d]/ ) {
print "$offset from $auth_server could not be evaluated.\n";
exit $unknown_exit;
}
elsif ($offset =~ m/[f-z]/ ) {
print "$offset from $auth_server could not be evaluated.\n";
exit $unknown_exit;
}
elsif ($offset >= $crit_thresh) {
print "$offset seconds from $auth_server.\n";
exit $critical_exit;
}
elsif ($offset >= $warn_thresh) {
print "$offset seconds from $auth_server.\n";
exit $warning_exit;
}
elsif ($offset >= $crit_thresh) {
print "$offset seconds from $auth_server.\n";
exit $critical_exit;
}
elsif ($offset >= 0) {
print "$offset seconds from $auth_server.\n";
exit $ok_exit;
}
else {
print "Something's wrong, offset=$offset, auth_server=$auth_server\n";
exit $unknown_exit;
}






BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org