Code

reverting my changes from !=TRUE to == ERROR, that's not good ;-( sorry
[nagiosplug.git] / plugins / check_snmp.c
index cb985cab78aca9b2180342e403a0902d39688ef1..6fae3d1f81b03db0e9e609ed0b70c49b3b4dff05 100644 (file)
  along with this program; if not, write to the Free Software
  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+ $Id$
 ******************************************************************************/
 
 const char *progname = "check_snmp";
 const char *revision = "$Revision$";
-const char *copyright = "1999-2003";
+const char *copyright = "1999-2004";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
 #include "common.h"
@@ -111,16 +113,13 @@ unsigned long upper_crit_lim[MAX_OIDS];
 unsigned long response_value[MAX_OIDS];
 int check_warning_value = FALSE;
 int check_critical_value = FALSE;
-int eval_method[MAX_OIDS];
+unsigned long eval_method[MAX_OIDS];
 char *delimiter;
 char *output_delim;
 char *miblist;
 
 
 
-
-
-\f
 int
 main (int argc, char **argv)
 {
@@ -158,7 +157,7 @@ main (int argc, char **argv)
        miblist = strdup (DEFAULT_MIBLIST);
 
        if (process_arguments (argc, argv) == ERROR)
-               usage (_("Incorrect arguments supplied\n"));
+               usage4 (_("Could not parse arguments"));
 
        /* create the command line to execute */
        asprintf (&command_line, "%s -t 1 -r %d -m %s -v %s %s %s:%s %s",
@@ -319,7 +318,7 @@ main (int argc, char **argv)
 
        if (found == 0)
                die (STATE_UNKNOWN,
-                    _("%s problem - No data recieved from host\nCMD: %s\n"),
+                    _("%s problem - No data received from host\nCMD: %s\n"),
                     label,
                     command_line);
 
@@ -344,9 +343,6 @@ main (int argc, char **argv)
 
 
 
-
-
-\f
 /* process command-line arguments */
 int
 process_arguments (int argc, char **argv)
@@ -402,7 +398,9 @@ process_arguments (int argc, char **argv)
 
                switch (c) {
                case '?':       /* usage */
-                       usage3 ("Unknown argument", optopt);
+                       printf (_("%s: Unknown argument: %s\n\n"), progname, optarg);
+                       print_usage ();
+                       exit (STATE_UNKNOWN);
                case 'h':       /* help */
                        print_help ();
                        exit (STATE_OK); 
@@ -446,18 +444,15 @@ process_arguments (int argc, char **argv)
                        break;
                case 't':       /* timeout period */
                        if (!is_integer (optarg))
-                               usage2 (_("Timeout Interval must be an integer"), optarg);
+                               usage2 (_("Timeout interval must be a positive integer"), optarg);
                        else
                                timeout_interval = atoi (optarg);
                        break;
 
        /* Test parameters */
                case 'c':                                                                       /* critical time threshold */
-                       if (strspn (optarg, "0123456789:,") < strlen (optarg)) {
-                               printf (_("Invalid critical threshold: %s\n"), optarg);
-                               print_usage ();
-                               exit (STATE_UNKNOWN);
-                       }
+                       if (strspn (optarg, "0123456789:,") < strlen (optarg))
+                               usage2 (_("Invalid critical threshold: %s\n"), optarg);
                        for (ptr = optarg; ptr && jj < MAX_OIDS; jj++) {
                                if (lu_getll (&lower_crit_lim[jj], ptr) == 1)
                                        eval_method[jj] |= CRIT_LT;
@@ -467,11 +462,8 @@ process_arguments (int argc, char **argv)
                        }
                        break;
                case 'w':                                                                       /* warning time threshold */
-                       if (strspn (optarg, "0123456789:,") < strlen (optarg)) {
-                               printf (_("Invalid warning threshold: %s\n"), optarg);
-                               print_usage ();
-                               exit (STATE_UNKNOWN);
-                       }
+                       if (strspn (optarg, "0123456789:,") < strlen (optarg))
+                               usage2 (_("Invalid warning threshold: %s\n"), optarg);
                        for (ptr = optarg; ptr && ii < MAX_OIDS; ii++) {
                                if (lu_getll (&lower_warn_lim[ii], ptr) == 1)
                                        eval_method[ii] |= WARN_LT;
@@ -545,10 +537,9 @@ process_arguments (int argc, char **argv)
                        }
                        labels[nlabels - 1] = optarg;
                        ptr = thisarg (optarg);
+                       labels[nlabels - 1] = ptr;
                        if (strstr (ptr, "'") == ptr)
                                labels[nlabels - 1] = ptr + 1;
-                       else
-                               labels[nlabels - 1] = ptr;
                        while (ptr && (ptr = nextarg (ptr))) {
                                if (nlabels >= labels_size) {
                                        labels_size += 8;
@@ -576,10 +567,9 @@ process_arguments (int argc, char **argv)
                        }
                        unitv[nunits - 1] = optarg;
                        ptr = thisarg (optarg);
+                       unitv[nunits - 1] = ptr;
                        if (strstr (ptr, "'") == ptr)
                                unitv[nunits - 1] = ptr + 1;
-                       else
-                               unitv[nunits - 1] = ptr;
                        while (ptr && (ptr = nextarg (ptr))) {
                                if (nunits >= unitv_size) {
                                        unitv_size += 8;
@@ -609,8 +599,6 @@ process_arguments (int argc, char **argv)
 }
 
 
-
-
 /******************************************************************************
 
 @@-
@@ -631,6 +619,8 @@ first character cannot be a number, however.</para>
 -@@
 ******************************************************************************/
 
+
+
 int
 validate_arguments ()
 {
@@ -673,7 +663,6 @@ validate_arguments ()
                        asprintf(&authpriv, "-l authPriv -a %s -u %s -A %s -x DES -X %s ", authproto, secname, authpasswd, privpasswd);
                }
                
-                                                                       
        }
        else {
                printf (_("Invalid SNMP version: %s\n"), proto);
@@ -681,17 +670,11 @@ validate_arguments ()
                exit (STATE_UNKNOWN);                           
        }
                        
-       
-       
-
        return OK;
 }
 
 
 
-
-
-\f
 char *
 clarify_message (char *msg)
 {
@@ -729,7 +712,6 @@ clarify_message (char *msg)
 
 
 
-
 int
 check_num (int i)
 {
@@ -753,7 +735,7 @@ check_num (int i)
        }
 
        if (eval_method[i] & CRIT_GT && eval_method[i] & CRIT_LT &&
-                       lower_warn_lim[i] > upper_warn_lim[i]) {
+                       lower_crit_lim[i] > upper_crit_lim[i]) {
                if (response_value[i] <= lower_crit_lim[i] &&
                                response_value[i] >= upper_crit_lim[i]) {
                        result = STATE_CRITICAL;
@@ -774,7 +756,6 @@ check_num (int i)
 
 
 
-
 int
 lu_getll (unsigned long *ll, char *str)
 {
@@ -790,7 +771,6 @@ lu_getll (unsigned long *ll, char *str)
 
 
 
-
 int
 lu_getul (unsigned long *ul, char *str)
 {
@@ -806,7 +786,6 @@ lu_getul (unsigned long *ul, char *str)
 
 
 
-
 /* trim leading whitespace
         if there is a leading quote, make sure it balances */
 
@@ -823,7 +802,6 @@ thisarg (char *str)
 
 
 
-
 /* if there's a leading quote, advance to the trailing quote
         set the trailing quote to '\x0'
         if the string continues, advance beyond the comma */
@@ -832,23 +810,21 @@ char *
 nextarg (char *str)
 {
        if (strstr (str, "'") == str) {
+               str[0] = 0;
                if (strlen (str) > 1) {
                        str = strstr (str + 1, "'");
-                       str[0] = 0;
                        return (++str);
                }
                else {
-                       str[0] = 0;
                        return NULL;
                }
        }
        if (strstr (str, ",") == str) {
+               str[0] = 0;
                if (strlen (str) > 1) {
-                       str[0] = 0;
                        return (++str);
                }
                else {
-                       str[0] = 0;
                        return NULL;
                }
        }
@@ -861,15 +837,12 @@ nextarg (char *str)
 
 
 
-
-
-\f
 void
 print_help (void)
 {
        print_revision (progname, revision);
 
-       printf (_(COPYRIGHT), copyright, email);
+       printf (COPYRIGHT, copyright, email);
 
        printf (_("\
 Check status of remote machines and obtain sustem information via SNMP\n\n"));
@@ -970,15 +943,16 @@ Check status of remote machines and obtain sustem information via SNMP\n\n"));
        printf (_(UT_SUPPORT));
 }
 
+
+
 void
 print_usage (void)
 {
-       printf (_("\
+       printf ("\
 Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\
-  [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\
-  [-l label] [-u units] [-p port-number] [-d delimiter]\n\
-  [-D output-delimiter] [-m miblist] [-P snmp version]\n\
-  [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\
-  [-X privpasswd]\n"), progname);
-       printf (_(UT_HLP_VRS), progname, progname);
+                  [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\
+                  [-l label] [-u units] [-p port-number] [-d delimiter]\n\
+                  [-D output-delimiter] [-m miblist] [-P snmp version]\n\
+                  [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\
+                  [-X privpasswd]\n", progname);
 }