diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-04-22 03:04:06 (GMT) |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2010-04-22 03:04:06 (GMT) |
commit | 00bf32bb6088557d69f91a41f3a556c3e495cd46 (patch) | |
tree | c2268859553f5107e726a95aee67d8afd1f2a4db /plugins | |
parent | 47d04677b7a8b12b00e4f4c2a815514ad56b1239 (diff) | |
download | monitoring-plugins-00bf32bb6088557d69f91a41f3a556c3e495cd46.tar.gz |
Fix tests and update NEWS file
Diffstat (limited to 'plugins')
-rwxr-xr-x | plugins/tests/check_snmp.t | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/plugins/tests/check_snmp.t b/plugins/tests/check_snmp.t index 5605b00..b5f3f89 100755 --- a/plugins/tests/check_snmp.t +++ b/plugins/tests/check_snmp.t | |||
@@ -8,8 +8,18 @@ use Test::More; | |||
8 | use NPTest; | 8 | use NPTest; |
9 | use FindBin qw($Bin); | 9 | use FindBin qw($Bin); |
10 | 10 | ||
11 | # Check that all dependent modules are available | ||
12 | eval { | ||
13 | require NetSNMP::OID; | ||
14 | require NetSNMP::agent; | ||
15 | require NetSNMP::ASN; | ||
16 | }; | ||
17 | |||
18 | if ($@) { | ||
19 | plan skip_all => "Missing required module for test: $@"; | ||
20 | } | ||
21 | |||
11 | my $port_snmp = 16100 + int(rand(100)); | 22 | my $port_snmp = 16100 + int(rand(100)); |
12 | my $running = 1; | ||
13 | 23 | ||
14 | 24 | ||
15 | # Start up server | 25 | # Start up server |
@@ -41,7 +51,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") { | |||
41 | } | 51 | } |
42 | } | 52 | } |
43 | 53 | ||
44 | my $tests = 3; | 54 | my $tests = 9; |
45 | if (-x "./check_snmp") { | 55 | if (-x "./check_snmp") { |
46 | plan tests => $tests; | 56 | plan tests => $tests; |
47 | } else { | 57 | } else { |
@@ -53,11 +63,46 @@ my $res; | |||
53 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); | 63 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0"); |
54 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); | 64 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); |
55 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | 65 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); |
56 | like($res->output, '/'.quotemeta('SNMP OK - "Cisco Internetwork Operating System SoftwareIOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version | 66 | like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software | |
67 | .1.3.6.1.4.1.8072.3.2.67.0: | ||
68 | "Cisco Internetwork Operating System Software | ||
69 | IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version | ||
57 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | 70 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) |
58 | Technical Support: http://www.cisco.com/techsupport | 71 | Technical Support: http://www.cisco.com/techsupport |
59 | Copyright (c) 1986-2004 by cisco Systems, Inc. | 72 | Copyright (c) 1986-2004 by cisco Systems, Inc. |
60 | "').'/m', "String contains all lines"); | 73 | "').'/m', "String contains all lines"); |
61 | 74 | ||
62 | print $res->output; | 75 | # sysContact.0 is "Alice" (from our snmpd.conf) |
76 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.0 -o sysContact.0 -o .1.3.6.1.4.1.8072.3.2.67.1"); | ||
77 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" ); | ||
78 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
79 | like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software Alice Kisco Outernetwork Oserating Gystem Totware | | ||
80 | .1.3.6.1.4.1.8072.3.2.67.0: | ||
81 | "Cisco Internetwork Operating System Software | ||
82 | IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version | ||
83 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | ||
84 | Technical Support: http://www.cisco.com/techsupport | ||
85 | Copyright (c) 1986-2004 by cisco Systems, Inc. | ||
86 | " | ||
87 | .1.3.6.1.4.1.8072.3.2.67.1: | ||
88 | "Kisco Outernetwork Oserating Gystem Totware | ||
89 | Copyleft (c) 2400-2689 by kisco Systrems, Inc."').'/m', "String contains all lines with multiple OIDs"); | ||
90 | |||
91 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.2"); | ||
92 | like($res->output, '/'.quotemeta('SNMP OK - This should not confuse check_snmp \"parser\" | | ||
93 | .1.3.6.1.4.1.8072.3.2.67.2: | ||
94 | "This should not confuse check_snmp \"parser\" | ||
95 | into thinking there is no 2nd line"').'/m', "Attempt to confuse parser No.1"); | ||
96 | |||
97 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.3"); | ||
98 | like($res->output, '/'.quotemeta('SNMP OK - It\'s getting even harder if the line | | ||
99 | .1.3.6.1.4.1.8072.3.2.67.3: | ||
100 | "It\'s getting even harder if the line | ||
101 | ends with with this: C:\\\\"').'/m', "Attempt to confuse parser No.2"); | ||
102 | |||
103 | $res = NPTest->testCmd( "./check_snmp -H 127.0.0.1 -C public -p $port_snmp -o .1.3.6.1.4.1.8072.3.2.67.4"); | ||
104 | like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C:\\\\\" | | ||
105 | .1.3.6.1.4.1.8072.3.2.67.4: | ||
106 | "And now have fun with with this: \"C:\\\\\" | ||
107 | because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3"); | ||
63 | 108 | ||