summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rwxr-xr-xplugins/tests/check_snmp.t53
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;
8use NPTest; 8use NPTest;
9use FindBin qw($Bin); 9use FindBin qw($Bin);
10 10
11# Check that all dependent modules are available
12eval {
13 require NetSNMP::OID;
14 require NetSNMP::agent;
15 require NetSNMP::ASN;
16};
17
18if ($@) {
19 plan skip_all => "Missing required module for test: $@";
20}
21
11my $port_snmp = 16100 + int(rand(100)); 22my $port_snmp = 16100 + int(rand(100));
12my $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
44my $tests = 3; 54my $tests = 9;
45if (-x "./check_snmp") { 55if (-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");
54cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" ); 64cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" );
55like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); 65like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
56like($res->output, '/'.quotemeta('SNMP OK - "Cisco Internetwork Operating System SoftwareIOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version 66like($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
69IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version
5712.2(20)EWA, RELEASE SOFTWARE (fc1) 7012.2(20)EWA, RELEASE SOFTWARE (fc1)
58Technical Support: http://www.cisco.com/techsupport 71Technical Support: http://www.cisco.com/techsupport
59Copyright (c) 1986-2004 by cisco Systems, Inc. 72Copyright (c) 1986-2004 by cisco Systems, Inc.
60"').'/m', "String contains all lines"); 73"').'/m', "String contains all lines");
61 74
62print $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");
77cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" );
78like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
79like($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
82IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version
8312.2(20)EWA, RELEASE SOFTWARE (fc1)
84Technical Support: http://www.cisco.com/techsupport
85Copyright (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
89Copyleft (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");
92like($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\"
95into 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");
98like($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
101ends 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");
104like($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:\\\\\"
107because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3");
63 108