summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_ntp.pl
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_ntp.pl')
-rwxr-xr-xplugins-scripts/check_ntp.pl37
1 files changed, 23 insertions, 14 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl
index f8648345..68acdf65 100755
--- a/plugins-scripts/check_ntp.pl
+++ b/plugins-scripts/check_ntp.pl
@@ -119,6 +119,12 @@ my $ntpdate_error = $ERRORS{'UNKNOWN'};
119my $dispersion_error = $ERRORS{'UNKNOWN'}; 119my $dispersion_error = $ERRORS{'UNKNOWN'};
120 120
121my $key = undef; 121my $key = undef;
122# some systems don't have a proper ntpdc/xntpdc
123if ($utils::PATH_TO_NTPDC && -x $utils::PATH_TO_NTPDC ) {
124 my $have_ntpdc = 1;
125}else{
126 my $have_ntpdc = 0;
127}
122 128
123# Just in case of problems, let's not hang Nagios 129# Just in case of problems, let's not hang Nagios
124$SIG{'ALRM'} = sub { 130$SIG{'ALRM'} = sub {
@@ -176,22 +182,25 @@ if ( $? ) {
176### and look in the 8th column for dispersion (ntpd v4) or jitter (ntpd v3) 182### and look in the 8th column for dispersion (ntpd v4) or jitter (ntpd v3)
177### 183###
178 184
179if ( open(NTPDC,"$utils::PATH_TO_NTPDC -s $host 2>&1 |") ) { 185if ($have_ntpdc) {
180 while (<NTPDC>) { 186
181 print $_ if ($verbose); 187 if ( open(NTPDC,"$utils::PATH_TO_NTPDC -s $host 2>&1 |") ) {
182 if (/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) { 188 while (<NTPDC>) {
183 if ($8>15) { 189 print $_ if ($verbose);
184 print "Dispersion = $8 \n" if ($verbose); 190 if (/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) {
185 $dispersion_error = $ERRORS{'CRITICAL'}; 191 if ($8>15) {
186 } elsif ($8>5 && $dispersion_error<$ERRORS{'CRITICAL'}) { 192 print "Dispersion = $8 \n" if ($verbose);
187 print "Dispersion = $8 \n" if ($verbose); 193 $dispersion_error = $ERRORS{'CRITICAL'};
188 $dispersion_error = $ERRORS{'WARNING'}; 194 } elsif ($8>5 && $dispersion_error<$ERRORS{'CRITICAL'}) {
189 } else { 195 print "Dispersion = $8 \n" if ($verbose);
190 $dispersion_error = $ERRORS{'OK'}; 196 $dispersion_error = $ERRORS{'WARNING'};
197 } else {
198 $dispersion_error = $ERRORS{'OK'};
199 }
191 } 200 }
192 } 201 }
202 close NTPDC;
193 } 203 }
194 close NTPDC;
195} 204}
196 205
197 206
@@ -205,7 +214,7 @@ if ($ntpdate_error != $ERRORS{'OK'}) {
205 $answer = "Server error and time difference $offset seconds greater than +/- $warning sec\n"; 214 $answer = "Server error and time difference $offset seconds greater than +/- $warning sec\n";
206 } 215 }
207 216
208} elsif ($dispersion_error != $ERRORS{'OK'}) { 217} elsif ($have_ntpdc && $dispersion_error != $ERRORS{'OK'}) {
209 $state = $dispersion_error; 218 $state = $dispersion_error;
210 $answer = "Dispersion too high\n"; 219 $answer = "Dispersion too high\n";
211 if (defined($offset) && abs($offset) > $critical) { 220 if (defined($offset) && abs($offset) > $critical) {