diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index ce3919d1af4f3592f08b3fa229cffe1102ce4bc5..19f78d03987c9d1a911dc2193cc9091117fcac62 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
int
main (int argc, char **argv)
{
- int i;
+ int i, len, line;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
int return_code = 0;
int external_error = 0;
- double perftmp;
char **command_line = NULL;
char *cl_hidden_auth = NULL;
char *oidname = NULL;
char *response = NULL;
+ char *mult_resp = NULL;
char *outbuff;
char *ptr = NULL;
char *show = NULL;
}
}
- for (i = 0; i < chld_out.lines; i++) {
+ for (line=0, i=0; line < chld_out.lines; line++, i++) {
const char *conv = "%.0f";
- ptr = chld_out.line[i];
+ ptr = chld_out.line[line];
oidname = strpcpy (oidname, ptr, delimiter);
response = strstr (ptr, delimiter);
if (response == NULL)
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++;
+ if (!mult_resp) mult_resp = strdup("");
+ asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], strstr (response, "STRING: ") + 8);
+ 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;
+ }
+ }
+
}
else if (strstr (response, "Timeticks: "))
show = strstr (response, "Timeticks: ");
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
- /* Try a two-way conversion of show and add perfdata only if we get
- * something back at the end */
+ /* Write perfdata with whatever can be parsed by strtod, if possible */
ptr = NULL;
- perftmp = strtod(show, &ptr);
- if (ptr != show) {
- ptr = NULL;
- asprintf(&ptr, "%0.9g", perftmp);
+ strtod(show, &ptr);
+ if (ptr > show) {
strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, ptr, sizeof(perfstr)-strlen(perfstr)-1);
- free(ptr);
+ len = sizeof(perfstr)-strlen(perfstr)-1;
+ strncat(perfstr, show, len>ptr-show ? ptr-show : len);
if (type)
strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1);
}
printf ("%s %s -%s %s \n", label, state_text (result), outbuff, perfstr);
+ if (mult_resp) printf ("%s", mult_resp);
return result;
}
print_usage ();
- printf (_(UT_HELP_VRSN));
- printf (_(UT_EXTRA_OPTS));
+ printf (UT_HELP_VRSN);
+ printf (UT_EXTRA_OPTS);
- printf (_(UT_HOST_PORT), 'p', DEFAULT_PORT);
+ printf (UT_HOST_PORT, 'p', DEFAULT_PORT);
/* SNMP and Authentication Protocol */
printf (" %s\n", "-n, --next");
printf (" %s\n", "-D, --output-delimiter=STRING");
printf (" %s\n", _("Separates output on multiple OID requests"));
- printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+ printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
printf (" %s\n", "-e, --retries=INTEGER");
printf (" %s\n", _("Number of retries to be used in the requests"));
- printf (_(UT_VERBOSE));
+ printf (UT_VERBOSE);
printf ("\n");
printf ("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package."));
printf (" %s\n", _("- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with"));
printf (" %s\n", _("internal spaces must be quoted) [max 8 OIDs]"));
- printf(" -%s", _(UT_THRESHOLDS_NOTES));
+ printf(" -%s", UT_THRESHOLDS_NOTES);
printf (" %s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'"));
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));
+ printf (" -%s", UT_EXTRA_OPTS_NOTES);
#endif
- printf (_(UT_SUPPORT));
+ printf (UT_SUPPORT);
}