summaryrefslogtreecommitdiffstats
path: root/plugins/t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t')
-rw-r--r--plugins/t/check_apt.t4
-rw-r--r--plugins/t/check_http.t32
-rw-r--r--plugins/t/check_procs.t6
-rw-r--r--plugins/t/check_snmp.t293
-rw-r--r--plugins/t/check_tcp.t6
5 files changed, 182 insertions, 159 deletions
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t
index 7123097..9ba0ff8 100644
--- a/plugins/t/check_apt.t
+++ b/plugins/t/check_apt.t
@@ -18,8 +18,8 @@ sub make_result_regexp {
18 } else { 18 } else {
19 $status = "CRITICAL"; 19 $status = "CRITICAL";
20 } 20 }
21 return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\).\s*$/', 21 return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\)\. |available_upgrades=%d;;;0 critical_updates=%d;;;0$/',
22 $status, $warning, $critical); 22 $status, $warning, $critical, $warning, $critical);
23} 23}
24 24
25if (-x "./check_apt") { 25if (-x "./check_apt") {
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t
index 0a25c77..9948c53 100644
--- a/plugins/t/check_http.t
+++ b/plugins/t/check_http.t
@@ -8,22 +8,22 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11plan tests => 28; 11plan tests => 30;
12 12
13my $successOutput = '/OK.*HTTP.*second/'; 13my $successOutput = '/OK.*HTTP.*second/';
14 14
15my $res; 15my $res;
16 16
17my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP", 17my $host_tcp_http = getTestParameter( "NP_HOST_TCP_HTTP",
18 "A host providing the HTTP Service (a web server)", 18 "A host providing the HTTP Service (a web server)",
19 "localhost" ); 19 "localhost" );
20 20
21my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", 21my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE",
22 "The hostname of system not responsive to network requests", 22 "The hostname of system not responsive to network requests",
23 "10.0.0.1" ); 23 "10.0.0.1" );
24 24
25my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID", 25my $hostname_invalid = getTestParameter( "NP_HOSTNAME_INVALID",
26 "An invalid (not known to DNS) hostname", 26 "An invalid (not known to DNS) hostname",
27 "nosuchhost"); 27 "nosuchhost");
28 28
29my $internet_access = getTestParameter( "NP_INTERNET_ACCESS", 29my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
@@ -32,8 +32,8 @@ my $internet_access = getTestParameter( "NP_INTERNET_ACCESS",
32 32
33my $host_tcp_http2; 33my $host_tcp_http2;
34if ($internet_access eq "no") { 34if ($internet_access eq "no") {
35 $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2", 35 $host_tcp_http2 = getTestParameter( "NP_HOST_TCP_HTTP2",
36 "A host providing an index page containing the string 'nagios'", 36 "A host providing an index page containing the string 'nagios'",
37 "www.nagios.com" ); 37 "www.nagios.com" );
38} 38}
39 39
@@ -45,14 +45,9 @@ cmp_ok( $res->return_code, '==', 0, "Webserver $host_tcp_http responded" );
45like( $res->output, $successOutput, "Output OK" ); 45like( $res->output, $successOutput, "Output OK" );
46 46
47$res = NPTest->testCmd( 47$res = NPTest->testCmd(
48 "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here'" 48 "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there' -k 'carl:frown'"
49 ); 49 );
50like( $res->output, '/bob:there\r\nfred:here\r\n/', "Got headers, delimited with ';'" ); 50like( $res->output, '/bob:there\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
51
52$res = NPTest->testCmd(
53 "./check_http $host_tcp_http -wt 300 -ct 600 -v -v -v -k 'bob:there;fred:here' -k 'carl:frown'"
54 );
55like( $res->output, '/bob:there\r\nfred:here\r\ncarl:frown\r\n/', "Got headers with multiple -k options" );
56 51
57$res = NPTest->testCmd( 52$res = NPTest->testCmd(
58 "./check_http $host_nonresponsive -wt 1 -ct 2" 53 "./check_http $host_nonresponsive -wt 1 -ct 2"
@@ -123,6 +118,10 @@ SKIP: {
123 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" ); 118 $res = NPTest->testCmd( "./check_http www.verisign.com -C 1" );
124 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); 119 cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works");
125 120
121 $res = NPTest->testCmd( "./check_http --ssl www.verisign.com -E" );
122 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
123 like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' );
124
126 $res = NPTest->testCmd( 125 $res = NPTest->testCmd(
127 "./check_http --ssl www.e-paycobalt.com" 126 "./check_http --ssl www.e-paycobalt.com"
128 ); 127 );
@@ -131,4 +130,7 @@ SKIP: {
131 130
132 $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" ); 131 $res = NPTest->testCmd( "./check_http -H www.mozilla.com -u /firefox -f follow" );
133 is( $res->return_code, 0, "Redirection based on location is okay"); 132 is( $res->return_code, 0, "Redirection based on location is okay");
133
134 $res = NPTest->testCmd( "./check_http -H www.mozilla.com --extended-perfdata" );
135 like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' );
134} 136}
diff --git a/plugins/t/check_procs.t b/plugins/t/check_procs.t
index 30f0248..a1a2883 100644
--- a/plugins/t/check_procs.t
+++ b/plugins/t/check_procs.t
@@ -20,7 +20,7 @@ my $result;
20 20
21$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" ); 21$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000" );
22is( $result->return_code, 0, "Checking less than 10000 processes" ); 22is( $result->return_code, 0, "Checking less than 10000 processes" );
23like( $result->output, '/^PROCS OK: [0-9]+ process(es)?$/', "Output correct" ); 23like( $result->output, '/^PROCS OK: [0-9]+ process(es)? | procs=[0-9]+;100000;100000;0;$/', "Output correct" );
24 24
25$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" ); 25$result = NPTest->testCmd( "./check_procs -w 100000 -c 100000 -s Z" );
26is( $result->return_code, 0, "Checking less than 100000 zombie processes" ); 26is( $result->return_code, 0, "Checking less than 100000 zombie processes" );
@@ -28,11 +28,11 @@ like( $result->output, '/^PROCS OK: [0-9]+ process(es)? with /', "Output correct
28 28
29$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" ); 29$result = NPTest->testCmd( "./check_procs -w 0 -c 100000" );
30is( $result->return_code, 1, "Checking warning if processes > 0" ); 30is( $result->return_code, 1, "Checking warning if processes > 0" );
31like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)?$/', "Output correct" ); 31like( $result->output, '/^PROCS WARNING: [0-9]+ process(es)? | procs=[0-9]+;0;100000;0;$/', "Output correct" );
32 32
33$result = NPTest->testCmd( "./check_procs -w 0 -c 0" ); 33$result = NPTest->testCmd( "./check_procs -w 0 -c 0" );
34is( $result->return_code, 2, "Checking critical if processes > 0" ); 34is( $result->return_code, 2, "Checking critical if processes > 0" );
35like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)?$/', "Output correct" ); 35like( $result->output, '/^PROCS CRITICAL: [0-9]+ process(es)? | procs=[0-9]+;0;0;0;$/', "Output correct" );
36 36
37$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" ); 37$result = NPTest->testCmd( "./check_procs -w 0 -c 0 -s S" );
38is( $result->return_code, 2, "Checking critical if sleeping processes" ); 38is( $result->return_code, 2, "Checking critical if sleeping processes" );
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t
index 04bf500..6de5f29 100644
--- a/plugins/t/check_snmp.t
+++ b/plugins/t/check_snmp.t
@@ -8,145 +8,164 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11my $tests = 8+42+2+2; 11BEGIN {
12plan tests => $tests; 12 plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp";
13 plan tests => 60;
14}
15
13my $res; 16my $res;
14 17
18my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost",
19 "A host providing an SNMP Service");
20
21my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
22 "The SNMP Community string for SNMP Testing (assumes snmp v1)" );
23
24my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
25 "The hostname of system not responsive to network requests" );
26
27my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
28 "An invalid (not known to DNS) hostname" );
29
30$res = NPTest->testCmd( "./check_snmp -t 1" );
31is( $res->return_code, 3, "No host name" );
32is( $res->output, "No host specified" );
33
34$res = NPTest->testCmd( "./check_snmp -H fakehostname" );
35is( $res->return_code, 3, "No OIDs specified" );
36is( $res->output, "No OIDs specified" );
37
38$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" );
39is( $res->return_code, 3, "Invalid seclevel" );
40like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
41
42$res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
43is( $res->return_code, 3, "Invalid protocol" );
44like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
45
46SKIP: {
47 skip "no snmp host defined", 38 if ( ! $host_snmp );
48
49 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
50 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
51 like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
52 $res->output =~ /^SNMP OK - (\d+)/;
53 my $value = $1;
54 cmp_ok( $value, ">", 0, "Got a time value" );
55 like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it");
56
57
58 # some more threshold tests
59 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1");
60 cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" );
61
62 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:");
63 cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" );
64
65 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c ~:1");
66 cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" );
67
68 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1:10");
69 cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" );
70
71 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c \@1:10");
72 cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" );
73
74 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 10:1");
75 cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" );
76
77
78 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:");
79 cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
80 like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
81
82 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
83 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
84 unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
85
86 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
87 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
88 like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
89
90 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
91 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
92 like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
93
94 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
95 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
96 like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
97
98 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
99 cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
100 like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
101
102 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
103 cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
104 like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
105
106 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
107 cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
108 like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
109 like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
110 like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
111
112 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2");
113 cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
114 like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
115 like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
116 like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
117
118 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
119 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
120 like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
121
122 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
123 cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
124 like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
125
126 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
127 $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
128 my $lower = $1 - 0.05;
129 my $higher = $1 + 0.05;
130 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
131 cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
132
133 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
134 cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
135 like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds");
136
137 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
138 cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
139
140 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
141 cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
142 like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
143
144 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
145 cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
146 like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
147
148 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
149 cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
150 like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
151
152 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
153 cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
154 like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed");
155}
156
157# These checks need a complete command line. An invalid community is used so
158# the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
15SKIP: { 159SKIP: {
16 skip "check_snmp is not compiled", $tests if ( ! -x "./check_snmp" ); 160 skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
17 161 $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
18 my $host_snmp = getTestParameter( "host_snmp", "NP_HOST_SNMP", "localhost", 162 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
19 "A host providing an SNMP Service"); 163 like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
20 164}
21 my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public",
22 "The SNMP Community string for SNMP Testing (assumes snmp v1)" );
23
24 my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
25 "The hostname of system not responsive to network requests" );
26
27 my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
28 "An invalid (not known to DNS) hostname" );
29
30 $res = NPTest->testCmd( "./check_snmp -t 1" );
31 is( $res->return_code, 3, "No host name" );
32 is( $res->output, "No host specified" );
33
34 $res = NPTest->testCmd( "./check_snmp -H fakehostname" );
35 is( $res->return_code, 3, "No OIDs specified" );
36 is( $res->output, "No OIDs specified" );
37
38 $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3 --seclevel=rubbish" );
39 is( $res->return_code, 3, "Invalid seclevel" );
40 like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" );
41
42 $res = NPTest->testCmd( "./check_snmp -H fakehost -o oids -P 3c" );
43 is( $res->return_code, 3, "Invalid protocol" );
44 like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
45
46 SKIP: {
47 skip "no snmp host defined", 38 if ( ! $host_snmp );
48
49 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:");
50 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
51 like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK");
52 $res->output =~ /^SNMP OK - (\d+)/;
53 my $value = $1;
54 cmp_ok( $value, ">", 0, "Got a time value" );
55 like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it");
56
57 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:");
58 cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" );
59 like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
60
61 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0");
62 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
63 unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
64
65 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0,system.sysDescr.0");
66 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" );
67 like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
68
69 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0");
70 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" );
71 like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
72
73 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1");
74 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
75 like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
76
77 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
78 cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
79 like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
80
81 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
82 cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
83 like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
84
85 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
86 cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" );
87 like($res->output, "/^SNMP OK - 2 1/", "Got two values back" );
88 like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
89 like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
90
91 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2");
92 cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" );
93 like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" );
94 like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" );
95 like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" );
96
97 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:");
98 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses");
99 like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses");
100
101 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0");
102 cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds");
103 like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format");
104
105 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3");
106 $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/;
107 my $lower = $1 - 0.05;
108 my $higher = $1 + 0.05;
109 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher");
110 cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments");
111
112 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2");
113 cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold");
114 like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds");
115
116 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''");
117 cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash");
118
119 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2");
120 cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check");
121 like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed");
122
123 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,");
124 cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds");
125 like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed");
126
127 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'");
128 cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold");
129 like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric");
130
131 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0");
132 cmp_ok( $res->return_code, '==', 0, "Timetick used as a string");
133 like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed");
134 }
135
136 # These checks need a complete command line. An invalid community is used so
137 # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway
138 SKIP: {
139 skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
140 $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
141 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
142 like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
143 }
144
145 SKIP: {
146 skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
147 $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
148 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
149 like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
150 }
151 165
166SKIP: {
167 skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
168 $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
169 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
170 like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
152} 171}
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t
index 75c1e5f..c100cad 100644
--- a/plugins/t/check_tcp.t
+++ b/plugins/t/check_tcp.t
@@ -9,7 +9,7 @@ use Test;
9use NPTest; 9use NPTest;
10 10
11use vars qw($tests); 11use vars qw($tests);
12BEGIN {$tests = 7; plan tests => $tests} 12BEGIN {$tests = 14; plan tests => $tests}
13 13
14my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost", 14my $host_tcp_http = getTestParameter( "host_tcp_http", "NP_HOST_TCP_HTTP", "localhost",
15 "A host providing the HTTP Service (a web server)" ); 15 "A host providing the HTTP Service (a web server)" );
@@ -27,13 +27,15 @@ my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on po
27my $t; 27my $t;
28 28
29$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); 29$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput );
30$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600 -6 ", 0, $successOutput );
30$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test 31$t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test
31$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); 32$t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 );
32$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); 33$t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 );
33$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 ); 34$t += checkCmd( "./check_tcp -S -D 1 -H www.verisign.com -p 443", 0 );
34$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 0 ); 35$t += checkCmd( "./check_tcp -S -D 9000,1 -H www.verisign.com -p 443", 1 );
35$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 ); 36$t += checkCmd( "./check_tcp -S -D 9000 -H www.verisign.com -p 443", 1 );
36$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 ); 37$t += checkCmd( "./check_tcp -S -D 9000,8999 -H www.verisign.com -p 443", 2 );
38$t += checkCmd( "./check_tcp -6 -p 80 www.heise.de", 0 );
37 39
38# Need the \r\n to make it more standards compliant with web servers. Need the various quotes 40# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
39# so that perl doesn't interpret the \r\n and is passed onto command line correctly 41# so that perl doesn't interpret the \r\n and is passed onto command line correctly