Creating a SNMP agent in the Debian

This post is a logic continuation of my friend Marcelo’s posts (in Portuguese sorry) :

https://jedizone.wordpress.com/2012/03/08/o-guia-definitivo-para-os-iniciantes-em-net-snmp-6/
https://jedizone.wordpress.com/2012/03/21/o-guia-definitivo-para-os-iniciantes-em-net-snmp/

When trying to run mib2c in Debian I got this error:

$ mib2c -c mib2c.scalar.conf exemplo

ERROR: You don't have the SNMP perl module installed.  Please obtain
this by getting the latest source release of the net-snmp toolkit from
http://www.net-snmp.org/download/ .  Once you download the source and
unpack it, the perl module is contained in the perl/SNMP directory.
See the README file there for instructions.

Then I downloaded the current netsnmp tarball, decompressed and executed:

$ cd net-snmp-5.7.3/perl/
$ perl Makefile.PL
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for NetSNMP::default_store
Writing MYMETA.yml and MYMETA.json
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for NetSNMP::ASN
Writing MYMETA.yml and MYMETA.json
ERROR:
Net-SNMP installed version: 5.7.2.1 => 5.07021
Perl Module Version:        5.0703

These versions must match for perfect support of the module.  It is possible
that different versions may work together, but it is strongly recommended
that you make these two versions identical.  You can get the Net-SNMP
source code and the associated perl modules directly from 

   http://www.net-snmp.org/

If you want to continue anyway please set the NETSNMP_DONT_CHECK_VERSION
environmental variable to 1 and re-run the Makefile.PL script.

Hmm, after downloading the netsnmp version 5.7.2.1 (that is the version used by my Debian distro) and repeated the process and it worked fine:

$ cd net-snmp-5.7.3/perl/
$ perl Makefile.PL
$ make
$ sudo make install

Great perl snmp module compiled and installed.

Now we can create our MIBs as a dynamic library (called module in this context) :

$ mib2c -c mib2c.scalar.conf exemplo

$ gcc `net-snmp-config --cflags` -fPIC -shared -g -O0 -o exemplo.so exemplo.c `net-snmp-config --libs` -lX11

Copy it to your defaul library directory (optional, but recommend if you are a “copypaster”) :

$ sudo cp exemplo.so /usr/lib
$ sudo ldconfig

Edit/create file /etc/snmp/snmpd.conf with:

createUser initial
rwuser initial

You can replace “initial” by other user, but you need to create this new user using the “net-snmp-config” command. This “initial” is an initial user that comes pre-configured in the snmp.

Case snmpd is running you need to stop it:

$ sudo service snmpd stop

Now start snmpd manually and ask it to debug the modules exemplo,dlmod:

$ sudo snmpd -f -L -Dexemplo,dlmod

Unfortunately this is not enough to start your dynamic module, as you can see:

$ snmpget -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = No Such Object available on this agent at this OID

We need to create a new row in the dlmod table:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodStatus.1 i create 

UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: create(6)

We can see its content using this command:

$ snmptable -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodTable 

SNMP table: UCD-DLMOD-MIB::dlmodTable

 dlmodName dlmodPath dlmodError dlmodStatus
                                   unloaded

We need to update this new row with our dynamic module info:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodName.1 s "exemplo" UCD-DLMOD-MIB::dlmodPath.1 s "/usr/lib/exemplo.so"

MIB::dlmodName.1 = STRING: exemplo
UCD-DLMOD-MIB::dlmodPath.1 = STRING: /usr/lib/exemplo.so

Load the dynamic module:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodStatus.1 i load

UCD-DLMOD-MIB::dlmodStatus.1 = INTEGER: load(4)

Confirm it was loaded successfully:

$ snmptable -c acme -v3 -u initial -l noAuthNoPriv localhost UCD-DLMOD-MIB::dlmodTable 

SNMP table: UCD-DLMOD-MIB::dlmodTable

 dlmodName           dlmodPath dlmodError dlmodStatus
   exemplo /usr/lib/exemplo.so                 loaded

Now that the dynamic library was loaded you can repeat the above command:

$ snmpget -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = INTEGER: 0

Let try to set it to 1:

$ snmpset -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0 i 1

EXEMPLO-MIB::scrollLock.0 = INTEGER: aceso(1)

Let to double check it changed:

$ snmpget -c acme -v3 -u initial -l noAuthNoPriv localhost EXEMPLO-MIB::scrollLock.0

EXEMPLO-MIB::scrollLock.0 = INTEGER: aceso(1)

Source: http://net-snmp.sourceforge.net/tutorial/tutorial-5/toolkit/dlmod/

How to create SNMP User: https://stomp.colorado.edu/blog/blog/2010/07/09/on-configuring-snmpv3-in-net-snmp/

One thought on “Creating a SNMP agent in the Debian

  1. Allowed values to set scrollLock.0 are 0 or 1, trying to set it to 2 will return:

    X Error of failed request: BadValue (integer parameter out of range for operation)
    Major opcode of failed request: 102 (X_ChangeKeyboardControl)
    Value in failed request: 0x2
    Serial number of failed request: 11
    Current serial number in output stream: 12

    The MIB definition needs to change to aceso(1) and apagado(0)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s