Code

Fix tests and update NEWS file
authorThomas Guyot-Sionnest <dermoth@aei.ca>
Thu, 22 Apr 2010 03:04:06 +0000 (23:04 -0400)
committerThomas Guyot-Sionnest <dermoth@aei.ca>
Thu, 22 Apr 2010 03:04:06 +0000 (23:04 -0400)
NEWS
plugins/tests/check_snmp.t

diff --git a/NEWS b/NEWS
index d09414ca82c4c4a18bc946542f4ff3639104b5e1..5ed4cf0d037c0c97cc0e51cb27a14fbb1ea6c785 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,7 @@ This file documents the major additions and syntax changes between releases.
        Fix compilation error of pst3 in Solaris 8
        Fix check_radius returning OK on unexpected results (Craig Leres - #2911752)
        Fix translations when extra-opts aren't enabled (Jan Wagner - #2832884)
        Fix compilation error of pst3 in Solaris 8
        Fix check_radius returning OK on unexpected results (Craig Leres - #2911752)
        Fix translations when extra-opts aren't enabled (Jan Wagner - #2832884)
+       Fix parsing of multi-line strings in check_snmp (broken in 1.4.14) and enhance output in such case (#2832451)
        WARNINGS
        Updated developer documentation to say that performance labels should not have an equals sign or
        single quote in the label
        WARNINGS
        Updated developer documentation to say that performance labels should not have an equals sign or
        single quote in the label
index 5605b003294e20e90c93c7f510a8380ab9a56bdd..b5f3f89e6e8e569fc4c30d83416aeb57071cc1a4 100755 (executable)
@@ -8,8 +8,18 @@ use Test::More;
 use NPTest;
 use FindBin qw($Bin);
 
 use NPTest;
 use FindBin qw($Bin);
 
+# Check that all dependent modules are available
+eval {
+       require NetSNMP::OID;
+       require NetSNMP::agent;
+       require NetSNMP::ASN;
+};
+
+if ($@) {
+       plan skip_all => "Missing required module for test: $@";
+}
+
 my $port_snmp = 16100 + int(rand(100));
 my $port_snmp = 16100 + int(rand(100));
-my $running = 1;
 
 
 # Start up server
 
 
 # Start up server
@@ -41,7 +51,7 @@ if ($ARGV[0] && $ARGV[0] eq "-d") {
        }
 }
 
        }
 }
 
-my $tests = 3;
+my $tests = 9;
 if (-x "./check_snmp") {
        plan tests => $tests;
 } else {
 if (-x "./check_snmp") {
        plan tests => $tests;
 } else {
@@ -53,11 +63,46 @@ my $res;
 $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");
 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" );
 like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
 $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");
 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying a multi-line string" );
 like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
-like($res->output, '/'.quotemeta('SNMP OK - "Cisco Internetwork Operating System SoftwareIOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version
+like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software | 
+.1.3.6.1.4.1.8072.3.2.67.0:
+"Cisco Internetwork Operating System Software
+IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version
 12.2(20)EWA, RELEASE SOFTWARE (fc1)
 Technical Support: http://www.cisco.com/techsupport
 Copyright (c) 1986-2004 by cisco Systems, Inc.
 "').'/m', "String contains all lines");
 
 12.2(20)EWA, RELEASE SOFTWARE (fc1)
 Technical Support: http://www.cisco.com/techsupport
 Copyright (c) 1986-2004 by cisco Systems, Inc.
 "').'/m', "String contains all lines");
 
-print $res->output;
+# sysContact.0 is "Alice" (from our snmpd.conf)
+$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");
+cmp_ok( $res->return_code, '==', 0, "Exit OK when querying multi-line OIDs" );
+like($res->output, '/^SNMP OK - /', "String contains SNMP OK");
+like($res->output, '/'.quotemeta('SNMP OK - Cisco Internetwork Operating System Software Alice Kisco Outernetwork Oserating Gystem Totware | 
+.1.3.6.1.4.1.8072.3.2.67.0:
+"Cisco Internetwork Operating System Software
+IOS (tm) Catalyst 4000 \"L3\" Switch Software (cat4000-I9K91S-M), Version
+12.2(20)EWA, RELEASE SOFTWARE (fc1)
+Technical Support: http://www.cisco.com/techsupport
+Copyright (c) 1986-2004 by cisco Systems, Inc.
+"
+.1.3.6.1.4.1.8072.3.2.67.1:
+"Kisco Outernetwork Oserating Gystem Totware
+Copyleft (c) 2400-2689 by kisco Systrems, Inc."').'/m', "String contains all lines with multiple OIDs");
+
+$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");
+like($res->output, '/'.quotemeta('SNMP OK - This should not confuse check_snmp \"parser\" | 
+.1.3.6.1.4.1.8072.3.2.67.2:
+"This should not confuse check_snmp \"parser\"
+into thinking there is no 2nd line"').'/m', "Attempt to confuse parser No.1");
+
+$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");
+like($res->output, '/'.quotemeta('SNMP OK - It\'s getting even harder if the line | 
+.1.3.6.1.4.1.8072.3.2.67.3:
+"It\'s getting even harder if the line
+ends with with this: C:\\\\"').'/m', "Attempt to confuse parser No.2");
+
+$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");
+like($res->output, '/'.quotemeta('SNMP OK - And now have fun with with this: \"C:\\\\\" | 
+.1.3.6.1.4.1.8072.3.2.67.4:
+"And now have fun with with this: \"C:\\\\\"
+because we\'re not done yet!"').'/m', "Attempt to confuse parser No.3");