Code

misc doc fix, missing verbose option
[nagiosplug.git] / plugins / check_snmp.c
index 38ce940bfdcc454a87859267d8fbdfa9509ae4ec..5344b93051461301d68c8c080a6b30c1225f962c 100644 (file)
  -R, --eregi=REGEX\n\
     Return OK state (for that OID) if case-insensitive extended REGEX matches\n\
  -l, --label=STRING\n\
-    Prefix label for output from plugin (default -s 'SNMP')\n"
+    Prefix label for output from plugin (default -s 'SNMP')\n\
+ -v, --verbose\n\
+    Debugging the output\n\ 
+               
+               "
 
 #define NOTES "\
-- This plugin uses the 'snmpget' command included with the UCD-SNMP package.\n\
+- This plugin uses the 'snmpget' command included with the NET-SNMP package.\n\
   If you don't have the package installed, you will need to download it from\n\
-  http://ucd-snmp.ucdavis.edu before you can use this plugin.\n\
+  http://net-snmp.sourceforge.net before you can use this plugin.\n\
 - Multiple OIDs may be indicated by a comma- or space-delimited list (lists with\n\
-  internal spaces must be quoted)\n\
+  internal spaces must be quoted) [max 8 OIDs]\n\
 - Ranges are inclusive and are indicated with colons. When specified as\n\
   'min:max' a STATE_OK will be returned if the result is within the indicated\n\
   range or is equal to the upper or lower bound. A non-OK state will be\n\
   returned if the result is outside the specified range.\n\
-- If spcified in the order 'max:min' a non-OK state will be returned if the\n\
+- If specified in the order 'max:min' a non-OK state will be returned if the\n\
   result is within the (inclusive) range.\n\
 - Upper or lower bounds may be omitted to skip checking the respective limit.\n\
 - Bare integers are interpreted as upper limits.\n\
@@ -155,10 +159,10 @@ int errcode, excode;
 
 char *server_address = NULL;
 char *community = NULL;
-char *oid = NULL;
+char *oid = "";
 char *label = NULL;
 char *units = NULL;
-char *port = NULL;
+char *port = DEFAULT_PORT;
 char string_value[MAX_INPUT_BUFFER] = "";
 char **labels = NULL;
 char **unitv = NULL;
@@ -189,7 +193,7 @@ main (int argc, char **argv)
        char input_buffer[MAX_INPUT_BUFFER];
        char *command_line = NULL;
        char *response = NULL;
-       char *outbuff = NULL;
+       char *outbuff = "";
        char *output = NULL;
        char *ptr = NULL;
        char *p2 = NULL;
@@ -197,7 +201,6 @@ main (int argc, char **argv)
 
        labels = malloc (labels_size);
        unitv = malloc (unitv_size);
-       outbuff = strscpy (outbuff, "");
        for (i = 0; i < MAX_OIDS; i++)
                eval_method[i] = CHECK_UNDEF;
        i = 0;
@@ -206,8 +209,8 @@ main (int argc, char **argv)
                usage ("Incorrect arguments supplied\n");
 
        /* create the command line to execute */
-       asprintf (&command_line, "%s -p %s -m ALL -v 1 %s -c %s %s",
-                 PATH_TO_SNMPGET, port, server_address, community, oid);
+       asprintf (&command_line, "%s -m ALL -v 1 -c %s %s:%s %s",
+                 PATH_TO_SNMPGET, community, server_address, port, oid);
        if (verbose)
                printf ("%s\n", command_line);
 
@@ -368,9 +371,9 @@ main (int argc, char **argv)
                result = max_state (result, STATE_WARNING);
 
        if (nunits > 0)
-               printf ("%s %s -%s\n", label, state_text (result), outbuff);
-       else
                printf ("%s %s -%s %s\n", label, state_text (result), outbuff, units);
+       else
+               printf ("%s %s -%s\n", label, state_text (result), outbuff);
 
        return result;
 }
@@ -416,16 +419,13 @@ process_arguments (int argc, char **argv)
                        strcpy (argv[c], "-c");
        }
 
-       /* initialize some args */
-       asprintf (&oid, "");
-
        while (1) {
 #ifdef HAVE_GETOPT_H
                c =
-                       getopt_long (argc, argv, "+?hVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:",
+                       getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:",
                                                                         long_options, &option_index);
 #else
-               c = getopt (argc, argv, "+?hVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:");
+               c = getopt (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:");
 #endif
 
                if (c == -1 || c == EOF)
@@ -433,7 +433,7 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':       /* usage */
-                       usage2 ("Unknown argument", optarg);
+                       usage3 ("Unknown argument", optopt);
                case 'h':       /* help */
                        print_help ();
                        exit (STATE_OK);
@@ -454,7 +454,7 @@ process_arguments (int argc, char **argv)
                                ptr[0] = ' '; /* relpace comma with space */
                        for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
                                eval_method[++j] |= WARN_PRESENT;
-                       asprintf (&oid, "%s %s", oid, optarg);
+                       asprintf (&oid, "%s %s", (oid?oid:""), optarg);
                        break;
                case 'E': /* PRELIMINARY - may change */
                        eval_method[j] |= WARN_PRESENT;
@@ -462,7 +462,7 @@ process_arguments (int argc, char **argv)
                                ptr[0] = ' '; /* relpace comma with space */
                        for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
                                eval_method[++j] |= CRIT_PRESENT;
-                       asprintf (&oid, "%s %s", oid, optarg);
+                       asprintf (&oid, "%s %s", (oid?oid:""), optarg);
                        break;
                case 'c':                                                                       /* critical time threshold */
                        if (strspn (optarg, "0123456789:,") < strlen (optarg)) {
@@ -501,10 +501,9 @@ process_arguments (int argc, char **argv)
                case 'o':                                                                       /* object identifier */
                        for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
                                ptr[0] = ' '; /* relpace comma with space */
-                       for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++) {
+                       for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
                                j++; /* count OIDs */
-                       }
-                       asprintf (&oid, "%s %s", oid, optarg);
+                       asprintf (&oid, "%s %s", (oid?oid:""), optarg);
                        break;
                case 'd':                                                                       /* delimiter */
                        delimiter = strscpy (delimiter, optarg);
@@ -652,9 +651,6 @@ validate_arguments ()
        if (units == NULL)
                asprintf (&units, "");
 
-       if (port == NULL)
-               asprintf (&port, DEFAULT_PORT);
-
        return OK;
 }
 \f