summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c50478)
raw | patch | inline | side by side (parent: 4c50478)
author | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 11 Aug 2006 08:26:34 +0000 (08:26 +0000) | ||
committer | Ton Voon <tonvoon@users.sourceforge.net> | |
Fri, 11 Aug 2006 08:26:34 +0000 (08:26 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1467 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_ntp.c | patch | blob | history | |
plugins/t/check_ntp.t | [new file with mode: 0644] | patch | blob |
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c
index 9cda2776d9359e6735e39bc0d481041c014b1974..f9dc49a4de4b2fb1f242b2e52220a729c1ad0def 100644 (file)
--- a/plugins/check_ntp.c
+++ b/plugins/check_ntp.c
* we have to do it in a way that our lazy macros don't handle currently :( */
double offset_request(const char *host, int *status){
int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0;
- int servers_completed=0, one_written=0, servers_readable=0, best_index=-1;
+ int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1;
time_t now_time=0, start_ts=0;
ntp_message *req=NULL;
double avg_offset=0.;
servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
servers[i].waiting=0;
servers_readable--;
+ one_read = 1;
if(servers[i].num_responses==AVG_NUM) servers_completed++;
}
}
/* lather, rinse, repeat. */
}
+ if (one_read == 0) {
+ die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n");
+ }
+
/* now, pick the best server from the list */
best_index=best_offset_server(servers, num_hosts);
if(best_index < 0){
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t
--- /dev/null
+++ b/plugins/t/check_ntp.t
@@ -0,0 +1,57 @@
+#! /usr/bin/perl -w -I ..
+#
+# Testing NTP
+#
+# $Id$
+#
+
+use strict;
+use Test::More;
+use NPTest;
+
+plan tests => 4;
+
+my $res;
+
+my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE",
+ "A host providing NTP service",
+ "pool.ntp.org");
+
+my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
+ "A host NOT providing the NTP service",
+ "localhost" );
+
+my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
+ "The hostname of system not responsive to network requests",
+ "10.0.0.1" );
+
+my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
+ "An invalid (not known to DNS) hostname",
+ "nosuchhost");
+
+SKIP: {
+ skip "No NTP server defined", 1 unless $ntp_service;
+ $res = NPTest->testCmd(
+ "./check_ntp -H $ntp_service"
+ );
+ cmp_ok( $res->return_code, '==', 0, "Got good NTP result");
+}
+
+SKIP: {
+ skip "No bad NTP server defined", 1 unless $ntp_service;
+ $res = NPTest->testCmd(
+ "./check_ntp -H $no_ntp_service"
+ );
+ cmp_ok( $res->return_code, '==', 2, "Got bad NTP result");
+}
+
+$res = NPTest->testCmd(
+ "./check_ntp -H $host_nonresponsive"
+ );
+cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding");
+
+$res = NPTest->testCmd(
+ "./check_ntp -H $hostname_invalid"
+ );
+cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid");
+