summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2009-10-22 07:25:41 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2009-10-22 07:25:41 (GMT)
commite7e9a99117d7e0a7189393b3a04366393620efab (patch)
treed46b980c32920ff5e1afe428ac73f9c7ab96a918
parent9c1aa029c088d6d52c7978198136731925c5f385 (diff)
downloadmonitoring-plugins-e7e9a99117d7e0a7189393b3a04366393620efab.tar.gz
Fix usage of repeated -o options in check_snmp
-rw-r--r--NEWS1
-rw-r--r--plugins/check_snmp.c2
-rw-r--r--plugins/t/check_snmp.t26
3 files changed, 19 insertions, 10 deletions
diff --git a/NEWS b/NEWS
index a20dbbe..f5be201 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ This file documents the major additions and syntax changes between releases.
6 Fix check_ircd binding to wrong interface (#668778) 6 Fix check_ircd binding to wrong interface (#668778)
7 Add proxy-authorization option to check_http (Marcel Kuiper - #1323230, Bryan Irvine - #2863925) 7 Add proxy-authorization option to check_http (Marcel Kuiper - #1323230, Bryan Irvine - #2863925)
8 check_icmp now increment the sequence counter in each packet 8 check_icmp now increment the sequence counter in each packet
9 Fix usage of repeated -o options in check_snmp
9 WARNINGS 10 WARNINGS
10 Updated developer documentation to say that performance labels should not have an equals sign or 11 Updated developer documentation to say that performance labels should not have an equals sign or
11 single quote in the label 12 single quote in the label
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index db16462..dcb3138 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -506,7 +506,7 @@ process_arguments (int argc, char **argv)
506 */ 506 */
507 needmibs = TRUE; 507 needmibs = TRUE;
508 } 508 }
509 oids = calloc(MAX_OIDS, sizeof (char *)); 509 if (!oids) oids = calloc(MAX_OIDS, sizeof (char *));
510 for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) { 510 for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) {
511 oids[j] = strdup(ptr); 511 oids[j] = strdup(ptr);
512 } 512 }
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t
index d65fd0b..004ba1a 100644
--- a/plugins/t/check_snmp.t
+++ b/plugins/t/check_snmp.t
@@ -8,7 +8,7 @@ use strict;
8use Test::More; 8use Test::More;
9use NPTest; 9use NPTest;
10 10
11my $tests = 46; 11my $tests = 8+38+2+2;
12plan tests => $tests; 12plan tests => $tests;
13my $res; 13my $res;
14 14
@@ -44,10 +44,10 @@ SKIP: {
44 like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); 44 like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" );
45 45
46 SKIP: { 46 SKIP: {
47 skip "no snmp host defined", 34 if ( ! $host_snmp ); 47 skip "no snmp host defined", 38 if ( ! $host_snmp );
48 48
49 $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:");
50 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); 50 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" );
51 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+)/; 52 $res->output =~ /^SNMP OK - (\d+)/;
53 my $value = $1; 53 my $value = $1;
@@ -59,19 +59,27 @@ SKIP: {
59 like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); 59 like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK");
60 60
61 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o system.sysDescr.0"); 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" ); 62 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" );
63 unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); 63 unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values");
64 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
65 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); 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");
66 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); 74 cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" );
67 like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); 75 like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format");
68 76
69 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); 77 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:");
70 cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); 78 cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " );
71 like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); 79 like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format");
72 80
73 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); 81 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0");
74 cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); 82 cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" );
75 like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); 83 like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format");
76 84
77 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); 85 $res = NPTest->testCmd( "./check_snmp -H $host_snmp -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2");
@@ -123,14 +131,14 @@ SKIP: {
123 SKIP: { 131 SKIP: {
124 skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); 132 skip "no non responsive host defined", 2 if ( ! $host_nonresponsive );
125 $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); 133 $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
126 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); 134 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
127 like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem"); 135 like($res->output, '/External command error: Timeout: No Response from /', "String matches timeout problem");
128 } 136 }
129 137
130 SKIP: { 138 SKIP: {
131 skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); 139 skip "no non invalid host defined", 2 if ( ! $hostname_invalid );
132 $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); 140 $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:");
133 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); 141 cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" );
134 like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host"); 142 like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host)/', "String matches invalid host");
135 } 143 }
136 144