[Nagiosplug-checkins] CVS: nagiosplug/plugins-scripts check_ntp.pl,1.3,1.4
Subhendu Ghosh
sghosh at users.sourceforge.net
Sun May 26 18:57:01 CEST 2002
Update of /cvsroot/nagiosplug/nagiosplug/plugins-scripts
In directory usw-pr-cvs1:/tmp/cvs-serv19928
Modified Files:
check_ntp.pl
Log Message:
logic reorg, ePN fix and support for utils.pm
Index: check_ntp.pl
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins-scripts/check_ntp.pl,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** check_ntp.pl 7 May 2002 05:35:49 -0000 1.3
--- check_ntp.pl 27 May 2002 01:56:22 -0000 1.4
***************
*** 1,3 ****
! #! /usr/bin/perl -wT
# (c)1999 Ian Cass, Knowledge Matters Ltd.
--- 1,3 ----
! #! /usr/bin/perl -w
# (c)1999 Ian Cass, Knowledge Matters Ltd.
***************
*** 48,52 ****
# with master has been lost.
#
! # Modifed to run under Embedded Perl
#
--- 48,55 ----
# with master has been lost.
#
! # Modifed to run under Embedded Perl (sghosh at users.sf.net)
! # - combined logic some blocks together..
! #
! # Todo - non-hardcoded dispersion values...
#
***************
*** 74,79 ****
"h" => \$opt_h, "help" => \$opt_h,
"v" => \$verbose, "verbose" => \$verbose,
! "w=s" => \$opt_w, "warning=s" => \$opt_w,
! "c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
--- 77,82 ----
"h" => \$opt_h, "help" => \$opt_h,
"v" => \$verbose, "verbose" => \$verbose,
! "w=s" => \$opt_w, "warning=s" => \$opt_w, # offset|adjust warning if above this number
! "c=s" => \$opt_c, "critical=s" => \$opt_c, # offset|adjust critical if above this number
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
***************
*** 91,94 ****
--- 94,98 ----
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]+)*)$/);
unless ($host) {
+ print "No target host specified\n";
print_usage();
exit $ERRORS{'UNKNOWN'};
***************
*** 101,104 ****
--- 105,114 ----
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
+ if ($opt_c < $opt_w) {
+ print "Critical offset should be larger than warning offset\n";
+ print_usage();
+ exit $ERRORS{"UNKNOWN"};
+ }
+
my $answer = undef;
my $offset = undef;
***************
*** 116,129 ****
exit $ERRORS{"UNKNOWN"};
};
! alarm($TIMEOUT);
###
! ###
### First, check ntpdate
###
###
! if (!open (NTPDATE, "/usr/local/sbin/ntpdate -q $host 2>&1 |")) {
print "Could not open ntpdate\n";
exit $ERRORS{"UNKNOWN"};
--- 126,139 ----
exit $ERRORS{"UNKNOWN"};
};
! #alarm($TIMEOUT);
###
! ###$dispersion_error = $ERRORS{'
### First, check ntpdate
###
###
! if (!open (NTPDATE, "$utils::PATH_TO_NTPDATE -q $host 2>&1 |")) {
print "Could not open ntpdate\n";
exit $ERRORS{"UNKNOWN"};
***************
*** 135,169 ****
if (/(offset|adjust)\s+([-.\d]+)/i) {
$offset = $2;
! last;
}
- }
- # soak up remaining output; check for error
- while (<NTPDATE>) {
if (/no server suitable for synchronization found/) {
$ntpdate_error = $ERRORS{"CRITICAL"};
}
- }
! close(NTPDATE);
! # only declare an error if we also get a non-zero return code from ntpdate
! $ntpdate_error = ($? >> 8) || $ntpdate_error;
###
###
! ### Then scan xntpdc if it exists
! ###
###
! if (#open(NTPDC,"/usr/sbin/ntpdc -c $host 2>&1 |") ||
! open(NTPDC,"/usr/sbin/xntpdc -c $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>15) {
$dispersion_error = $ERRORS{'CRITICAL'};
} elsif ($8>5 && $dispersion_error<$ERRORS{'CRITICAL'}) {
$dispersion_error = $ERRORS{'WARNING'};
}
}
--- 145,192 ----
if (/(offset|adjust)\s+([-.\d]+)/i) {
$offset = $2;
!
! # An offset of 0.000000 with an error is probably bogus. Actually,
! # it's probably always bogus, but let's be paranoid here.
! if ($offset == 0) { undef $offset;}
!
! $ntpdate_error = defined ($offset) ? $ERRORS{"OK"} : $ERRORS{"CRITICAL"};
! print "ntperr = $ntpdate_error \n" if $verbose;
!
}
if (/no server suitable for synchronization found/) {
$ntpdate_error = $ERRORS{"CRITICAL"};
+ $msg = "No suitable peer server found - ";
}
! }
! close (NTPDATE);
! # declare an error if we also get a non-zero return code from ntpdate
! # unless already set to critical
! if ( $? ) {
! print "stderr = $? : $! \n" if $verbose;
! $ntpdate_error = $ntpdate_error == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"} ;
! print "ntperr = $ntpdate_error : $!\n" if $verbose;
! }
###
###
! ### Then scan xntpdc/ntpdc if it exists
! ### and look in the 8th column for dispersion (ntpd v4) or jitter (ntpd v3)
###
! 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>15) {
+ print "Dispersion = $8 \n" if ($verbose);
$dispersion_error = $ERRORS{'CRITICAL'};
} elsif ($8>5 && $dispersion_error<$ERRORS{'CRITICAL'}) {
+ print "Dispersion = $8 \n" if ($verbose);
$dispersion_error = $ERRORS{'WARNING'};
+ } else {
+ $dispersion_error = $ERRORS{'OK'};
}
}
***************
*** 172,182 ****
}
- # An offset of 0.000000 with an error is probably bogus. Actually,
- # it's probably always bogus, but let's be paranoid here.
- if ($ntpdate_error && $offset && ($offset == 0)) { undef $offset;}
! if ($ntpdate_error > $ERRORS{'OK'}) {
$state = $ntpdate_error;
! $answer = "Server for ntp probably down\n";
if (defined($offset) && abs($offset) > $critical) {
$state = $ERRORS{'CRITICAL'};
--- 195,202 ----
}
! if ($ntpdate_error != $ERRORS{'OK'}) {
$state = $ntpdate_error;
! $answer = $msg . "Server for ntp probably down\n";
if (defined($offset) && abs($offset) > $critical) {
$state = $ERRORS{'CRITICAL'};
***************
*** 186,190 ****
}
! } elsif ($dispersion_error > $ERRORS{'OK'}) {
$state = $dispersion_error;
$answer = "Dispersion too high\n";
--- 206,210 ----
}
! } elsif ($dispersion_error != $ERRORS{'OK'}) {
$state = $dispersion_error;
$answer = "Dispersion too high\n";
More information about the Commits
mailing list