summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_ntp.pl
diff options
context:
space:
mode:
authorSubhendu Ghosh <sghosh@users.sourceforge.net>2003-02-03 15:47:21 +0000
committerSubhendu Ghosh <sghosh@users.sourceforge.net>2003-02-03 15:47:21 +0000
commit3477ec434d6ff7577f7f52498642f0ea4c0c2841 (patch)
tree6fa438fbc066c04cd21df1c1eaefca31cc3f30ac /plugins-scripts/check_ntp.pl
parent19d459ffeb14c8f38b9886f11f24ea423ff6f51e (diff)
downloadmonitoring-plugins-3477ec434d6ff7577f7f52498642f0ea4c0c2841.tar.gz
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
Diffstat (limited to 'plugins-scripts/check_ntp.pl')
-rwxr-xr-xplugins-scripts/check_ntp.pl32
1 files changed, 26 insertions, 6 deletions
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 @@
50# Modifed to run under Embedded Perl (sghosh@users.sf.net) 50# Modifed to run under Embedded Perl (sghosh@users.sf.net)
51# - combined logic some blocks together.. 51# - combined logic some blocks together..
52# 52#
53# Todo - non-hardcoded dispersion values... 53# Added ntpdate check for stratum 16 desynch peer (James Fidell) Feb 03, 2003
54# 54#
55 55
56 56
@@ -111,6 +111,8 @@ if ($critical < $warning ) {
111 exit $ERRORS{"UNKNOWN"}; 111 exit $ERRORS{"UNKNOWN"};
112} 112}
113 113
114my $stratum = -1;
115my $ignoreret = 0;
114my $answer = undef; 116my $answer = undef;
115my $offset = undef; 117my $offset = undef;
116my $msg; # first line of output to print if format is invalid 118my $msg; # first line of output to print if format is invalid
@@ -137,7 +139,7 @@ alarm($TIMEOUT);
137 139
138 140
139### 141###
140###$dispersion_error = $ERRORS{' 142###
141### First, check ntpdate 143### First, check ntpdate
142### 144###
143### 145###
@@ -150,6 +152,11 @@ if (!open (NTPDATE, "$utils::PATH_TO_NTPDATE -q $host 2>&1 |")) {
150while (<NTPDATE>) { 152while (<NTPDATE>) {
151 print if ($verbose); 153 print if ($verbose);
152 $msg = $_ unless ($msg); 154 $msg = $_ unless ($msg);
155
156 if (/stratum\s(\d+)/) {
157 $stratum = $1;
158 }
159
153 if (/(offset|adjust)\s+([-.\d]+)/i) { 160 if (/(offset|adjust)\s+([-.\d]+)/i) {
154 $offset = $2; 161 $offset = $2;
155 162
@@ -163,8 +170,15 @@ while (<NTPDATE>) {
163 } 170 }
164 171
165 if (/no server suitable for synchronization found/) { 172 if (/no server suitable for synchronization found/) {
166 $ntpdate_error = $ERRORS{"CRITICAL"}; 173 if ($stratum == 16) {
167 $msg = "No suitable peer server found - "; 174 $ntpdate_error = $ERRORS{"WARNING"};
175 $msg = "Desynchronized peer server found";
176 $ignoreret=1;
177 }
178 else {
179 $ntpdate_error = $ERRORS{"CRITICAL"};
180 $msg = "No suitable peer server found - ";
181 }
168 } 182 }
169 183
170} 184}
@@ -172,7 +186,7 @@ while (<NTPDATE>) {
172close (NTPDATE); 186close (NTPDATE);
173# declare an error if we also get a non-zero return code from ntpdate 187# declare an error if we also get a non-zero return code from ntpdate
174# unless already set to critical 188# unless already set to critical
175if ( $? ) { 189if ( $? && !$ignoreret ) {
176 print "stderr = $? : $! \n" if $verbose; 190 print "stderr = $? : $! \n" if $verbose;
177 $ntpdate_error = $ntpdate_error == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"} ; 191 $ntpdate_error = $ntpdate_error == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"} ;
178 print "ntperr = $ntpdate_error : $!\n" if $verbose; 192 print "ntperr = $ntpdate_error : $!\n" if $verbose;
@@ -208,7 +222,13 @@ if ($have_ntpdc) {
208 222
209if ($ntpdate_error != $ERRORS{'OK'}) { 223if ($ntpdate_error != $ERRORS{'OK'}) {
210 $state = $ntpdate_error; 224 $state = $ntpdate_error;
211 $answer = $msg . "Server for ntp probably down\n"; 225 if ($ntpdate_error == $ERRORS{'WARNING'} ) {
226 $answer = $msg . "\n";
227 }
228 else {
229 $answer = $msg . "Server for ntp probably down\n";
230 }
231
212 if (defined($offset) && abs($offset) > $critical) { 232 if (defined($offset) && abs($offset) > $critical) {
213 $state = $ERRORS{'CRITICAL'}; 233 $state = $ERRORS{'CRITICAL'};
214 $answer = "Server Error and time difference $offset seconds greater than +/- $critical sec\n"; 234 $answer = "Server Error and time difference $offset seconds greater than +/- $critical sec\n";