[Nagiosplug-checkins] CVS: nagiosplug/plugins-scripts check_ntp.pl,1.10,1.11 utils.pm.in,1.5,1.6
Subhendu Ghosh
sghosh at users.sourceforge.net
Mon Feb 3 13:35:21 CET 2003
Update of /cvsroot/nagiosplug/nagiosplug/plugins-scripts
In directory sc8-pr-cvs1:/tmp/cvs-serv21279/plugins-scripts
Modified Files:
check_ntp.pl utils.pm.in
Log Message:
change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
Index: check_ntp.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/check_ntp.pl,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** check_ntp.pl 3 Feb 2003 15:47:21 -0000 1.10
--- check_ntp.pl 3 Feb 2003 20:29:55 -0000 1.11
***************
*** 59,64 ****
use strict;
use Getopt::Long;
! use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $verbose $PROGNAME);
! use lib utils.pm ;
use utils qw($TIMEOUT %ERRORS &print_revision &support);
--- 59,64 ----
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);
***************
*** 72,82 ****
$ENV{'ENV'}='';
Getopt::Long::Configure('bundling');
GetOptions
("V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
! "v" => \$verbose, "verbose" => \$verbose,
"w=f" => \$opt_w, "warning=f" => \$opt_w, # offset|adjust warning if above this number
"c=f" => \$opt_c, "critical=f" => \$opt_c, # offset|adjust critical if above this number
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
--- 72,90 ----
$ENV{'ENV'}='';
+ # defaults in millisec
+ my $DEFAULT_OFFSET_WARN = 60000;
+ my $DEFAULT_OFFSET_CRIT = 120000;
+ my $DEFAULT_JITTER_WARN = 5000;
+ my $DEFAULT_JITTER_CRIT = 10000;
+
Getopt::Long::Configure('bundling');
GetOptions
("V" => \$opt_V, "version" => \$opt_V,
"h" => \$opt_h, "help" => \$opt_h,
! "v" => \$verbose, "verbose" => \$verbose,
"w=f" => \$opt_w, "warning=f" => \$opt_w, # offset|adjust warning if above this number
"c=f" => \$opt_c, "critical=f" => \$opt_c, # offset|adjust critical if above this number
+ "j=s" => \$opt_j, "jwarn=s" => \$opt_j, # jitter warning if above this number
+ "k=s" => \$opt_k, "jcrit=s" => \$opt_k, # jitter critical if above this number
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
***************
*** 99,114 ****
}
! ($opt_w) || ($opt_w = 60);
! my $warning = $1 if ($opt_w =~ /([0-9.]+)/);
! ($opt_c) || ($opt_c = 120);
! my $critical = $1 if ($opt_c =~ /([0-9.]+)/);
! if ($critical < $warning ) {
print "Critical offset should be larger than warning offset\n";
print_usage();
exit $ERRORS{"UNKNOWN"};
}
my $stratum = -1;
--- 107,132 ----
}
! ($opt_w) || ($opt_w = $DEFAULT_OFFSET_WARN);
! my $owarn = $1 if ($opt_w =~ /([0-9.]+)/);
!
! ($opt_c) || ($opt_c = $DEFAULT_OFFSET_CRIT);
! my $ocrit = $1 if ($opt_c =~ /([0-9.]+)/);
! ($opt_j) || ($opt_j = $DEFAULT_JITTER_WARN);
! my $jwarn = $1 if ($opt_j =~ /([0-9]+)/);
+ ($opt_k) || ($opt_k = $DEFAULT_JITTER_CRIT);
+ my $jcrit = $1 if ($opt_k =~ /([0-9]+)/);
! if ($ocrit < $owarn ) {
print "Critical offset should be larger than warning offset\n";
print_usage();
exit $ERRORS{"UNKNOWN"};
}
+ if ($opt_k < $opt_j) {
+ print "Critical jitter should be larger than warning jitter\n";
+ print_usage();
+ exit $ERRORS{'UNKNOWN'};
+ }
my $stratum = -1;
***************
*** 116,132 ****
my $answer = undef;
my $offset = undef;
my $msg; # first line of output to print if format is invalid
my $state = $ERRORS{'UNKNOWN'};
my $ntpdate_error = $ERRORS{'UNKNOWN'};
! my $dispersion_error = $ERRORS{'UNKNOWN'};
! my $key = undef;
! # some systems don't have a proper ntpdc/xntpdc
! my $have_ntpdc = undef;
! if ($utils::PATH_TO_NTPDC && -x $utils::PATH_TO_NTPDC ) {
! $have_ntpdc = 1;
}else{
! $have_ntpdc = 0;
}
--- 134,152 ----
my $answer = undef;
my $offset = undef;
+ my $jitter = undef;
+ my $syspeer = undef;
+ my $candidates = 0;
my $msg; # first line of output to print if format is invalid
my $state = $ERRORS{'UNKNOWN'};
my $ntpdate_error = $ERRORS{'UNKNOWN'};
! my $jitter_error = $ERRORS{'UNKNOWN'};
! # some systems don't have a proper ntpq (migrated from ntpdc)
! my $have_ntpq = undef;
! if ($utils::PATH_TO_NTPQ && -x $utils::PATH_TO_NTPQ ) {
! $have_ntpq = 1;
}else{
! $have_ntpq = 0;
}
***************
*** 195,220 ****
###
###
! ### Then scan xntpdc/ntpdc if it exists
! ### and look in the 8th column for dispersion (ntpd v4) or jitter (ntpd v3)
###
! if ($have_ntpdc) {
! if ( open(NTPDC,"$utils::PATH_TO_NTPDC -s $host 2>&1 |") ) {
! while (<NTPDC>) {
print $_ if ($verbose);
! if (/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) {
! if ($8 gt $critical) {
! print "Dispersion_crit = $8 :$critical\n" if ($verbose);
! $dispersion_error = $ERRORS{'CRITICAL'};
! } elsif ($8 gt $warning ) {
! print "Dispersion_warn = $8 :$warning \n" if ($verbose);
! $dispersion_error = $ERRORS{'WARNING'};
} else {
! $dispersion_error = $ERRORS{'OK'};
}
}
}
! close NTPDC;
}
}
--- 215,266 ----
###
###
! ### Then scan xntpq/ntpq if it exists
! ### and look in the 11th column for jitter
###
+ # Field 1: Tally Code ( Space, 'x','.','-','+','#','*','o')
+ # Only match for '*' which implies sys.peer
+ # or 'o' which implies pps.peer
+ # 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)
+ # broadcast (b); not sure about multicast/broadcast
+ # Field 6: last packet receive (in seconds)
+ # Field 7: polling interval
+ # Field 8: reachability resgister (octal)
+ # Field 9: delay
+ # Field 10: offset
+ # Field 11: dispersion/jitter
+ #
! if ($have_ntpq) {
! if ( open(NTPQ,"$utils::PATH_TO_NTPQ -np $host 2>&1 |") ) {
! while (<NTPQ>) {
print $_ if ($verbose);
! # number of candidates on <host> for sys.peer
! if (/^(\*|\+|\#|o])/) {
! ++$candidates;
! print "Candiate count= $candidates\n" if ($verbose);
! }
!
! # 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;
! if ($jitter > $jcrit) {
! print "Jitter_crit = $11 :$jcrit\n" if ($verbose);
! $jitter_error = $ERRORS{'CRITICAL'};
! } elsif ($jitter > $jwarn ) {
! print "Jitter_warn = $11 :$jwarn \n" if ($verbose);
! $jitter_error = $ERRORS{'WARNING'};
} else {
! $jitter_error = $ERRORS{'OK'};
}
}
}
! close NTPQ;
}
}
***************
*** 230,269 ****
}
! if (defined($offset) && abs($offset) > $critical) {
$state = $ERRORS{'CRITICAL'};
! $answer = "Server Error and time difference $offset seconds greater than +/- $critical sec\n";
! } elsif (defined($offset) && abs($offset) > $warning) {
! $answer = "Server error and time difference $offset seconds greater than +/- $warning sec\n";
}
! } elsif ($have_ntpdc && $dispersion_error != $ERRORS{'OK'}) {
! $state = $dispersion_error;
! $answer = "Dispersion too high\n";
! if (defined($offset) && abs($offset) > $critical) {
$state = $ERRORS{'CRITICAL'};
! $answer = "Dispersion error and time difference $offset seconds greater than +/- $critical sec\n";
! } elsif (defined($offset) && abs($offset) > $warning) {
! $answer = "Dispersion error and time difference $offset seconds greater than +/- $warning sec\n";
! }
!
! } else { # no errors from ntpdate or xntpdc
! if (defined $offset) {
! if (abs($offset) > $critical) {
! $state = $ERRORS{'CRITICAL'};
! $answer = "Time difference $offset seconds greater than +/- $critical sec\n";
! } elsif (abs($offset) > $warning) {
! $state = $ERRORS{'WARNING'};
! $answer = "Time difference $offset seconds greater than +/- $warning sec\n";
! } elsif (abs($offset) <= $warning) {
! $state = $ERRORS{'OK'};
! $answer = "Time difference $offset seconds\n";
! }
! } else { # no offset defined
! $state = $ERRORS{'UNKNOWN'};
! $answer = "Invalid format returned from ntpdate ($msg)\n";
}
}
! foreach $key (keys %ERRORS) {
if ($state==$ERRORS{$key}) {
print ("$key: $answer");
--- 276,331 ----
}
! if (defined($offset) && abs($offset) > $ocrit) {
$state = $ERRORS{'CRITICAL'};
! $answer = "Server Error and offset $offset msec > +/- $ocrit msec\n";
! } elsif (defined($offset) && abs($offset) > $owarn) {
! $answer = "Server error and offset $offset msec > +/- $owarn msec\n";
! } elsif (defined($jitter) && abs($jitter) > $jcrit) {
! $answer = "Server error and jitter $jitter msec > +/- $jcrit msec\n";
! } elsif (defined($jitter) && abs($jitter) > $jwarn) {
! $answer = "Server error and jitter $jitter msec > +/- $jwarn msec\n";
}
! } elsif ($have_ntpq && $jitter_error != $ERRORS{'OK'}) {
! $state = $jitter_error;
! $answer = "Jitter $jitter too high\n";
! if (defined($offset) && abs($offset) > $ocrit) {
$state = $ERRORS{'CRITICAL'};
! $answer = "Jitter error and offset $offset msec > +/- $ocrit msec\n";
! } elsif (defined($offset) && abs($offset) > $owarn) {
! $answer = "Jitter error and offset $offset msec > +/- $owarn msec\n";
! } elsif (defined($jitter) && abs($jitter) > $jcrit) {
! $answer = "Jitter error and jitter $jitter msec > +/- $jcrit msec\n";
! } elsif (defined($jitter) && abs($jitter) > $jwarn) {
! $answer = "Jitter error and jitter $jitter msec > +/- $jwarn msec\n";
}
+
+ } else { # no errors from ntpdate or ntpq
+ if (abs($offset) > $ocrit) {
+ $state = $ERRORS{'CRITICAL'};
+ $answer = "Offset $offset msec > +/- $ocrit msec, jitter $jitter msec\n";
+ } elsif (abs($jitter) > $jcrit ) {
+ $state = $ERRORS{'CRITICAL'};
+ $answer = "Jitter $jitter msec> +/- $jcrit msec, offset $offset msec \n";
+ } elsif (abs($offset) > $owarn) {
+ $state = $ERRORS{'WARNING'};
+ $answer = "Offset $offset msec > +/- $owarn msec, jitter $jitter msec\n";
+ } elsif (abs($jitter) > $jwarn ) {
+ $state = $ERRORS{'WARNING'};
+ $answer = "Jitter $jitter msec> +/- $jwarn msec, offset $offset msec \n";
+
+ } else {
+ $state = $ERRORS{'OK'};
+ $answer = "Offset $offset msecs, 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");
***************
*** 273,278 ****
exit $state;
sub print_usage () {
! print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>] [-v verbose]\n";
}
--- 335,344 ----
exit $state;
+
+ ####
+ #### subs
+
sub print_usage () {
! print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n";
}
***************
*** 282,290 ****
print "\n";
print_usage();
! print "\n";
! print "<warn> = Clock offset in seconds at which a warning message will be generated.\n Defaults to 60.\n";
! print "<crit> = Clock offset in seconds at which a critical message will be generated.\n Defaults to 120.\n\n";
! print "The same warning and critical values are used to check against the dispersion \n";
! print "column of ntpdc/xntpdc for the host being queried.\n\n";
support();
}
--- 348,362 ----
print "\n";
print_usage();
! print "
! Checks the local timestamp offset versus <host> with ntpdate
! Checks the jitter/dispersion of clock signal between <host> and its sys.peer with ntpq\n
! -w ( --warning)
! Clock offset in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_OFFSET_WARN.
! -c (--critical)
! Clock offset in milliseconds at which a critical message will be generated.\n Defaults to $DEFAULT_OFFSET_CRIT.
! -j (--jwarn)
! 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();
}
Index: utils.pm.in
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/utils.pm.in,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** utils.pm.in 30 Oct 2002 05:07:29 -0000 1.5
--- utils.pm.in 3 Feb 2003 20:29:55 -0000 1.6
***************
*** 3,6 ****
--- 3,9 ----
#
# $Log$
+ # Revision 1.6 2003/02/03 20:29:55 sghosh
+ # change ntpdc to ntpq (Jonathan Rozes,Thomas Schimpke, bug-656237 )
+ #
# Revision 1.5 2002/10/30 05:07:29 sghosh
# monitor mailq
***************
*** 33,36 ****
--- 36,40 ----
$PATH_TO_NTPDATE = "@PATH_TO_NTPDATE@" ;
$PATH_TO_NTPDC = "@PATH_TO_NTPDC@" ;
+ $PATH_TO_NTPQ = "@PATH_TO_NTPQ@" ;
$PATH_TO_LMSTAT = "@PATH_TO_LMSTAT@" ;
$PATH_TO_SMBCLIENT = "@PATH_TO_SMBCLIENT@" ;
More information about the Commits
mailing list