[Nagiosplug-checkins] CVS: nagiosplug/plugins-scripts check_ntp.pl,1.12,1.13
Subhendu Ghosh
sghosh at users.sourceforge.net
Tue Feb 11 20:31:04 CET 2003
Update of /cvsroot/nagiosplug/nagiosplug/plugins-scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv11644
Modified Files:
check_ntp.pl
Log Message:
fixed regex for stratum1 peer, added logic for failed ntpq call(e.g. sntp host)
Index: check_ntp.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/check_ntp.pl,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -r1.12 -r1.13
*** check_ntp.pl 4 Feb 2003 05:54:39 -0000 1.12
--- check_ntp.pl 12 Feb 2003 04:30:36 -0000 1.13
***************
*** 56,59 ****
--- 56,60 ----
# changed ntpdc to ntpq - jitter/dispersion is in milliseconds
#
+ # Patch for for regex for stratum1 refid.
require 5.004;
***************
*** 61,65 ****
use strict;
use Getopt::Long;
! use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME);
use lib utils.pm;
use utils qw($TIMEOUT %ERRORS &print_revision &support);
--- 62,66 ----
use strict;
use Getopt::Long;
! use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME $def_jitter);
use lib utils.pm;
use utils qw($TIMEOUT %ERRORS &print_revision &support);
***************
*** 102,105 ****
--- 103,111 ----
}
+ # jitter test params specified
+ if (defined $opt_j || defined $opt_k ) {
+ $def_jitter = 1;
+ }
+
$opt_H = shift unless ($opt_H);
my $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]+)*)$/);
***************
*** 133,136 ****
--- 139,143 ----
}
+
my $stratum = -1;
my $ignoreret = 0;
***************
*** 226,230 ****
# If both exist, the last one is picked.
# Field 2: address of the remote peer
! # Field 3: Refid of the clock (0.0.0.0 if unknown)
# Field 4: stratum (0-15)
# Field 5: Type of the peer: local (l), unicast (u), multicast (m)
--- 233,237 ----
# If both exist, the last one is picked.
# Field 2: address of the remote peer
! # Field 3: Refid of the clock (0.0.0.0 if unknown, WWWV/PPS/GPS if Stratum1)
# Field 4: stratum (0-15)
# Field 5: Type of the peer: local (l), unicast (u), multicast (m)
***************
*** 243,246 ****
--- 250,257 ----
while (<NTPQ>) {
print $_ if ($verbose);
+ if ( /timed out/ ){
+ $have_ntpq = 0 ;
+ last ;
+ }
# number of candidates on <host> for sys.peer
if (/^(\*|\+|\#|o])/) {
***************
*** 250,255 ****
# match sys.peer or pps.peer
! 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.]+)/) {
! $syspeer = $2;
$jitter = $11;
print "match $_ \n" if $verbose;
--- 261,267 ----
# match sys.peer or pps.peer
! 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.]+)/) {
! $syspeer = $2;
! $stratum = $4;
$jitter = $11;
print "match $_ \n" if $verbose;
***************
*** 304,307 ****
--- 316,339 ----
}
+ } elsif( !$have_ntpq ) { # no errors from ntpdate and no ntpq or ntpq timed out
+ if (abs($offset) > $ocrit) {
+ $state = $ERRORS{'CRITICAL'};
+ $answer = "Offset $offset msec > +/- $ocrit sec\n";
+ } elsif (abs($offset) > $owarn) {
+ $state = $ERRORS{'WARNING'};
+ $answer = "Offset $offset msec > +/- $owarn sec\n";
+ } elsif (( abs($offset) > $owarn) && $def_jitter ) {
+ $state = $ERRORS{'WARNING'};
+ $answer = "Offset $offset msec > +/- $owarn sec, ntpq timed out\n";
+ } elsif ( $def_jitter ) {
+ $state = $ERRORS{'WARNING'};
+ $answer = "Offset $offset secs, ntpq timed out\n";
+ } else{
+ $state = $ERRORS{'OK'};
+ $answer = "Offset $offset secs \n";
+ }
+
+
+
} else { # no errors from ntpdate or ntpq
if (abs($offset) > $ocrit) {
***************
*** 320,336 ****
} else {
$state = $ERRORS{'OK'};
! $answer = "Offset $offset secs, jitter $jitter msec\n";
}
- # else { # no offset defined
- # $state = $ERRORS{'UNKNOWN'};
- # $answer = "Invalid format returned from ntpdate ($msg)\n";
- # }
-
}
foreach my $key (keys %ERRORS) {
if ($state==$ERRORS{$key}) {
! print ("$key: $answer");
last;
}
--- 352,363 ----
} else {
$state = $ERRORS{'OK'};
! $answer = "Offset $offset secs, jitter $jitter msec, peer is stratum $stratum\n";
}
}
foreach my $key (keys %ERRORS) {
if ($state==$ERRORS{$key}) {
! print ("NTP $key: $answer");
last;
}
***************
*** 348,352 ****
sub print_help () {
print_revision($PROGNAME,'$Revision$');
! print "Copyright (c) 2000 Bo Kersey/Karl DeBisschop\n";
print "\n";
print_usage();
--- 375,379 ----
sub print_help () {
print_revision($PROGNAME,'$Revision$');
! print "Copyright (c) 2003 Bo Kersey/Karl DeBisschop\n";
print "\n";
print_usage();
***************
*** 361,365 ****
Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_WARN.
-k (--jcrit)
! Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_CRIT.\n";
! support();
}
--- 388,396 ----
Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_WARN.
-k (--jcrit)
! Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_CRIT.\n
!
! If jitter/dispersion is specified with -j or -k and ntpq times out, then a
! warning is returned.
! ";
! support();
}
More information about the Commits
mailing list