diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index af8f11983b10f9713df73861126579ce1a48bbf9..ef411e15fe59208e521b66fbdb7a723cbaff06a2 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 *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"
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
unsigned long response_value[MAX_OIDS];
int check_warning_value = FALSE;
int check_critical_value = FALSE;
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;
char *delimiter;
char *output_delim;
char *miblist;
-
-
-\f
int
main (int argc, char **argv)
{
int
main (int argc, char **argv)
{
char *p2 = NULL;
char *show = NULL;
char *p2 = NULL;
char *show = NULL;
+ setlocale (LC_ALL, "");
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+
labels = malloc (labels_size);
unitv = malloc (unitv_size);
for (i = 0; i < MAX_OIDS; i++)
labels = malloc (labels_size);
unitv = malloc (unitv_size);
for (i = 0; i < MAX_OIDS; i++)
miblist = strdup (DEFAULT_MIBLIST);
if (process_arguments (argc, argv) == ERROR)
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",
/* create the command line to execute */
asprintf (&command_line, "%s -t 1 -r %d -m %s -v %s %s %s:%s %s",
eval_method[i] & WARN_NE) {
p2 = strpbrk (p2, "0123456789");
if (p2 == NULL)
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]);
response_value[i] = strtoul (p2, NULL, 10);
iresult = check_num (i);
asprintf (&show, "%lu", response_value[i]);
/* Process this block for string matching */
else if (eval_method[i] & CRIT_STRING) {
/* 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;
iresult = STATE_CRITICAL;
else
iresult = STATE_OK;
iresult = STATE_CRITICAL;
}
#else
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
}
exit (STATE_UNKNOWN);
#endif
}
if (found == 0)
die (STATE_UNKNOWN,
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);
label,
command_line);
-
-
-\f
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
/* process command-line arguments */
int
process_arguments (int argc, char **argv)
switch (c) {
case '?': /* usage */
switch (c) {
case '?': /* usage */
- usage3 ("Unknown argument", optopt);
+ usage2 (_("Unknown argument"), optarg);
case 'h': /* help */
print_help ();
exit (STATE_OK);
case 'h': /* help */
print_help ();
exit (STATE_OK);
break;
case 't': /* timeout period */
if (!is_integer (optarg))
break;
case 't': /* timeout period */
if (!is_integer (optarg))
- usage2 (_("Timeout Interval must be an integer"), optarg);
- timeout_interval = atoi (optarg);
+ usage2 (_("Timeout interval must be a positive integer"), optarg);
+ else
+ timeout_interval = atoi (optarg);
break;
/* Test parameters */
case 'c': /* critical time threshold */
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;
for (ptr = optarg; ptr && jj < MAX_OIDS; jj++) {
if (lu_getll (&lower_crit_lim[jj], ptr) == 1)
eval_method[jj] |= CRIT_LT;
}
break;
case 'w': /* warning time threshold */
}
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;
for (ptr = optarg; ptr && ii < MAX_OIDS; ii++) {
if (lu_getll (&lower_warn_lim[ii], ptr) == 1)
eval_method[ii] |= WARN_LT;
eval_method[jj++] = CRIT_REGEX;
ii++;
#else
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;
exit (STATE_UNKNOWN);
#endif
break;
labels_size += 8;
labels = realloc (labels, labels_size);
if (labels == NULL)
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);
}
labels[nlabels - 1] = optarg;
ptr = thisarg (optarg);
+ labels[nlabels - 1] = ptr;
if (strstr (ptr, "'") == ptr)
labels[nlabels - 1] = ptr + 1;
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;
labels = realloc (labels, labels_size);
if (labels == NULL)
while (ptr && (ptr = nextarg (ptr))) {
if (nlabels >= labels_size) {
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);
}
labels++;
ptr = thisarg (ptr);
unitv_size += 8;
unitv = realloc (unitv, unitv_size);
if (unitv == NULL)
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);
}
unitv[nunits - 1] = optarg;
ptr = thisarg (optarg);
+ unitv[nunits - 1] = ptr;
if (strstr (ptr, "'") == ptr)
unitv[nunits - 1] = ptr + 1;
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;
while (ptr && (ptr = nextarg (ptr))) {
if (nunits >= unitv_size) {
unitv_size += 8;
}
}
-
-
/******************************************************************************
@@-
/******************************************************************************
@@-
-@@
******************************************************************************/
-@@
******************************************************************************/
+
+
int
validate_arguments ()
{
int
validate_arguments ()
{
}
else if ( strcmp(seclevel, "authNoPriv") == 0 ) {
if ( secname == NULL || authpasswd == NULL) {
}
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);
}
print_usage ();
exit (STATE_UNKNOWN);
}
}
else if ( strcmp(seclevel, "authPriv") == 0 ) {
if ( secname == NULL || authpasswd == NULL || privpasswd == NULL ) {
}
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);
}
print_usage ();
exit (STATE_UNKNOWN);
}
asprintf(&authpriv, "-l authPriv -a %s -u %s -A %s -x DES -X %s ", authproto, secname, authpasswd, privpasswd);
}
-
}
else {
}
else {
- printf (_("Invalid SNMP version: %s\n"), proto);
- print_usage ();
- exit (STATE_UNKNOWN);
+ usage2 (_("Invalid SNMP version"), proto);
}
}
-
-
-
return OK;
}
return OK;
}
-
-
-\f
char *
clarify_message (char *msg)
{
char *
clarify_message (char *msg)
{
-
int
check_num (int i)
{
int
check_num (int i)
{
}
if (eval_method[i] & CRIT_GT && eval_method[i] & CRIT_LT &&
}
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;
if (response_value[i] <= lower_crit_lim[i] &&
response_value[i] >= upper_crit_lim[i]) {
result = STATE_CRITICAL;
-
int
lu_getll (unsigned long *ll, char *str)
{
int
lu_getll (unsigned long *ll, char *str)
{
-
int
lu_getul (unsigned long *ul, char *str)
{
int
lu_getul (unsigned long *ul, char *str)
{
-
/* trim leading whitespace
if there is a leading quote, make sure it balances */
/* trim leading whitespace
if there is a leading quote, make sure it balances */
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, "'"))
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;
}
}
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 */
/* 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 */
nextarg (char *str)
{
if (strstr (str, "'") == str) {
nextarg (char *str)
{
if (strstr (str, "'") == str) {
+ str[0] = 0;
if (strlen (str) > 1) {
str = strstr (str + 1, "'");
if (strlen (str) > 1) {
str = strstr (str + 1, "'");
- str[0] = 0;
return (++str);
}
else {
return (++str);
}
else {
- str[0] = 0;
return NULL;
}
}
if (strstr (str, ",") == str) {
return NULL;
}
}
if (strstr (str, ",") == str) {
+ str[0] = 0;
if (strlen (str) > 1) {
if (strlen (str) > 1) {
- str[0] = 0;
return (++str);
}
else {
return (++str);
}
else {
- str[0] = 0;
return NULL;
}
}
return NULL;
}
}
-
-
-\f
void
print_help (void)
{
print_revision (progname, revision);
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"));
printf (_("\
Check status of remote machines and obtain sustem information via SNMP\n\n"));
@@ -965,15 +937,16 @@ Check status of remote machines and obtain sustem information via SNMP\n\n"));
printf (_(UT_SUPPORT));
}
printf (_(UT_SUPPORT));
}
+
+
void
print_usage (void)
{
void
print_usage (void)
{
- printf (_("\
+ printf ("\
Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\
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);
}
}