[Nagiosplug-devel] check_snmp -- Modify source code, to allow SNMP protocol version 2c?

Jason Byrns jason-sourceforge at microlnk.net
Wed Dec 8 08:36:09 CET 2004


Good morning, all.

I'm having trouble with the current check_snmp plugin for Nagios.  Can 
anyone help me make a minor modification?  check_snmp only allows either 
version 1 or version 3 of the SNMP protocol.  But some of our network 
devices will ONLY respond to protocol version 2 (2c, to be exact).

I see check_snmp is just using /usr/bin/snmpget, building an snmpget 
command as appropriate.  If I use snmpget directly, I am able to select 
the protocol version I need and it works just fine.

I'm looking at check_snmp.c right now, and I can see the section of code 
where it validates your choice of protocl version.  Anyone familiar 
enough with SNMP and the check_snmp plugin to advise me?

Here's the snmpget command that works for me:
/usr/bin/snmpget -t 1 -r 9 -m ALL -v 2c -c [COMMUNITY STRING] [DEVICE IP 
ADDRESS]:161 [DESIRED OID]

Here's the section of code from check_snmp.c that seems most relevant. 
Could I just duplicate the protocol version 3 section, and make a 
similar section for protocol version 2c?

And I'm looking now to see how I'd recompile just one plugin.  Any easy 
pointers on that, as well?

	if (proto == NULL || (strcmp(proto,DEFAULT_PROTOCOL) == 0) ) { 
/* 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 ) {
                         asprintf(&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);
                         }
                         asprintf(&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);
                         }
                         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);
         }


Thanks to everyone for all their help in the past, and thanks for any 
future offers of help too!

-- 
Jason Byrns
System Administrator, MicroLnk
http://www.MicroLnk.com/
402-328-8600 ext. 653




More information about the Devel mailing list