X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=plugins%2Fcheck_snmp.c;h=ef411e15fe59208e521b66fbdb7a723cbaff06a2;hb=187f86275426bfb501c7180c48161e1e22af1ef7;hp=b17a41775ba956580c972f0185d746e6a18cd109;hpb=c5f0ee256bc9508e19b86003c5327ffafd2de28e;p=nagiosplug.git diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index b17a417..ef411e1 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -14,11 +14,13 @@ 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; - - - 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", @@ -252,7 +251,7 @@ main (int argc, char **argv) eval_method[i] & WARN_NE) { p2 = strpbrk (p2, "0123456789"); if (p2 == NULL) - die (STATE_UNKNOWN,"No valid data returned"); + die (STATE_UNKNOWN,_("No valid data returned")); response_value[i] = strtoul (p2, NULL, 10); iresult = check_num (i); asprintf (&show, "%lu", response_value[i]); @@ -260,7 +259,7 @@ main (int argc, char **argv) /* Process this block for string matching */ else if (eval_method[i] & CRIT_STRING) { - if (strcmp (response, string_value)) + if (strcmp (show, string_value)) iresult = STATE_CRITICAL; else iresult = STATE_OK; @@ -282,7 +281,7 @@ main (int argc, char **argv) iresult = STATE_CRITICAL; } #else - printf (_("%s UNKNOWN: call for regex which was not a compiled option"), label); + printf (_("Call for regex which was not a compiled option")); exit (STATE_UNKNOWN); #endif } @@ -344,9 +343,6 @@ main (int argc, char **argv) - - - /* process command-line arguments */ int process_arguments (int argc, char **argv) @@ -402,7 +398,7 @@ process_arguments (int argc, char **argv) switch (c) { case '?': /* usage */ - usage3 ("Unknown argument", optopt); + usage2 (_("Unknown argument"), optarg); case 'h': /* help */ print_help (); exit (STATE_OK); @@ -446,7 +442,7 @@ 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; @@ -515,7 +511,7 @@ process_arguments (int argc, char **argv) eval_method[jj++] = CRIT_REGEX; ii++; #else - printf (_("%s UNKNOWN: call for regex which was not a compiled option"), label); + printf (_("call for regex which was not a compiled option")); exit (STATE_UNKNOWN); #endif break; @@ -534,8 +530,7 @@ process_arguments (int argc, char **argv) labels_size += 8; labels = realloc (labels, labels_size); if (labels == NULL) - die (STATE_UNKNOWN, - _("Could not realloc() labels[%d]"), nlabels); + die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), nlabels); } labels[nlabels - 1] = optarg; ptr = thisarg (optarg); @@ -547,7 +542,7 @@ process_arguments (int argc, char **argv) labels_size += 8; labels = realloc (labels, labels_size); if (labels == NULL) - die (STATE_UNKNOWN, _("Could not realloc() labels\n")); + die (STATE_UNKNOWN, _("Could not reallocate labels\n")); } labels++; ptr = thisarg (ptr); @@ -564,8 +559,7 @@ process_arguments (int argc, char **argv) unitv_size += 8; unitv = realloc (unitv, unitv_size); if (unitv == NULL) - die (STATE_UNKNOWN, - _("Could not realloc() units [%d]\n"), nunits); + die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), nunits); } unitv[nunits - 1] = optarg; ptr = thisarg (optarg); @@ -601,8 +595,6 @@ process_arguments (int argc, char **argv) } - - /****************************************************************************** @@- @@ -623,6 +615,8 @@ first character cannot be a number, however. -@@ ******************************************************************************/ + + int validate_arguments () { @@ -650,7 +644,7 @@ validate_arguments () } else if ( strcmp(seclevel, "authNoPriv") == 0 ) { if ( secname == NULL || authpasswd == NULL) { - printf (_("Missing secname (%s) or authpassword (%s) ! \n)"),secname, authpasswd ); + printf (_("Missing secname (%s) or authpassword (%s) ! \n"),secname, authpasswd ); print_usage (); exit (STATE_UNKNOWN); } @@ -658,32 +652,23 @@ validate_arguments () } else if ( strcmp(seclevel, "authPriv") == 0 ) { if ( secname == NULL || authpasswd == NULL || privpasswd == NULL ) { - printf (("Missing secname (%s), authpassword (%s), or privpasswd (%s)! \n"),secname, authpasswd,privpasswd ); + printf (_("Missing secname (%s), authpassword (%s), or privpasswd (%s)! \n"),secname, authpasswd,privpasswd ); print_usage (); exit (STATE_UNKNOWN); } 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); - print_usage (); - exit (STATE_UNKNOWN); + usage2 (_("Invalid SNMP version"), proto); } - - - return OK; } - - - char * clarify_message (char *msg) { @@ -721,7 +706,6 @@ clarify_message (char *msg) - int check_num (int i) { @@ -745,7 +729,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; @@ -766,7 +750,6 @@ check_num (int i) - int lu_getll (unsigned long *ll, char *str) { @@ -782,7 +765,6 @@ lu_getll (unsigned long *ll, char *str) - int lu_getul (unsigned long *ul, char *str) { @@ -798,7 +780,6 @@ lu_getul (unsigned long *ul, char *str) - /* trim leading whitespace if there is a leading quote, make sure it balances */ @@ -808,14 +789,13 @@ thisarg (char *str) str += strspn (str, " \t\r\n"); /* trim any leading whitespace */ if (strstr (str, "'") == str) { /* handle SIMPLE quoted strings */ if (strlen (str) == 1 || !strstr (str + 1, "'")) - die (STATE_UNKNOWN, "Unbalanced quotes\n"); + die (STATE_UNKNOWN, _("Unbalanced quotes\n")); } return 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 */ @@ -851,15 +831,12 @@ nextarg (char *str) - - - 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")); @@ -960,15 +937,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 -o [-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); }