diff options
author | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-11-10 22:55:46 +0000 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@users.sourceforge.net> | 2007-11-10 22:55:46 +0000 |
commit | cbae6033d1499fdf779fadf13217a5ae6770a850 (patch) | |
tree | de84949b475c5e019296e1213c9d1f26f4ed0b3e | |
parent | 05f9bbfdc28ba8200fbc620e28f06fe58e2d6d2e (diff) | |
download | monitoring-plugins-cbae6033d1499fdf779fadf13217a5ae6770a850.tar.gz |
New tests!! + single file to test all three plugins (Can be split again if ppl prefer that).
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/branches/dermoth_ntp_rework@1826 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/t/check_ntp.t | 86 | ||||
-rw-r--r-- | plugins/t/check_ntpd.t | 57 | ||||
-rw-r--r-- | plugins/t/check_time_ntp.t | 57 |
3 files changed, 67 insertions, 133 deletions
diff --git a/plugins/t/check_ntp.t b/plugins/t/check_ntp.t index 6e222a38..a36a730d 100644 --- a/plugins/t/check_ntp.t +++ b/plugins/t/check_ntp.t | |||
@@ -9,7 +9,10 @@ use strict; | |||
9 | use Test::More; | 9 | use Test::More; |
10 | use NPTest; | 10 | use NPTest; |
11 | 11 | ||
12 | plan tests => 4; | 12 | my @PLUGINS1 = ('check_ntp', 'check_ntpd', 'check_time_ntp'); |
13 | my @PLUGINS2 = ('check_ntp', 'check_ntpd'); | ||
14 | |||
15 | plan tests => (9 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2)); | ||
13 | 16 | ||
14 | my $res; | 17 | my $res; |
15 | 18 | ||
@@ -25,33 +28,78 @@ 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 | ||
28 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | 31 | my $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 | ||
32 | SKIP: { | 35 | my $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; | 36 | my $ntp_warnmatch1 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/'; |
37 | my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/'; | ||
38 | my $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}/'; | ||
39 | my $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}/'; | ||
40 | my $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}/'; | ||
41 | |||
42 | foreach my $plugin (@PLUGINS1) { | ||
43 | SKIP: { | ||
44 | skip "No NTP server defined", 1 unless $ntp_service; | ||
45 | $res = NPTest->testCmd( | ||
46 | "./$plugin -H $ntp_service -w 1000 -c 2000" | ||
47 | ); | ||
48 | cmp_ok( $res->return_code, '==', 0, "Got good NTP result"); | ||
49 | like( $res->output, $ntp_okmatch1, "Output OK" ); | ||
50 | |||
51 | $res = NPTest->testCmd( | ||
52 | "./$plugin -H $ntp_service -w 1000: -c 2000" | ||
53 | ); | ||
54 | cmp_ok( $res->return_code, '==', 1, "Got warning NTP result"); | ||
55 | like( $res->output, $ntp_warnmatch1, "Output WARNING" ); | ||
56 | |||
57 | $res = NPTest->testCmd( | ||
58 | "./$plugin -H $ntp_service -w 1000 -c 2000:" | ||
59 | ); | ||
60 | cmp_ok( $res->return_code, '==', 2, "Got critical NTP result"); | ||
61 | like( $res->output, $ntp_critmatch1, "Output CRITICAL" ); | ||
62 | } | ||
63 | |||
64 | SKIP: { | ||
65 | skip "No bad NTP server defined", 1 unless $no_ntp_service; | ||
66 | $res = NPTest->testCmd( | ||
67 | "./$plugin -H $no_ntp_service" | ||
68 | ); | ||
69 | cmp_ok( $res->return_code, '==', 2, "Got bad NTP result"); | ||
70 | } | ||
71 | |||
34 | $res = NPTest->testCmd( | 72 | $res = NPTest->testCmd( |
35 | "./check_ntp -H $ntp_service" | 73 | "./$plugin -H $host_nonresponsive" |
36 | ); | 74 | ); |
37 | cmp_ok( $res->return_code, '==', 0, "Got good NTP result"); | 75 | cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding"); |
38 | } | ||
39 | 76 | ||
40 | SKIP: { | ||
41 | skip "No bad NTP server defined", 1 unless $no_ntp_service; | ||
42 | $res = NPTest->testCmd( | 77 | $res = NPTest->testCmd( |
43 | "./check_ntp -H $no_ntp_service" | 78 | "./$plugin -H $hostname_invalid" |
44 | ); | 79 | ); |
45 | cmp_ok( $res->return_code, '==', 2, "Got bad NTP result"); | 80 | cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid"); |
81 | |||
46 | } | 82 | } |
47 | 83 | ||
48 | $res = NPTest->testCmd( | 84 | foreach my $plugin (@PLUGINS2) { |
49 | "./check_ntp -H $host_nonresponsive" | 85 | SKIP: { |
50 | ); | 86 | skip "No NTP server defined", 1 unless $ntp_service; |
51 | cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding"); | 87 | $res = NPTest->testCmd( |
88 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000" | ||
89 | ); | ||
90 | cmp_ok( $res->return_code, '==', 0, "Got good NTP result"); | ||
91 | like( $res->output, $ntp_okmatch2, "Output OK" ); | ||
52 | 92 | ||
53 | $res = NPTest->testCmd( | 93 | $res = NPTest->testCmd( |
54 | "./check_ntp -H $hostname_invalid" | 94 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000" |
55 | ); | 95 | ); |
56 | cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid"); | 96 | cmp_ok( $res->return_code, '==', 1, "Got warning NTP result"); |
97 | like( $res->output, $ntp_warnmatch2, "Output WARNING" ); | ||
57 | 98 | ||
99 | $res = NPTest->testCmd( | ||
100 | "./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1" | ||
101 | ); | ||
102 | cmp_ok( $res->return_code, '==', 2, "Got critical NTP result"); | ||
103 | like( $res->output, $ntp_critmatch2, "Output CRITICAL" ); | ||
104 | } | ||
105 | } | ||
diff --git a/plugins/t/check_ntpd.t b/plugins/t/check_ntpd.t deleted file mode 100644 index 3c5fe2ed..00000000 --- a/plugins/t/check_ntpd.t +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Testing NTP | ||
4 | # | ||
5 | # $Id: check_ntp.t 1468 2006-08-14 08:42:23Z tonvoon $ | ||
6 | # | ||
7 | |||
8 | use strict; | ||
9 | use Test::More; | ||
10 | use NPTest; | ||
11 | |||
12 | plan tests => 4; | ||
13 | |||
14 | my $res; | ||
15 | |||
16 | my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE", | ||
17 | "A host providing NTP service", | ||
18 | "pool.ntp.org"); | ||
19 | |||
20 | my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE", | ||
21 | "A host NOT providing the NTP service", | ||
22 | "localhost" ); | ||
23 | |||
24 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | ||
25 | "The hostname of system not responsive to network requests", | ||
26 | "10.0.0.1" ); | ||
27 | |||
28 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | ||
29 | "An invalid (not known to DNS) hostname", | ||
30 | "nosuchhost"); | ||
31 | |||
32 | SKIP: { | ||
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 | |||
40 | SKIP: { | ||
41 | skip "No bad NTP server defined", 1 unless $no_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 | ); | ||
51 | cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding"); | ||
52 | |||
53 | $res = NPTest->testCmd( | ||
54 | "./check_ntp -H $hostname_invalid" | ||
55 | ); | ||
56 | cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid"); | ||
57 | |||
diff --git a/plugins/t/check_time_ntp.t b/plugins/t/check_time_ntp.t deleted file mode 100644 index 3c5fe2ed..00000000 --- a/plugins/t/check_time_ntp.t +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | #! /usr/bin/perl -w -I .. | ||
2 | # | ||
3 | # Testing NTP | ||
4 | # | ||
5 | # $Id: check_ntp.t 1468 2006-08-14 08:42:23Z tonvoon $ | ||
6 | # | ||
7 | |||
8 | use strict; | ||
9 | use Test::More; | ||
10 | use NPTest; | ||
11 | |||
12 | plan tests => 4; | ||
13 | |||
14 | my $res; | ||
15 | |||
16 | my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE", | ||
17 | "A host providing NTP service", | ||
18 | "pool.ntp.org"); | ||
19 | |||
20 | my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE", | ||
21 | "A host NOT providing the NTP service", | ||
22 | "localhost" ); | ||
23 | |||
24 | my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", | ||
25 | "The hostname of system not responsive to network requests", | ||
26 | "10.0.0.1" ); | ||
27 | |||
28 | my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", | ||
29 | "An invalid (not known to DNS) hostname", | ||
30 | "nosuchhost"); | ||
31 | |||
32 | SKIP: { | ||
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 | |||
40 | SKIP: { | ||
41 | skip "No bad NTP server defined", 1 unless $no_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 | ); | ||
51 | cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding"); | ||
52 | |||
53 | $res = NPTest->testCmd( | ||
54 | "./check_ntp -H $hostname_invalid" | ||
55 | ); | ||
56 | cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid"); | ||
57 | |||