diff options
-rw-r--r-- | plugins/check_snmp.c | 20 | ||||
-rw-r--r-- | plugins/tests/check_snmp_agent.pl | 21 |
2 files changed, 32 insertions, 9 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index f04ca85..19f78d0 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -117,7 +117,7 @@ int needmibs = FALSE; | |||
117 | int | 117 | int |
118 | main (int argc, char **argv) | 118 | main (int argc, char **argv) |
119 | { | 119 | { |
120 | int i, len; | 120 | int i, len, line; |
121 | int iresult = STATE_UNKNOWN; | 121 | int iresult = STATE_UNKNOWN; |
122 | int result = STATE_UNKNOWN; | 122 | int result = STATE_UNKNOWN; |
123 | int return_code = 0; | 123 | int return_code = 0; |
@@ -126,6 +126,7 @@ main (int argc, char **argv) | |||
126 | char *cl_hidden_auth = NULL; | 126 | char *cl_hidden_auth = NULL; |
127 | char *oidname = NULL; | 127 | char *oidname = NULL; |
128 | char *response = NULL; | 128 | char *response = NULL; |
129 | char *mult_resp = NULL; | ||
129 | char *outbuff; | 130 | char *outbuff; |
130 | char *ptr = NULL; | 131 | char *ptr = NULL; |
131 | char *show = NULL; | 132 | char *show = NULL; |
@@ -249,10 +250,10 @@ main (int argc, char **argv) | |||
249 | } | 250 | } |
250 | } | 251 | } |
251 | 252 | ||
252 | for (i = 0; i < chld_out.lines; i++) { | 253 | for (line=0, i=0; line < chld_out.lines; line++, i++) { |
253 | const char *conv = "%.0f"; | 254 | const char *conv = "%.0f"; |
254 | 255 | ||
255 | ptr = chld_out.line[i]; | 256 | ptr = chld_out.line[line]; |
256 | oidname = strpcpy (oidname, ptr, delimiter); | 257 | oidname = strpcpy (oidname, ptr, delimiter); |
257 | response = strstr (ptr, delimiter); | 258 | response = strstr (ptr, delimiter); |
258 | if (response == NULL) | 259 | if (response == NULL) |
@@ -283,6 +284,18 @@ main (int argc, char **argv) | |||
283 | else if (strstr (response, "STRING: ")) { | 284 | else if (strstr (response, "STRING: ")) { |
284 | show = strstr (response, "STRING: ") + 8; | 285 | show = strstr (response, "STRING: ") + 8; |
285 | conv = "%.10g"; | 286 | conv = "%.10g"; |
287 | /* Get the rest of the string on multi-line strings */ | ||
288 | if (show[0] == '"' && (response[strlen(response)-1] != '\"' || response[strlen(response)-2] != '\\')) { | ||
289 | /* Strip out unmatched double-quote */ | ||
290 | if (show[0] == '"') show++; | ||
291 | if (!mult_resp) mult_resp = strdup(""); | ||
292 | asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], strstr (response, "STRING: ") + 8); | ||
293 | for (line++; line < chld_out.lines; line++) { | ||
294 | asprintf (&mult_resp, "%s%s\n", mult_resp, chld_out.line[line]); | ||
295 | if (mult_resp[strlen(mult_resp)-2] == '"' && response[strlen(response)-2] != '\\') break; | ||
296 | } | ||
297 | } | ||
298 | |||
286 | } | 299 | } |
287 | else if (strstr (response, "Timeticks: ")) | 300 | else if (strstr (response, "Timeticks: ")) |
288 | show = strstr (response, "Timeticks: "); | 301 | show = strstr (response, "Timeticks: "); |
@@ -367,6 +380,7 @@ main (int argc, char **argv) | |||
367 | } | 380 | } |
368 | 381 | ||
369 | printf ("%s %s -%s %s \n", label, state_text (result), outbuff, perfstr); | 382 | printf ("%s %s -%s %s \n", label, state_text (result), outbuff, perfstr); |
383 | if (mult_resp) printf ("%s", mult_resp); | ||
370 | 384 | ||
371 | return result; | 385 | return result; |
372 | } | 386 | } |
diff --git a/plugins/tests/check_snmp_agent.pl b/plugins/tests/check_snmp_agent.pl index d1ff6d0..302ba6e 100644 --- a/plugins/tests/check_snmp_agent.pl +++ b/plugins/tests/check_snmp_agent.pl | |||
@@ -18,15 +18,24 @@ if (!$agent) { | |||
18 | my $baseoid = '.1.3.6.1.4.1.8072.3.2.67'; | 18 | my $baseoid = '.1.3.6.1.4.1.8072.3.2.67'; |
19 | # Next are arrays of indexes (Type, initial value and increments) | 19 | # Next are arrays of indexes (Type, initial value and increments) |
20 | # Undef miltipliers are randomized | 20 | # Undef miltipliers are randomized |
21 | my $multiline = "Cisco Internetwork Operating System Software | 21 | my $multiline = 'Cisco Internetwork Operating System Software |
22 | IOS (tm) Catalyst 4000 L3 Switch Software (cat4000-I9K91S-M), Version | 22 | IOS (tm) Catalyst 4000 "L3" Switch Software (cat4000-I9K91S-M), Version |
23 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) | 23 | 12.2(20)EWA, RELEASE SOFTWARE (fc1) |
24 | Technical Support: http://www.cisco.com/techsupport | 24 | Technical Support: http://www.cisco.com/techsupport |
25 | Copyright (c) 1986-2004 by cisco Systems, Inc. | 25 | Copyright (c) 1986-2004 by cisco Systems, Inc. |
26 | "; | 26 | '; |
27 | my @fields = (ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED); | 27 | my $multilin2 = "Kisco Outernetwork Oserating Gystem Totware |
28 | my @values = ($multiline, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32))); | 28 | Copyleft (c) 2400-2689 by kisco Systrems, Inc."; |
29 | my @incrts = (undef, 1000, -500, 1000, 100000, undef); | 29 | my $multilin3 = 'This should not confuse check_snmp "parser" |
30 | into thinking there is no 2nd line'; | ||
31 | my $multilin4 = 'It\'s getting even harder if the line | ||
32 | ends with with this: C:\\'; | ||
33 | my $multilin5 = 'And now have fun with with this: "C:\\" | ||
34 | because we\'re not done yet!'; | ||
35 | |||
36 | my @fields = (ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_OCTET_STR, ASN_UNSIGNED, ASN_UNSIGNED, ASN_COUNTER, ASN_COUNTER64, ASN_UNSIGNED); | ||
37 | my @values = ($multiline, $multilin2, $multilin3, $multilin4, $multilin5, 4294965296, 1000, 4294965296, uint64("18446744073709351616"), int(rand(2**32))); | ||
38 | my @incrts = (undef, undef, undef, undef, undef, 1000, -500, 1000, 100000, undef); | ||
30 | 39 | ||
31 | # Number of elements in our OID | 40 | # Number of elements in our OID |
32 | my $oidelts; | 41 | my $oidelts; |