Bläddra i källkod

Merge pull request #489 from sawolf/453-undefined-jitter

Resolve #453 - $jitter and $stratum will not be referenced unless ntpq was used to retrieve those attributes
Sebastian Wolf 6 år sedan
förälder
incheckning
7450edcbad
2 ändrade filer med 6 tillägg och 2 borttagningar
  1. 1 0
      NEWS
  2. 5 2
      plugins-scripts/check_ntp.pl

+ 1 - 0
NEWS

@@ -63,6 +63,7 @@ This file documents the major additions and syntax changes between releases.
 	check_ntp/ntp_time/ntp_peer: Fix how thresholds are displayed in performance data
 	check_ntp_time calls `write` on a UDP socket without a successful call to `connect`
 	check_ntp_time: Periodically returns "Socket timeout" when one of several ntp server doesn't respond
+	check_ntp.pl: Fixed crash due to references to undefined variables
 	check_ping: FreeBSD ping working natively
 	check_procs: Prevent buffer overflow/crash on Solaris
 	check_radius: Fix for null pointer dereference (Vít Heřman)

+ 5 - 2
plugins-scripts/check_ntp.pl

@@ -427,8 +427,11 @@ if ($ntpdate_error != $ERRORS{'OK'}) {
 
 foreach my $key (keys %ERRORS) {
 	if ($state==$ERRORS{$key}) {
-#		print ("NTP $key: $answer");
-		print ("NTP $key: $answer|offset=$offset, jitter=" . $jitter/1000 .	",peer_stratum=$stratum\n");
+		print ("NTP $key: $answer|offset=$offset");
+		if ($have_ntpq) {
+			print (", jitter=" . $jitter/1000 .	",peer_stratum=$stratum");
+		}
+		print ("\n");
 		last;
 	}
 }