Code

Fix translations when extra-opts aren't enabled
[nagiosplug.git] / plugins / check_snmp.c
index 9096cdadcadaad29ffc7574cfb706ad61963d670..f04ca85fa2e9fb76f93b8550495c680909b55c50 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;
@@ -186,7 +186,7 @@ main (int argc, char **argv)
        }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;
@@ -207,7 +207,7 @@ main (int argc, char **argv)
 
        /* This is just for display purposes, so it can remain a string */
        asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s",
-               snmpcmd, timeout_interval, retries, miblist, proto, "[authpriv]",
+               snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
                server_address, port);
 
        for (i = 0; i < numoids; i++) {
@@ -255,15 +255,17 @@ main (int argc, char **argv)
                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  line: %s\n  oidname: %s\n  response: %s\n", i+1, ptr, oidname, response);
+                       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: "))
@@ -349,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);
@@ -504,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);
                        }
@@ -647,7 +653,7 @@ validate_arguments ()
                if ( needmibs == TRUE ) {
                        miblist = strdup (DEFAULT_MIBLIST);
                }else{
-                       miblist = "''";                 /* don't read any mib files for numeric oids */
+                       miblist = "";                   /* don't read any mib files for numeric oids */
                }
        }
 
@@ -800,10 +806,10 @@ print_help (void)
 
        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");
@@ -861,11 +867,11 @@ print_help (void)
        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."));
@@ -877,17 +883,17 @@ print_help (void)
        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);
 }