summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xplugins-scripts/check_ntp.pl59
1 files changed, 45 insertions, 14 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl
index 2215fbd..67c0a6a 100755
--- a/plugins-scripts/check_ntp.pl
+++ b/plugins-scripts/check_ntp.pl
@@ -55,12 +55,13 @@
55# ntpdate - offset is in seconds 55# ntpdate - offset is in seconds
56# changed ntpdc to ntpq - jitter/dispersion is in milliseconds 56# changed ntpdc to ntpq - jitter/dispersion is in milliseconds
57# 57#
58# Patch for for regex for stratum1 refid.
58 59
59require 5.004; 60require 5.004;
60use POSIX; 61use POSIX;
61use strict; 62use strict;
62use Getopt::Long; 63use Getopt::Long;
63use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME); 64use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME $def_jitter);
64use lib utils.pm; 65use lib utils.pm;
65use utils qw($TIMEOUT %ERRORS &print_revision &support); 66use utils qw($TIMEOUT %ERRORS &print_revision &support);
66 67
@@ -101,6 +102,11 @@ if ($opt_h) {
101 exit $ERRORS{'OK'}; 102 exit $ERRORS{'OK'};
102} 103}
103 104
105# jitter test params specified
106if (defined $opt_j || defined $opt_k ) {
107 $def_jitter = 1;
108}
109
104$opt_H = shift unless ($opt_H); 110$opt_H = shift unless ($opt_H);
105my $host = $1 if ($opt_H && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/); 111my $host = $1 if ($opt_H && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/);
106unless ($host) { 112unless ($host) {
@@ -132,6 +138,7 @@ if ($opt_k < $opt_j) {
132 exit $ERRORS{'UNKNOWN'}; 138 exit $ERRORS{'UNKNOWN'};
133} 139}
134 140
141
135my $stratum = -1; 142my $stratum = -1;
136my $ignoreret = 0; 143my $ignoreret = 0;
137my $answer = undef; 144my $answer = undef;
@@ -225,7 +232,7 @@ if ( $? && !$ignoreret ) {
225# or 'o' which implies pps.peer 232# or 'o' which implies pps.peer
226# If both exist, the last one is picked. 233# If both exist, the last one is picked.
227# Field 2: address of the remote peer 234# Field 2: address of the remote peer
228# Field 3: Refid of the clock (0.0.0.0 if unknown) 235# Field 3: Refid of the clock (0.0.0.0 if unknown, WWWV/PPS/GPS if Stratum1)
229# Field 4: stratum (0-15) 236# Field 4: stratum (0-15)
230# Field 5: Type of the peer: local (l), unicast (u), multicast (m) 237# Field 5: Type of the peer: local (l), unicast (u), multicast (m)
231# broadcast (b); not sure about multicast/broadcast 238# broadcast (b); not sure about multicast/broadcast
@@ -242,6 +249,10 @@ if ($have_ntpq) {
242 if ( open(NTPQ,"$utils::PATH_TO_NTPQ -np $host 2>&1 |") ) { 249 if ( open(NTPQ,"$utils::PATH_TO_NTPQ -np $host 2>&1 |") ) {
243 while (<NTPQ>) { 250 while (<NTPQ>) {
244 print $_ if ($verbose); 251 print $_ if ($verbose);
252 if ( /timed out/ ){
253 $have_ntpq = 0 ;
254 last ;
255 }
245 # number of candidates on <host> for sys.peer 256 # number of candidates on <host> for sys.peer
246 if (/^(\*|\+|\#|o])/) { 257 if (/^(\*|\+|\#|o])/) {
247 ++$candidates; 258 ++$candidates;
@@ -249,8 +260,9 @@ if ($have_ntpq) {
249 } 260 }
250 261
251 # match sys.peer or pps.peer 262 # match sys.peer or pps.peer
252 if (/^(\*|o)([-0-9.\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([lumb]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) { 263 if (/^(\*|o)([-0-9.\s]+)\s+([-0-9WwVvGgPpSs.]+)\s+([-0-9.]+)\s+([lumb]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) {
253 $syspeer = $2; 264 $syspeer = $2;
265 $stratum = $4;
254 $jitter = $11; 266 $jitter = $11;
255 print "match $_ \n" if $verbose; 267 print "match $_ \n" if $verbose;
256 if ($jitter > $jcrit) { 268 if ($jitter > $jcrit) {
@@ -303,6 +315,26 @@ if ($ntpdate_error != $ERRORS{'OK'}) {
303 $answer = "Jitter error and jitter $jitter msec > +/- $jwarn msec\n"; 315 $answer = "Jitter error and jitter $jitter msec > +/- $jwarn msec\n";
304 } 316 }
305 317
318} elsif( !$have_ntpq ) { # no errors from ntpdate and no ntpq or ntpq timed out
319 if (abs($offset) > $ocrit) {
320 $state = $ERRORS{'CRITICAL'};
321 $answer = "Offset $offset msec > +/- $ocrit sec\n";
322 } elsif (abs($offset) > $owarn) {
323 $state = $ERRORS{'WARNING'};
324 $answer = "Offset $offset msec > +/- $owarn sec\n";
325 } elsif (( abs($offset) > $owarn) && $def_jitter ) {
326 $state = $ERRORS{'WARNING'};
327 $answer = "Offset $offset msec > +/- $owarn sec, ntpq timed out\n";
328 } elsif ( $def_jitter ) {
329 $state = $ERRORS{'WARNING'};
330 $answer = "Offset $offset secs, ntpq timed out\n";
331 } else{
332 $state = $ERRORS{'OK'};
333 $answer = "Offset $offset secs \n";
334 }
335
336
337
306} else { # no errors from ntpdate or ntpq 338} else { # no errors from ntpdate or ntpq
307 if (abs($offset) > $ocrit) { 339 if (abs($offset) > $ocrit) {
308 $state = $ERRORS{'CRITICAL'}; 340 $state = $ERRORS{'CRITICAL'};
@@ -319,19 +351,14 @@ if ($ntpdate_error != $ERRORS{'OK'}) {
319 351
320 } else { 352 } else {
321 $state = $ERRORS{'OK'}; 353 $state = $ERRORS{'OK'};
322 $answer = "Offset $offset secs, jitter $jitter msec\n"; 354 $answer = "Offset $offset secs, jitter $jitter msec, peer is stratum $stratum\n";
323 } 355 }
324 356
325# else { # no offset defined
326# $state = $ERRORS{'UNKNOWN'};
327# $answer = "Invalid format returned from ntpdate ($msg)\n";
328# }
329
330} 357}
331 358
332foreach my $key (keys %ERRORS) { 359foreach my $key (keys %ERRORS) {
333 if ($state==$ERRORS{$key}) { 360 if ($state==$ERRORS{$key}) {
334 print ("$key: $answer"); 361 print ("NTP $key: $answer");
335 last; 362 last;
336 } 363 }
337} 364}
@@ -347,7 +374,7 @@ sub print_usage () {
347 374
348sub print_help () { 375sub print_help () {
349 print_revision($PROGNAME,'$Revision$'); 376 print_revision($PROGNAME,'$Revision$');
350 print "Copyright (c) 2000 Bo Kersey/Karl DeBisschop\n"; 377 print "Copyright (c) 2003 Bo Kersey/Karl DeBisschop\n";
351 print "\n"; 378 print "\n";
352 print_usage(); 379 print_usage();
353 print " 380 print "
@@ -360,6 +387,10 @@ Checks the jitter/dispersion of clock signal between <host> and its sys.peer wit
360-j (--jwarn) 387-j (--jwarn)
361 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_WARN. 388 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_WARN.
362-k (--jcrit) 389-k (--jcrit)
363 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_CRIT.\n"; 390 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_CRIT.\n
364 support(); 391
392 If jitter/dispersion is specified with -j or -k and ntpq times out, then a
393 warning is returned.
394";
395support();
365} 396}