Note: Much of this tutorial requires ucd-snmp-4.2.2 or higher!, so make sure you get it before running the commands found in this tutorial.
Note: A new tutorial for net-snmp 5.0 and above is available as well. The commands is
the ucd-snmp specific tutorial will not work as expected if you
are using net-snmp and not ucd-snmp.
Now, lets take the ustScalarSet mib module we created in the previous example and make it work as a dynamicly loadable shared object.
Note: For this to work, you must have compiled the ucd-snmp package with dynamicly loadable module support turned on, as well as built it with --enable-shared turned on . It's on by default, if your system supports it, in version 4.2 and higher. You can check your agent but looking at the output of the "snmpd -H" command for the "dlmod" token. If its listed, the compiled agent supports it.
Note: You should also re-compile the agent without the ustScalarSet code by removing it from the list of --with-mib-modules option, or else this example won't work correctly.
Note: All command line options below assume you have an appropriately setup ~/.snmp/snmp.conf file that allows you to not have to specify a snmp version number, community name, username, or whatever else in order to talk to your agent. The agent, of course, must have a matching /usr/local/share/snmp/snmpd.conf file (or equivalent).
Here are the files discussed in this example so you can download them:
File | Description |
---|---|
Makefile | A simple makefile used to build the projects |
UCD-SNMP-TUTORIAL-MIB.txt | The MIB we'll be writing code for |
ustScalarSet.h | The mib module's header file |
ustScalarSet.c | The mib module's C source code |
The shared object loader calls the "init_ustScalarSet()" function when the module gets loaded, and calls the "deinit_ustScalarSet()" when (and if) the module is unloaded. These function names to use are built by adding the shared object's module name (UCD-DLMOD-MIB::dlmodName) to the `init_' and `deinit_' prefixes.
Steps to build the shared object:
Steps to test the shared object:
ustSSSimpleString.0 = No Such Object available on this agent
dlmodStatus.1 = create(6)
SNMP table: dlmodTable dlmodName dlmodPath dlmodError dlmodStatus unloaded
dlmodName.1 = "ustScalarSet" dlmodName.1 = "/path/to/ustScalarSet.so"
SNMP table: dlmodTable dlmodName dlmodPath dlmodError dlmodStatus ustScalarSet /path/to/ustScalarSet.so unloaded
dlmodName.1 = ustScalarSet dlmodName.1 = /path/to/ustScalarSet.so
SNMP table: dlmodTable dlmodName dlmodPath dlmodError dlmodStatus ustScalarSet /path/to/ustScalarSet.so loaded
ustSSSimpleString.0 = "Hello World"
You can also load shared objects using the "dlmod" token in the snmpd.conf file by putting a line like this in your snmpd.conf file:
dlmod ustScalarSet /path/to/ustScalarSet.so
The first argument specifies the shared object's module name
(UCD-DLMOD-MIB::dlmodName) and second argument specifies the
full pathname of the shared object file.
Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.