diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 5d65113f4046e7fa5c25ab4b73b690f00b566de6..9ff3439e74783bed1d366c780e86514e70684997 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
void print_usage (void);
void print_help (void);
-#ifdef HAVE_REGEX_H
-#include <regex.h>
+#include "regex.h"
char regex_expect[MAX_INPUT_BUFFER] = "";
regex_t preg;
regmatch_t pmatch[10];
int cflags = REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
int eflags = 0;
int errcode, excode;
-#endif
char *server_address = NULL;
char *community = NULL;
size_t nunits = 0;
size_t unitv_size = 8;
int verbose = FALSE;
+int usesnmpgetnext = FALSE;
unsigned long lower_warn_lim[MAX_OIDS];
unsigned long upper_warn_lim[MAX_OIDS];
unsigned long lower_crit_lim[MAX_OIDS];
unsigned long eval_method[MAX_OIDS];
char *delimiter;
char *output_delim;
-char *miblist;
+char *miblist = NULL;
+int needmibs = FALSE;
+
int
main (int argc, char **argv)
char *p2 = NULL;
char *show = NULL;
char type[8];
+ char *str[MAX_INPUT_BUFFER];
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
output = strdup ("");
delimiter = strdup (" = ");
output_delim = strdup (DEFAULT_OUTPUT_DELIMITER);
- miblist = strdup (DEFAULT_MIBLIST);
+ /* miblist = strdup (DEFAULT_MIBLIST); */
timeout_interval = DEFAULT_TIMEOUT;
retries = DEFAULT_RETRIES;
usage4 (_("Could not parse arguments"));
/* create the command line to execute */
- asprintf (&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
+ if(usesnmpgetnext == TRUE) {
+ asprintf(&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
+ PATH_TO_SNMPGETNEXT, timeout_interval, retries, miblist, proto,
+ authpriv, server_address, port, oid);
+ }else{
+
+ asprintf (&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
PATH_TO_SNMPGET, timeout_interval, retries, miblist, proto,
authpriv, server_address, port, oid);
+ }
+
if (verbose)
printf ("%s\n", command_line);
+
/* run the command */
child_process = spopen (command_line);
/* Process this block for regex matching */
else if (eval_method[i] & CRIT_REGEX) {
-#ifdef HAVE_REGEX_H
excode = regexec (&preg, response, 10, pmatch, eflags);
if (excode == 0) {
iresult = STATE_OK;
else {
iresult = STATE_CRITICAL;
}
-#else
- printf (_("Call for regex which was not a compiled option"));
- exit (STATE_UNKNOWN);
-#endif
}
/* Process this block for existence-nonexistence checks */
i++;
- char *str[MAX_INPUT_BUFFER];
asprintf(str, "=%s%s;;;; ", show, type ? type : "");
strcat(perfstr, *str);
{"authproto", required_argument, 0, 'a'},
{"authpasswd", required_argument, 0, 'A'},
{"privpasswd", required_argument, 0, 'X'},
+ {"next", no_argument, 0, 'n'},
{0, 0, 0, 0}
};
}
while (1) {
- c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:A:X:",
+ c = getopt_long (argc, argv, "nhvVt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:A:X:",
longopts, &option);
if (c == -1 || c == EOF)
case 'm': /* List of MIBS */
miblist = optarg;
break;
+ case 'n': /* usesnmpgetnext */
+ usesnmpgetnext = TRUE;
+ break;
case 'P': /* SNMP protocol version */
proto = optarg;
break;
retries = atoi(optarg);
break;
case 'o': /* object identifier */
+ if ( strspn( optarg, "0123456789." ) != strlen( optarg ) ) {
+ /*
+ * we have something other than digits and periods, so we
+ * have a mib variable, rather than just an SNMP OID, so
+ * we have to actually read the mib files
+ */
+ needmibs = TRUE;
+ }
+
for (ptr = optarg; (ptr = index (ptr, ',')); ptr++)
ptr[0] = ' '; /* relpace comma with space */
for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++)
ii++;
break;
case 'R': /* regex */
-#ifdef HAVE_REGEX_H
cflags = REG_ICASE;
-#endif
case 'r': /* regex */
-#ifdef HAVE_REGEX_H
cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
strncpy (regex_expect, optarg, sizeof (regex_expect) - 1);
regex_expect[sizeof (regex_expect) - 1] = 0;
}
eval_method[jj++] = CRIT_REGEX;
ii++;
-#else
- printf (_("call for regex which was not a compiled option"));
- exit (STATE_UNKNOWN);
-#endif
break;
/* Format */
labels_size += 8;
labels = realloc (labels, labels_size);
if (labels == NULL)
- die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), nlabels);
+ die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels);
}
labels[nlabels - 1] = optarg;
ptr = thisarg (optarg);
unitv_size += 8;
unitv = realloc (unitv, unitv_size);
if (unitv == NULL)
- die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), nunits);
+ die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits);
}
unitv[nunits - 1] = optarg;
ptr = thisarg (optarg);
if (community == NULL)
community = strdup (DEFAULT_COMMUNITY);
+
+
return validate_arguments ();
}
<para>&PROTO_validate_arguments;</para>
-<para>Given a database name, this function returns TRUE if the string
-is a valid PostgreSQL database name, and returns false if it is
-not.</para>
+<para>Checks to see if the default miblist needs to be loaded. Also verifies
+the authentication and authorization combinations based on protocol version
+selected.</para>
-<para>Valid PostgreSQL database names are less than &NAMEDATALEN;
-characters long and consist of letters, numbers, and underscores. The
-first character cannot be a number, however.</para>
+<para></para>
</sect3>
-@@
int
validate_arguments ()
{
+ /* check whether to load locally installed MIBS (CPU/disk intensive) */
+ if (miblist == NULL) {
+ if ( needmibs == TRUE ) {
+ miblist = strdup (DEFAULT_MIBLIST);
+ }else{
+ miblist = "''"; /* don't read any mib files for numeric oids */
+ }
+ }
+
/* Need better checks to verify seclevel and authproto choices */
/* SNMP and Authentication Protocol */
printf (_("\
+ -n, --next\n\
+ Use SNMP GETNEXT instead of SNMP GET\n\
-P, --protocol=[1|2c|3]\n\
SNMP protocol version\n\
-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\
/* OID Stuff */
printf (_("\
-o, --oid=OID(s)\n\
- Object identifier(s) whose value you wish to query\n\
+ Object identifier(s) or SNMP variables whose value you wish to query\n\
-m, --miblist=STRING\n\
- List of MIBS to be loaded (default = ALL)\n -d, --delimiter=STRING\n\
+ List of MIBS to be loaded (default = none if using numeric oids or 'ALL'\n\
+ for symbolic oids.)\n\
+ -d, --delimiter=STRING\n\
Delimiter to use when parsing returned data. Default is \"%s\"\n\
Any data on the right hand side of the delimiter is considered\n\
to be the data that should be used in the evaluation.\n"), DEFAULT_DELIMITER);