diff options
author | Ton Voon <tonvoon@macbook.local> | 2009-03-14 01:17:50 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2009-03-14 01:17:50 +0000 |
commit | 36e58ae0c3ad7a9d3660722b35d3ed9c97687dd2 (patch) | |
tree | 86bf7e19a500bc7d10c5bcaa6d976ffd476d0229 /plugins/t | |
parent | 674841e279cc1bdbcb5c84c9b26377b156aee76b (diff) | |
download | monitoring-plugins-36e58ae0c3ad7a9d3660722b35d3ed9c97687dd2.tar.gz |
Fixed passing of quotes in OID for check_snmp (#1985230 - Jan Wagner, patch by John Barbuto)
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_snmp.t | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 369314ec..4820aace 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
@@ -8,9 +8,8 @@ use strict; | |||
8 | use Test::More; | 8 | use Test::More; |
9 | use NPTest; | 9 | use NPTest; |
10 | 10 | ||
11 | use vars qw($tests); | 11 | my $tests = 32; |
12 | BEGIN {$tests = 14; plan tests => $tests} | 12 | plan tests => $tests; |
13 | |||
14 | my $res; | 13 | my $res; |
15 | 14 | ||
16 | SKIP: { | 15 | SKIP: { |
@@ -20,7 +19,7 @@ SKIP: { | |||
20 | "A host providing an SNMP Service"); | 19 | "A host providing an SNMP Service"); |
21 | 20 | ||
22 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", | 21 | my $snmp_community = getTestParameter( "snmp_community", "NP_SNMP_COMMUNITY", "public", |
23 | "The SNMP Community string for SNMP Testing" ); | 22 | "The SNMP Community string for SNMP Testing (assumes snmp v1)" ); |
24 | 23 | ||
25 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", | 24 | my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1", |
26 | "The hostname of system not responsive to network requests" ); | 25 | "The hostname of system not responsive to network requests" ); |
@@ -28,12 +27,32 @@ SKIP: { | |||
28 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", | 27 | my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost", |
29 | "An invalid (not known to DNS) hostname" ); | 28 | "An invalid (not known to DNS) hostname" ); |
30 | 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 | |||
31 | SKIP: { | 46 | SKIP: { |
32 | skip "no snmp host defined", 10 if ( ! $host_snmp ); | 47 | skip "no snmp host defined", 20 if ( ! $host_snmp ); |
33 | 48 | ||
34 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 49 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
35 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 50 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
36 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | 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"); | ||
37 | 56 | ||
38 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); | 57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); |
39 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | 58 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); |
@@ -49,21 +68,33 @@ SKIP: { | |||
49 | 68 | ||
50 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | 69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); |
51 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | 70 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); |
52 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and ouput format"); | 71 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); |
72 | |||
73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | ||
74 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); | ||
75 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); | ||
76 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | ||
77 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
78 | |||
79 | $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"); | ||
80 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); | ||
81 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); | ||
82 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | ||
83 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
53 | } | 84 | } |
54 | 85 | ||
55 | SKIP: { | 86 | SKIP: { |
56 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | 87 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
57 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 88 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
58 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 89 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
59 | like($res->output, '/SNMP problem - /', "String matches SNMP Problem"); | 90 | like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); |
60 | } | 91 | } |
61 | 92 | ||
62 | SKIP: { | 93 | SKIP: { |
63 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | 94 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); |
64 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 95 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
65 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 96 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
66 | like($res->output, '/SNMP problem - /', "String matches SNMP Problem"); | 97 | like($res->output, '/External command error: .*nosuchhost/', "String matches invalid host"); |
67 | } | 98 | } |
68 | 99 | ||
69 | } | 100 | } |