summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2006-08-11 08:26:34 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2006-08-11 08:26:34 +0000
commit0c2be6a608135d8a45c82a1c0ada5e8020bc2409 (patch)
treecc1c96e681de1de347a0e34eadf571d18c39de48 /plugins
parent4c50478efce19e079c030574e1b23bf02a50573a (diff)
downloadmonitoring-plugins-0c2be6a608135d8a45c82a1c0ada5e8020bc2409.tar.gz
Catch no responses from any server (1538341 - nmdias)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1467 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_ntp.c7
-rw-r--r--plugins/t/check_ntp.t57
2 files changed, 63 insertions, 1 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 9cda2776..f9dc49a4 100644
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
@@ -335,7 +335,7 @@ int best_offset_server(const ntp_server_results *slist, int nservers){
335 * we have to do it in a way that our lazy macros don't handle currently :( */ 335 * we have to do it in a way that our lazy macros don't handle currently :( */
336double offset_request(const char *host, int *status){ 336double offset_request(const char *host, int *status){
337 int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0; 337 int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0;
338 int servers_completed=0, one_written=0, servers_readable=0, best_index=-1; 338 int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1;
339 time_t now_time=0, start_ts=0; 339 time_t now_time=0, start_ts=0;
340 ntp_message *req=NULL; 340 ntp_message *req=NULL;
341 double avg_offset=0.; 341 double avg_offset=0.;
@@ -437,12 +437,17 @@ double offset_request(const char *host, int *status){
437 servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay); 437 servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
438 servers[i].waiting=0; 438 servers[i].waiting=0;
439 servers_readable--; 439 servers_readable--;
440 one_read = 1;
440 if(servers[i].num_responses==AVG_NUM) servers_completed++; 441 if(servers[i].num_responses==AVG_NUM) servers_completed++;
441 } 442 }
442 } 443 }
443 /* lather, rinse, repeat. */ 444 /* lather, rinse, repeat. */
444 } 445 }
445 446
447 if (one_read == 0) {
448 die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n");
449 }
450
446 /* now, pick the best server from the list */ 451 /* now, pick the best server from the list */
447 best_index=best_offset_server(servers, num_hosts); 452 best_index=best_offset_server(servers, num_hosts);
448 if(best_index < 0){ 453 if(best_index < 0){
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t
new file mode 100644
index 00000000..6ba521f1
--- /dev/null
+++ b/plugins/t/check_ntp.t
@@ -0,0 +1,57 @@
1#! /usr/bin/perl -w -I ..
2#
3# Testing NTP
4#
5# $Id$
6#
7
8use strict;
9use Test::More;
10use NPTest;
11
12plan tests => 4;
13
14my $res;
15
16my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE",
17 "A host providing NTP service",
18 "pool.ntp.org");
19
20my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
21 "A host NOT providing the NTP service",
22 "localhost" );
23
24my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
25 "The hostname of system not responsive to network requests",
26 "10.0.0.1" );
27
28my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
29 "An invalid (not known to DNS) hostname",
30 "nosuchhost");
31
32SKIP: {
33 skip "No NTP server defined", 1 unless $ntp_service;
34 $res = NPTest->testCmd(
35 "./check_ntp -H $ntp_service"
36 );
37 cmp_ok( $res->return_code, '==', 0, "Got good NTP result");
38}
39
40SKIP: {
41 skip "No bad NTP server defined", 1 unless $ntp_service;
42 $res = NPTest->testCmd(
43 "./check_ntp -H $no_ntp_service"
44 );
45 cmp_ok( $res->return_code, '==', 2, "Got bad NTP result");
46}
47
48$res = NPTest->testCmd(
49 "./check_ntp -H $host_nonresponsive"
50 );
51cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding");
52
53$res = NPTest->testCmd(
54 "./check_ntp -H $hostname_invalid"
55 );
56cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid");
57