[Nagiosplug-devel] check_ntp warning patch

James Fidell james at cloud9.co.uk
Thu Dec 5 10:06:02 CET 2002


Appended is a patch for check_ntp.

When xntpd starts, it can spend some time running correctly, but
unsynchronised, because it may take ten minutes or more to correctly
synchronise with its servers.  During this period, ntpdate will report
the server as being stratum 16 and give an error that no suitable servers
were found.  In this case, I wanted nagios to log a warning rather than
an error, because (in my view) it isn't a critical problem.

James


--- check_ntp.pl.orig	Thu Dec  5 17:55:05 2002
+++ check_ntp.pl	Thu Dec  5 17:55:10 2002
@@ -147,9 +147,15 @@
 	exit $ERRORS{"UNKNOWN"};
 }
 
+my $stratum = -1;
+my $ignoreret = 0;
+
 while (<NTPDATE>) {
 	print if ($verbose);
 	$msg = $_ unless ($msg);
+        if ( /stratum\s(\d+)/ ) {
+          $stratum = $1;
+        }
 	if (/(offset|adjust)\s+([-.\d]+)/i) {
 		$offset = $2;
 
@@ -163,8 +169,14 @@
 	}
 
 	if (/no server suitable for synchronization found/) {
+          if ( $stratum == 16 ) {
+		$ntpdate_error = $ERRORS{"WARNING"};
+		$msg = "Desynchronised peer server found";
+                $ignoreret = 1;
+          } else {
 		$ntpdate_error = $ERRORS{"CRITICAL"};
 		$msg = "No suitable peer server found - ";
+          }
 	}
 
 }
@@ -172,7 +184,7 @@
 close (NTPDATE); 
 # declare an error if we also get a non-zero return code from ntpdate
 # unless already set to critical
-if ( $? ) {
+if ( $? && !$ignoreret ) {
 	print "stderr = $? : $! \n" if $verbose;
 	$ntpdate_error = $ntpdate_error == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"}  ;
 	print "ntperr = $ntpdate_error : $!\n" if $verbose;
@@ -208,7 +220,11 @@
 
 if ($ntpdate_error != $ERRORS{'OK'}) {
 	$state = $ntpdate_error;
-	$answer = $msg . "Server for ntp probably down\n";
+        if ( $ntpdate_error == $ERRORS{'WARNING'} ) {
+          $answer = $msg . "\n";
+        } else {
+	  $answer = $msg . "Server for ntp probably down\n";
+        }
 	if (defined($offset) && abs($offset) > $critical) {
 		$state = $ERRORS{'CRITICAL'};
 		$answer = "Server Error and time difference $offset seconds greater than +/- $critical sec\n";




More information about the Devel mailing list