[Nagiosplug-checkins] CVS: nagiosplug/plugins check_snmp.c,1.14,1.15

Subhendu Ghosh sghosh at users.sourceforge.net
Mon Nov 11 11:38:20 CET 2002


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv19034

Modified Files:
	check_snmp.c 
Log Message:
long opt for miblist, snmpv3 support (rosenauer)

Index: check_snmp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_snmp.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** check_snmp.c	11 Nov 2002 16:04:12 -0000	1.14
--- check_snmp.c	11 Nov 2002 19:29:19 -0000	1.15
***************
*** 53,56 ****
--- 53,68 ----
   -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\
***************
*** 101,104 ****
--- 113,118 ----
  #define DEFAULT_TIMEOUT 10
  #define DEFAULT_MIBLIST "ALL"
+ #define DEFAULT_PROTOCOL "1"
+ #define DEFAULT_AUTH_PROTOCOL "MD5"
  
  #include "common.h"
***************
*** 161,164 ****
--- 175,185 ----
  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;
***************
*** 212,217 ****
  
  	/* 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);
  	if (verbose)
  		printf ("%s\n", command_line);
--- 233,238 ----
  
  	/* create the command line to execute */
! 	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);
***************
*** 405,408 ****
--- 426,436 ----
  		{"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}
  	};
***************
*** 425,432 ****
  #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:",
  									 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:");
  #endif
  
--- 453,460 ----
  #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: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:P:L:U:a:A:X:");
  #endif
  
***************
*** 439,443 ****
  		case 'h':	/* help */
  			print_help ();
! 			exit (STATE_OK);
  		case 'V':	/* version */
  			print_revision (PROGNAME, REVISION);
--- 467,471 ----
  		case 'h':	/* help */
  			print_help ();
! 			exit (STATE_OK); 
  		case 'V':	/* version */
  			print_revision (PROGNAME, REVISION);
***************
*** 608,611 ****
--- 636,657 ----
  			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;
  
  		}
***************
*** 660,666 ****
  		asprintf (&units, "");
  
  	return OK;
  }
! 
  
  
--- 706,773 ----
  		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;
  }
! 
  
  





More information about the Commits mailing list