summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarper Mann <harpermann@users.sourceforge.net>2005-11-30 00:49:47 +0000
committerHarper Mann <harpermann@users.sourceforge.net>2005-11-30 00:49:47 +0000
commite5b45d0e143bd3dbfb870cbe9fd33977db1a2b19 (patch)
treec5ff93e7a2e329f934431089b8af9d13500b0535
parenta0798228587ee211dfec887f88b25c55ddd16ecb (diff)
downloadmonitoring-plugins-e5b45d0e143bd3dbfb870cbe9fd33977db1a2b19.tar.gz
Nagiosplug bug # 1251096
check_ntp wasn't properly handing a bad exit status from the external programs it calls (ntpdate and ntpq), so jitter wasn't set. Added check of $? on close and proper error output if status from the sub program call completion is non-zero. This includes "host not found". git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1291 f882894a-f735-0410-b71e-b25c423dba1c
-rwxr-xr-xplugins-scripts/check_ntp.pl15
1 files changed, 11 insertions, 4 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl
index e844327b..d4175f64 100755
--- a/plugins-scripts/check_ntp.pl
+++ b/plugins-scripts/check_ntp.pl
@@ -1,5 +1,5 @@
1#!/usr/bin/perl -w 1#!/usr/bin/perl -w
2 2#
3# (c)1999 Ian Cass, Knowledge Matters Ltd. 3# (c)1999 Ian Cass, Knowledge Matters Ltd.
4# Read the GNU copyright stuff for all the legalese 4# Read the GNU copyright stuff for all the legalese
5# 5#
@@ -200,13 +200,15 @@ elsif ($ipv6) {
200### 200###
201 201
202if (!open (NTPDATE, $ntpdate . " -q $host 2>&1 |")) { 202if (!open (NTPDATE, $ntpdate . " -q $host 2>&1 |")) {
203 print "Could not open ntpdate\n"; 203 print "Could not open $ntpdate: $!\n";
204 exit $ERRORS{"UNKNOWN"}; 204 exit $ERRORS{"UNKNOWN"};
205} 205}
206 206
207my $out;
207while (<NTPDATE>) { 208while (<NTPDATE>) {
208 #print if ($verbose); # noop 209 #print if ($verbose); # noop
209 $msg = $_ unless ($msg); 210 $msg = $_ unless ($msg);
211 $out .= "$_ ";
210 212
211 if (/stratum\s(\d+)/) { 213 if (/stratum\s(\d+)/) {
212 $stratum = $1; 214 $stratum = $1;
@@ -241,8 +243,11 @@ while (<NTPDATE>) {
241 } 243 }
242 244
243} 245}
246$out =~ s/\n//g;
247close (NTPDATE) ||
248 die $! ? "$out - Error closing $ntpdate pipe: $!"
249 : "$out - Exit status: $? from $ntpdate\n";
244 250
245close (NTPDATE);
246# declare an error if we also get a non-zero return code from ntpdate 251# declare an error if we also get a non-zero return code from ntpdate
247# unless already set to critical 252# unless already set to critical
248if ( $? && !$ignoreret ) { 253if ( $? && !$ignoreret ) {
@@ -313,7 +318,9 @@ if ($have_ntpq) {
313 } 318 }
314 319
315 } 320 }
316 close NTPQ; 321 close NTPQ ||
322 die $! ? "Error closing $ntpq pipe: $!"
323 : "Exit status: $? from $ntpq\n";
317 324
318 # if we did not match sys.peer or pps.peer but matched # candidates only 325 # if we did not match sys.peer or pps.peer but matched # candidates only
319 # generate a warning 326 # generate a warning