summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/t/check_ntp.t42
1 files changed, 24 insertions, 18 deletions
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t
index e7eb0c41..ae7f0369 100644
--- a/plugins/t/check_ntp.t
+++ b/plugins/t/check_ntp.t
@@ -12,7 +12,7 @@ use NPTest;
12my @PLUGINS1 = ('check_ntp', 'check_ntp_peer', 'check_ntp_time'); 12my @PLUGINS1 = ('check_ntp', 'check_ntp_peer', 'check_ntp_time');
13my @PLUGINS2 = ('check_ntp_peer'); 13my @PLUGINS2 = ('check_ntp_peer');
14 14
15plan tests => (9 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2)); 15plan tests => (12 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2));
16 16
17my $res; 17my $res;
18 18
@@ -38,6 +38,9 @@ my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?
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}/'; 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}/'; 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}/'; 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
41 44
42foreach my $plugin (@PLUGINS1) { 45foreach my $plugin (@PLUGINS1) {
43 SKIP: { 46 SKIP: {
@@ -45,39 +48,42 @@ foreach my $plugin (@PLUGINS1) {
45 $res = NPTest->testCmd( 48 $res = NPTest->testCmd(
46 "./$plugin -H $ntp_service -w 1000 -c 2000" 49 "./$plugin -H $ntp_service -w 1000 -c 2000"
47 ); 50 );
48 cmp_ok( $res->return_code, '==', 0, "$plugin: Got good NTP result"); 51 cmp_ok( $res->return_code, '==', 0, "$plugin: Good NTP result (simple check)" );
49 like( $res->output, $ntp_okmatch1, "Output OK" ); 52 like( $res->output, $ntp_okmatch1, "$plugin: Output match OK (simple check)" );
50 53
51 $res = NPTest->testCmd( 54 $res = NPTest->testCmd(
52 "./$plugin -H $ntp_service -w 1000: -c 2000" 55 "./$plugin -H $ntp_service -w 1000: -c 2000"
53 ); 56 );
54 cmp_ok( $res->return_code, '==', 1, "$plugin: Got warning NTP result"); 57 cmp_ok( $res->return_code, '==', 1, "$plugin: Warning NTP result (simple check)" );
55 like( $res->output, $ntp_warnmatch1, "Output WARNING" ); 58 like( $res->output, $ntp_warnmatch1, "$plugin: Output match WARNING (simple check)" );
56 59
57 $res = NPTest->testCmd( 60 $res = NPTest->testCmd(
58 "./$plugin -H $ntp_service -w 1000 -c 2000:" 61 "./$plugin -H $ntp_service -w 1000 -c 2000:"
59 ); 62 );
60 cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical NTP result"); 63 cmp_ok( $res->return_code, '==', 2, "$plugin: Critical NTP result (simple check)" );
61 like( $res->output, $ntp_critmatch1, "Output CRITICAL" ); 64 like( $res->output, $ntp_critmatch1, "$plugin: Output match CRITICAL (simple check)" );
62 } 65 }
63 66
64 SKIP: { 67 SKIP: {
65 skip "No bad NTP server defined", 1 unless $no_ntp_service; 68 skip "No bad NTP server defined", 1 unless $no_ntp_service;
66 $res = NPTest->testCmd( 69 $res = NPTest->testCmd(
67 "./$plugin -H $no_ntp_service" 70 "./$plugin -H $no_ntp_service -t 3"
68 ); 71 );
69 cmp_ok( $res->return_code, '==', 2, "$plugin: Got bad NTP result"); 72 cmp_ok( $res->return_code, '==', 2, "$plugin: No NTP service" );
73 like( $res->output, $ntp_noresponse, "$plugin: Output match no NTP service" );
70 } 74 }
71 75
72 $res = NPTest->testCmd( 76 $res = NPTest->testCmd(
73 "./$plugin -H $host_nonresponsive" 77 "./$plugin -H $host_nonresponsive -t 3"
74 ); 78 );
75 cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical if server not responding"); 79 cmp_ok( $res->return_code, '==', 2, "$plugin: Server not responding" );
80 like( $res->output, $ntp_noresponse, "$plugin: Output match non-responsive" );
76 81
77 $res = NPTest->testCmd( 82 $res = NPTest->testCmd(
78 "./$plugin -H $hostname_invalid" 83 "./$plugin -H $hostname_invalid"
79 ); 84 );
80 cmp_ok( $res->return_code, '==', 3, "$plugin: Got critical if server hostname invalid"); 85 cmp_ok( $res->return_code, '==', 3, "$plugin: Invalid hostname/address" );
86 like( $res->output, $ntp_nosuchhost, "$plugin: Output match invalid hostname/address" );
81 87
82} 88}
83 89
@@ -87,19 +93,19 @@ foreach my $plugin (@PLUGINS2) {
87 $res = NPTest->testCmd( 93 $res = NPTest->testCmd(
88 "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000" 94 "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000"
89 ); 95 );
90 cmp_ok( $res->return_code, '==', 0, "$plugin: Got good NTP result"); 96 cmp_ok( $res->return_code, '==', 0, "$plugin: Good NTP result with jitter and stratum check" );
91 like( $res->output, $ntp_okmatch2, "Output OK" ); 97 like( $res->output, $ntp_okmatch2, "$plugin: Output match OK with jitter and stratum" );
92 98
93 $res = NPTest->testCmd( 99 $res = NPTest->testCmd(
94 "./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000" 100 "./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000"
95 ); 101 );
96 cmp_ok( $res->return_code, '==', 1, "$plugin: Got warning NTP result"); 102 cmp_ok( $res->return_code, '==', 1, "$plugin: Warning NTP result with jitter and stratum check" );
97 like( $res->output, $ntp_warnmatch2, "Output WARNING" ); 103 like( $res->output, $ntp_warnmatch2, "$plugin: Output match WARNING with jitter and stratum" );
98 104
99 $res = NPTest->testCmd( 105 $res = NPTest->testCmd(
100 "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1" 106 "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1"
101 ); 107 );
102 cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical NTP result"); 108 cmp_ok( $res->return_code, '==', 2, "$plugin: Critical NTP result with jitter and stratum check" );
103 like( $res->output, $ntp_critmatch2, "Output CRITICAL" ); 109 like( $res->output, $ntp_critmatch2, "$plugin: Output match CRITICAL with jitter and stratum" );
104 } 110 }
105} 111}