diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 19f78d03987c9d1a911dc2193cc9091117fcac62..2bc6024f42bab4ca06475ab69473f3d1fc64e729 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
#define MAX_OIDS 8
+/* Gobble to string - stop incrementing c when c[0] match one of the
+ * characters in s */
+#define GOBBLE_TOS(c, s) while(c[0]!='\0' && strchr(s, c[0])==NULL) { c++; }
+/* Given c, keep track of backslashes (bk) and double-quotes (dq)
+ * from c[0] */
+#define COUNT_SEQ(c, bk, dq) switch(c[0]) {\
+ case '\\': \
+ if (bk) bk--; \
+ else bk++; \
+ break; \
+ case '"': \
+ if (!dq) { dq++; } \
+ else if(!bk) { dq--; } \
+ else { bk--; } \
+ break; \
+ }
+
+
+
int process_arguments (int, char **);
int validate_arguments (void);
char *thisarg (char *str);
main (int argc, char **argv)
{
int i, len, line;
+ unsigned int bk_count = 0, dq_count = 0;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
int return_code = 0;
break;
if (verbose > 2) {
- printf("Processing line %i\n oidname: %s\n response: %s\n", i+1, oidname, response);
+ printf("Processing oid %i (line %i)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response);
}
/* Clean up type array - Sol10 does not necessarily zero it out */
else if (strstr (response, "STRING: ")) {
show = strstr (response, "STRING: ") + 8;
conv = "%.10g";
+
/* Get the rest of the string on multi-line strings */
- if (show[0] == '"' && (response[strlen(response)-1] != '\"' || response[strlen(response)-2] != '\\')) {
- /* Strip out unmatched double-quote */
- if (show[0] == '"') show++;
+ ptr = show;
+ COUNT_SEQ(ptr, bk_count, dq_count)
+ while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') {
+ ptr++;
+ GOBBLE_TOS(ptr, "\n\"\\")
+ COUNT_SEQ(ptr, bk_count, dq_count)
+ }
+
+ if (dq_count) { /* unfinished line */
+ /* copy show verbatim first */
if (!mult_resp) mult_resp = strdup("");
- asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], strstr (response, "STRING: ") + 8);
+ asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show);
+ /* then strip out unmatched double-quote from single-line output */
+ if (show[0] == '"') show++;
+
+ /* Keep reading until we match end of double-quoted string */
for (line++; line < chld_out.lines; line++) {
- asprintf (&mult_resp, "%s%s\n", mult_resp, chld_out.line[line]);
- if (mult_resp[strlen(mult_resp)-2] == '"' && response[strlen(response)-2] != '\\') break;
+ ptr = chld_out.line[line];
+ asprintf (&mult_resp, "%s%s\n", mult_resp, ptr);
+
+ COUNT_SEQ(ptr, bk_count, dq_count)
+ while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') {
+ ptr++;
+ GOBBLE_TOS(ptr, "\n\"\\")
+ COUNT_SEQ(ptr, bk_count, dq_count)
+ }
+ /* Break for loop before next line increment when done */
+ if (!dq_count) break;
}
}
}
}
- printf ("%s %s -%s %s \n", label, state_text (result), outbuff, perfstr);
+ printf ("%s %s -%s %s\n", label, state_text (result), outbuff, perfstr);
if (mult_resp) printf ("%s", mult_resp);
return result;
printf (" %s\n", _("- Note that only one string and one regex may be checked at present"));
printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value"));
printf (" %s\n", _("returned from the SNMP query is an unsigned integer."));
-#ifdef NP_EXTRA_OPTS
- printf (" -%s", UT_EXTRA_OPTS_NOTES);
-#endif
printf (UT_SUPPORT);
}
void
print_usage (void)
{
- printf (_("Usage:"));
+ printf ("%s\n", _("Usage:"));
printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname);
printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n");
printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");