diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index bb3d295e0f31fe0a14b822a7ccfeaf5f72648d1e..fdb5819e05d443e5a71accbe5625e843b63b5989 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
int
main (int argc, char **argv)
{
- int i;
+ int i, len;
int iresult = STATE_UNKNOWN;
int result = STATE_UNKNOWN;
int return_code = 0;
}else{
snmpcmd = strdup (PATH_TO_SNMPGET);
}
-
+
/* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *));
command_line[0] = snmpcmd;
ptr = chld_out.line[i];
oidname = strpcpy (oidname, ptr, delimiter);
response = strstr (ptr, delimiter);
+ if (response == NULL)
+ break;
+
if (verbose > 2) {
printf("Processing line %i\n oidname: %s\n response: %s\n", i+1, oidname, response);
}
- /* We strip out the datatype indicator for PHBs */
-
/* Clean up type array - Sol10 does not necessarily zero it out */
bzero(type, sizeof(type));
+ /* We strip out the datatype indicator for PHBs */
if (strstr (response, "Gauge: "))
show = strstr (response, "Gauge: ") + 7;
else if (strstr (response, "Gauge32: "))
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
asprintf (&outbuff, "%s %s", outbuff, unitv[i]);
- if (is_numeric(show)) {
+ /* Write perfdata with whatever can be parsed by strtod, if possible */
+ ptr = NULL;
+ strtod(show, &ptr);
+ if (ptr > show) {
strncat(perfstr, oidname, sizeof(perfstr)-strlen(perfstr)-1);
strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1);
- strncat(perfstr, show, sizeof(perfstr)-strlen(perfstr)-1);
+ 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);
*/
needmibs = TRUE;
}
- oids = calloc(MAX_OIDS, sizeof (char *));
+ if (!oids) oids = calloc(MAX_OIDS, sizeof (char *));
for (ptr = strtok(optarg, ", "); ptr != NULL && j < MAX_OIDS; ptr = strtok(NULL, ", "), j++) {
oids[j] = strdup(ptr);
}