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

Andrew Lillie a.lillie at surewest.net
Wed Dec 8 09:52:05 CET 2004


Jason,

I had a similar issue, so I added in the following (in between the 
version 1 and version 3 sections (line 725 in my copy of the source)):

        else if ((strcmp(proto,"2c") == 0) || (strcmp(proto,"2") == 0)) 
{       /* why does the world hate snmp v2 so much? */
                asprintf(&proto, "%s", "2c");
                asprintf(&authpriv, "%s%s", "-c ", community);
        }

This works for me without any issues.

-Andrew

Jason Byrns wrote:

> 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!
>




More information about the Devel mailing list