summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ab67f9e)
raw | patch | inline | side by side (parent: ab67f9e)
author | Subhendu Ghosh <sghosh@users.sourceforge.net> | |
Mon, 11 Nov 2002 19:29:19 +0000 (19:29 +0000) | ||
committer | Subhendu Ghosh <sghosh@users.sourceforge.net> | |
Mon, 11 Nov 2002 19:29:19 +0000 (19:29 +0000) |
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@185 f882894a-f735-0410-b71e-b25c423dba1c
plugins/check_snmp.c | patch | blob | history |
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 7e574c5fd7b52eee334630997889117f3e1a551c..19306b5860377830611443d129c8a9a468a8627f 100644 (file)
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
Units label(s) for output data (e.g., 'sec.').\n\
-p, --port=STRING\n\
UDP port number target is listening on. Default is \"%s\"\n\
+ -P, --protocol=[1|3]\n\
+ SNMP protocol version\n\
+ -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\
+ SNMPv3 securityLevel\n\
+ -U, --secname=USERNAME\n\
+ SNMPv3 username\n\
+ -a, --authproto=[MD5|SHA]\n\
+ SNMPv3 auth proto\n\
+ -A, --authpassword=PASSWORD\n\
+ SNMPv3 authentication password\n\
+ -X, --privpasswd=PASSWORD\n\
+ SNMPv3 crypt passwd (DES)\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\
#define DEFAULT_PORT "161"
#define DEFAULT_TIMEOUT 10
#define DEFAULT_MIBLIST "ALL"
+#define DEFAULT_PROTOCOL "1"
+#define DEFAULT_AUTH_PROTOCOL "MD5"
#include "common.h"
#include "utils.h"
char *server_address = NULL;
char *community = NULL;
+char *authpriv = NULL;
+char *proto = NULL;
+char *seclevel = NULL;
+char *secname = NULL;
+char *authproto = NULL;
+char *authpasswd = NULL;
+char *privpasswd = NULL;
char *oid = "";
char *label = NULL;
char *units = NULL;
usage ("Incorrect arguments supplied\n");
/* create the command line to execute */
- asprintf (&command_line, "%s -m %s -v 1 -c %s %s:%s %s",
- PATH_TO_SNMPGET, miblist, community, server_address, port, oid);
+ asprintf (&command_line, "%s -m %s -v %s %s %s:%s %s",
+ PATH_TO_SNMPGET, miblist, proto, authpriv, server_address, port, oid);
if (verbose)
printf ("%s\n", command_line);
{"label", required_argument, 0, 'l'},
{"units", required_argument, 0, 'u'},
{"port", required_argument, 0, 'p'},
+ {"miblist", required_argument, 0, 'm'},
+ {"protocol", required_argument, 0, 'P'},
+ {"seclevel", required_argument, 0, 'L'},
+ {"secname", required_argument, 0, 'U'},
+ {"authproto", required_argument, 0, 'a'},
+ {"authpasswd", required_argument, 0, 'A'},
+ {"privpasswd", required_argument, 0, 'X'},
{0, 0, 0, 0}
};
#endif
while (1) {
#ifdef HAVE_GETOPT_H
c =
- getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:",
+ getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:",
long_options, &option_index);
#else
- c = getopt (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:");
+ c = getopt (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:");
#endif
if (c == -1 || c == EOF)
usage3 ("Unknown argument", optopt);
case 'h': /* help */
print_help ();
- exit (STATE_OK);
+ exit (STATE_OK);
case 'V': /* version */
print_revision (PROGNAME, REVISION);
exit (STATE_OK);
case 'm': /* List of MIBS */
miblist = strscpy(miblist, optarg);
break;
+ case 'P': /* SNMP protocol version */
+ proto = strscpy(proto, optarg);
+ break;
+ case 'L': /* security level */
+ seclevel = strscpy(seclevel,optarg);
+ break;
+ case 'U': /* security username */
+ secname = strscpy(secname, optarg);
+ break;
+ case 'a': /* auth protocol */
+ authproto = strscpy(authproto, optarg);
+ break;
+ case 'A': /* auth passwd */
+ authpasswd = strscpy(authpasswd, optarg);
+ break;
+ case 'X': /* priv passwd */
+ privpasswd = strscpy(privpasswd, optarg);
+ break;
}
}
if (units == NULL)
asprintf (&units, "");
+ if ( strcmp(seclevel, "noAuthNoPriv") && strcmp(seclevel, "authNoPriv") && strcmp(seclevel, "authPriv") ) {
+ if (seclevel == NULL)
+ asprintf (&seclevel, "noAuthNoPriv");
+ else {
+ printf ("Invalid seclevel: %s! \n", seclevel);
+ print_usage ();
+ exit (STATE_UNKNOWN);
+ }
+ }
+
+
+ if ( strcmp (authproto, "SHA") && strcmp(authproto, "MD5") ) {
+ if (authproto == NULL )
+ asprintf(&authproto, DEFAULT_AUTH_PROTOCOL);
+ else{
+ printf ("Invalid authproto: %s! \n", authproto);
+ print_usage ();
+ exit (STATE_UNKNOWN);
+ }
+ }
+
+
+
+ if (proto == NULL || !strcmp(proto,DEFAULT_PROTOCOL) ) { /* default protocol version */
+ asprintf(&proto, DEFAULT_PROTOCOL);
+ asprintf(&authpriv, "%s%s", "-c ", community);
+ }
+ else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
+ asprintf(&proto, "%s", "3");
+
+ if ( (strcmp(seclevel, "noAuthNoPriv") == 0) || seclevel == NULL ) {
+ authpriv = ssprintf(authpriv, "%s", "-l noAuthNoPriv" );
+ }
+ else if ( strcmp(seclevel, "authNoPriv") == 0 ) {
+ if ( secname == NULL || authpasswd == NULL) {
+ printf ("Missing secname (%s) or authpassword (%s) ! \n",secname, authpasswd );
+ print_usage ();
+ exit (STATE_UNKNOWN);
+ }
+ authpriv = ssprintf(authpriv, "-l authNoPriv -a %s -u %s -A %s ", authproto, secname, authpasswd);
+ }
+ 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 );
+ print_usage ();
+ exit (STATE_UNKNOWN);
+ }
+ authpriv = ssprintf(authpriv, "-l authPriv -a %s -u %s -A %s -X %s ", authproto, secname, authpasswd, privpasswd);
+ }
+
+
+ }
+ else {
+ printf ("Invalid SNMP version: %s\n", proto);
+ print_usage ();
+ exit (STATE_UNKNOWN);
+ }
+
+
+
+
return OK;
}
-\f
+
void