Code

Code cleanup
[nagiosplug.git] / plugins / check_snmp.c
index cb13bc9ae3e22cb3a5fd893f832a46da9e95c9a5..b943379d4770bbc67d220ec258c9d6019f5abd9f 100644 (file)
@@ -23,7 +23,7 @@
  *
  *****************************************************************************/
 
-#define PROGNAME "check_snmp"
+const char *progname = "check_snmp";
 #define REVISION "$Revision$"
 #define COPYRIGHT "1999-2002"
 #define AUTHOR "Ethan Galstad"
@@ -297,8 +297,12 @@ main (int argc, char **argv)
                        show = strstr (response, "Gauge: ") + 7;
                else if (strstr (response, "Gauge32: "))
                        show = strstr (response, "Gauge32: ") + 9;
+               else if (strstr (response, "Counter32: "))
+                       show = strstr (response, "Counter32: ") + 11;
                else if (strstr (response, "INTEGER: "))
                        show = strstr (response, "INTEGER: ") + 9;
+               else if (strstr (response, "STRING: "))
+                       show = strstr (response, "STRING: ") + 8;
                else
                        show = response;
                p2 = show;
@@ -319,6 +323,8 @@ main (int argc, char **argv)
                    eval_method[i] & WARN_EQ ||
                    eval_method[i] & WARN_NE) {
                        p2 = strpbrk (p2, "0123456789");
+                       if (p2 == NULL) 
+                               terminate (STATE_UNKNOWN,"No valid data returned");
                        response_value[i] = strtoul (p2, NULL, 10);
                        iresult = check_num (i);
                        asprintf (&show, "%lu", response_value[i]);
@@ -416,7 +422,6 @@ process_arguments (int argc, char **argv)
        int c = 1;
        int j = 0, jj = 0, ii = 0;
 
-#ifdef HAVE_GETOPT_H
        int option_index = 0;
        static struct option long_options[] = {
                STD_LONG_OPTS,
@@ -441,7 +446,6 @@ process_arguments (int argc, char **argv)
                {"privpasswd", required_argument, 0, 'X'},
                {0, 0, 0, 0}
        };
-#endif
 
        if (argc < 2)
                return ERROR;
@@ -457,13 +461,8 @@ process_arguments (int argc, char **argv)
        }
 
        while (1) {
-#ifdef HAVE_GETOPT_H
-               c =
-                       getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:",
+               c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:",
                                                                         long_options, &option_index);
-#else
-               c = getopt (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:");
-#endif
 
                if (c == -1 || c == EOF)
                        break;
@@ -475,7 +474,7 @@ process_arguments (int argc, char **argv)
                        print_help ();
                        exit (STATE_OK); 
                case 'V':       /* version */
-                       print_revision (PROGNAME, REVISION);
+                       print_revision (progname, REVISION);
                        exit (STATE_OK);
                case 'v': /* verbose */
                        verbose = TRUE;
@@ -753,10 +752,9 @@ validate_arguments ()
 void
 print_help (void)
 {
-       print_revision (PROGNAME, REVISION);
+       print_revision (progname, REVISION);
        printf
-               ("Copyright (c) %s %s <%s>\n\n%s\n",
-                COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
+               ("Copyright (c) %s %s <%s>\n\n%s\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
        print_usage ();
        printf
                ("\nOptions:\n" LONGOPTIONS "\n" DESCRIPTION "\n" NOTES "\n", 
@@ -771,7 +769,7 @@ print_usage (void)
                ("Usage:\n" " %s %s\n"
                 " %s (-h | --help) for detailed help\n"
                 " %s (-V | --version) for version information\n",
-                PROGNAME, OPTIONS, PROGNAME, PROGNAME);
+                progname, OPTIONS, progname, progname);
 }
 \f