Code

check_snmp: Update last patch to copy value verbatim
[nagiosplug.git] / plugins / check_snmp.c
index db16462bec5e20e7a53abbfc05c8bf4d32e21cb9..fdb5819e05d443e5a71accbe5625e843b63b5989 100644 (file)
@@ -117,7 +117,7 @@ int needmibs = FALSE;
 int
 main (int argc, char **argv)
 {
-       int i;
+       int i, len;
        int iresult = STATE_UNKNOWN;
        int result = STATE_UNKNOWN;
        int return_code = 0;
@@ -351,10 +351,14 @@ main (int argc, char **argv)
                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);
@@ -506,7 +510,7 @@ process_arguments (int argc, char **argv)
                                         */
                                        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);
                        }