From 3477ec434d6ff7577f7f52498642f0ea4c0c2841 Mon Sep 17 00:00:00 2001 From: Subhendu Ghosh Date: Mon, 3 Feb 2003 15:47:21 +0000 Subject: patch for desync peer and ntpdate (James Fidell) git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@280 f882894a-f735-0410-b71e-b25c423dba1c --- plugins-scripts/check_ntp.pl | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'plugins-scripts') diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl index 331f8556..560a8775 100755 --- a/plugins-scripts/check_ntp.pl +++ b/plugins-scripts/check_ntp.pl @@ -50,7 +50,7 @@ # Modifed to run under Embedded Perl (sghosh@users.sf.net) # - combined logic some blocks together.. # -# Todo - non-hardcoded dispersion values... +# Added ntpdate check for stratum 16 desynch peer (James Fidell) Feb 03, 2003 # @@ -111,6 +111,8 @@ if ($critical < $warning ) { exit $ERRORS{"UNKNOWN"}; } +my $stratum = -1; +my $ignoreret = 0; my $answer = undef; my $offset = undef; my $msg; # first line of output to print if format is invalid @@ -137,7 +139,7 @@ alarm($TIMEOUT); ### -###$dispersion_error = $ERRORS{' +### ### First, check ntpdate ### ### @@ -150,6 +152,11 @@ if (!open (NTPDATE, "$utils::PATH_TO_NTPDATE -q $host 2>&1 |")) { while () { print if ($verbose); $msg = $_ unless ($msg); + + if (/stratum\s(\d+)/) { + $stratum = $1; + } + if (/(offset|adjust)\s+([-.\d]+)/i) { $offset = $2; @@ -163,8 +170,15 @@ while () { } if (/no server suitable for synchronization found/) { - $ntpdate_error = $ERRORS{"CRITICAL"}; - $msg = "No suitable peer server found - "; + if ($stratum == 16) { + $ntpdate_error = $ERRORS{"WARNING"}; + $msg = "Desynchronized peer server found"; + $ignoreret=1; + } + else { + $ntpdate_error = $ERRORS{"CRITICAL"}; + $msg = "No suitable peer server found - "; + } } } @@ -172,7 +186,7 @@ while () { 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 +222,13 @@ if ($have_ntpdc) { 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"; -- cgit v1.2.3-74-g34f1