summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-12-04 12:38:56 +0000
committerThomas Guyot-Sionnest <dermoth@users.sourceforge.net>2007-12-04 12:38:56 +0000
commit0d34c4da9decb76ea32b73c68497a6b83a791bd1 (patch)
treef6c6583fa76f6740afc733eb1cd379c0f3b5f1e3 /plugins/t
parentee6c34108031a217a5e92df50a1cb6544ff07cf9 (diff)
downloadmonitoring-plugins-0d34c4da9decb76ea32b73c68497a6b83a791bd1.tar.gz
Merge changes from branches/dermoth_ntp_rework (check_ntp_peer/check_ntp_time)
NEWS | 13 plugins/Makefile.am | 8 plugins/check_ntp_peer.c | 628 ++++++++++++++++------------------------------- plugins/check_ntp_time.c | 323 ++---------------------- plugins/t/check_ntp.t | 92 +++++- git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1846 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_ntp.t92
1 files changed, 73 insertions, 19 deletions
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t
index 6e222a38..ae7f0369 100644
--- a/plugins/t/check_ntp.t
+++ b/plugins/t/check_ntp.t
@@ -9,7 +9,10 @@ use strict;
9use Test::More; 9use Test::More;
10use NPTest; 10use NPTest;
11 11
12plan tests => 4; 12my @PLUGINS1 = ('check_ntp', 'check_ntp_peer', 'check_ntp_time');
13my @PLUGINS2 = ('check_ntp_peer');
14
15plan tests => (12 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2));
13 16
14my $res; 17my $res;
15 18
@@ -25,33 +28,84 @@ my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
25 "The hostname of system not responsive to network requests", 28 "The hostname of system not responsive to network requests",
26 "10.0.0.1" ); 29 "10.0.0.1" );
27 30
28my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", 31my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
29 "An invalid (not known to DNS) hostname", 32 "An invalid (not known to DNS) hostname",
30 "nosuchhost"); 33 "nosuchhost");
31 34
32SKIP: { 35my $ntp_okmatch1 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
33 skip "No NTP server defined", 1 unless $ntp_service; 36my $ntp_warnmatch1 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
37my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
38my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}/';
39my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}/';
40my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}/';
41my $ntp_noresponse = '/^(CRITICAL - Socket timeout after 3 seconds)|(NTP CRITICAL: No response from NTP server)$/';
42my $ntp_nosuchhost = '/^check_ntp.*: Invalid hostname/address - ' . $hostname_invalid . '/';
43
44
45foreach my $plugin (@PLUGINS1) {
46 SKIP: {
47 skip "No NTP server defined", 1 unless $ntp_service;
48 $res = NPTest->testCmd(
49 "./$plugin -H $ntp_service -w 1000 -c 2000"
50 );
51 cmp_ok( $res->return_code, '==', 0, "$plugin: Good NTP result (simple check)" );
52 like( $res->output, $ntp_okmatch1, "$plugin: Output match OK (simple check)" );
53
54 $res = NPTest->testCmd(
55 "./$plugin -H $ntp_service -w 1000: -c 2000"
56 );
57 cmp_ok( $res->return_code, '==', 1, "$plugin: Warning NTP result (simple check)" );
58 like( $res->output, $ntp_warnmatch1, "$plugin: Output match WARNING (simple check)" );
59
60 $res = NPTest->testCmd(
61 "./$plugin -H $ntp_service -w 1000 -c 2000:"
62 );
63 cmp_ok( $res->return_code, '==', 2, "$plugin: Critical NTP result (simple check)" );
64 like( $res->output, $ntp_critmatch1, "$plugin: Output match CRITICAL (simple check)" );
65 }
66
67 SKIP: {
68 skip "No bad NTP server defined", 1 unless $no_ntp_service;
69 $res = NPTest->testCmd(
70 "./$plugin -H $no_ntp_service -t 3"
71 );
72 cmp_ok( $res->return_code, '==', 2, "$plugin: No NTP service" );
73 like( $res->output, $ntp_noresponse, "$plugin: Output match no NTP service" );
74 }
75
34 $res = NPTest->testCmd( 76 $res = NPTest->testCmd(
35 "./check_ntp -H $ntp_service" 77 "./$plugin -H $host_nonresponsive -t 3"
36 ); 78 );
37 cmp_ok( $res->return_code, '==', 0, "Got good NTP result"); 79 cmp_ok( $res->return_code, '==', 2, "$plugin: Server not responding" );
38} 80 like( $res->output, $ntp_noresponse, "$plugin: Output match non-responsive" );
39 81
40SKIP: {
41 skip "No bad NTP server defined", 1 unless $no_ntp_service;
42 $res = NPTest->testCmd( 82 $res = NPTest->testCmd(
43 "./check_ntp -H $no_ntp_service" 83 "./$plugin -H $hostname_invalid"
44 ); 84 );
45 cmp_ok( $res->return_code, '==', 2, "Got bad NTP result"); 85 cmp_ok( $res->return_code, '==', 3, "$plugin: Invalid hostname/address" );
86 like( $res->output, $ntp_nosuchhost, "$plugin: Output match invalid hostname/address" );
87
46} 88}
47 89
48$res = NPTest->testCmd( 90foreach my $plugin (@PLUGINS2) {
49 "./check_ntp -H $host_nonresponsive" 91 SKIP: {
50 ); 92 skip "No NTP server defined", 1 unless $ntp_service;
51cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding"); 93 $res = NPTest->testCmd(
94 "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000"
95 );
96 cmp_ok( $res->return_code, '==', 0, "$plugin: Good NTP result with jitter and stratum check" );
97 like( $res->output, $ntp_okmatch2, "$plugin: Output match OK with jitter and stratum" );
52 98
53$res = NPTest->testCmd( 99 $res = NPTest->testCmd(
54 "./check_ntp -H $hostname_invalid" 100 "./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000"
55 ); 101 );
56cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid"); 102 cmp_ok( $res->return_code, '==', 1, "$plugin: Warning NTP result with jitter and stratum check" );
103 like( $res->output, $ntp_warnmatch2, "$plugin: Output match WARNING with jitter and stratum" );
57 104
105 $res = NPTest->testCmd(
106 "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1"
107 );
108 cmp_ok( $res->return_code, '==', 2, "$plugin: Critical NTP result with jitter and stratum check" );
109 like( $res->output, $ntp_critmatch2, "$plugin: Output match CRITICAL with jitter and stratum" );
110 }
111}