Logo
Home page Net-SNMP

Archive Search:

Require all words?

Site Search:
Google

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.


Dynamic Module Creation for the ucd-snmp agent

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:

FileDescription
MakefileA simple makefile used to build the projects
UCD-SNMP-TUTORIAL-MIB.txtThe MIB we'll be writing code for
ustScalarSet.hThe mib module's header file
ustScalarSet.cThe 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:

  1. First off we must get the Makefile file, the ustScalarSet.h file, and the ustScalarSet.c file.
  2. make ustScalarSet.so

Steps to test the shared object:

  1. Start the snmpd and watch the dlmod and ustScalarSet modules interact using the debugging flag (this assumes you already have access control set up properly for your agent):

    • % snmpd -f -L -DustScalarSet,dlmod

  2. In another window, test to make sure that the agent doesn't currently support the ustScalarSet (if you get different results running this command you need to recompile the ucd-snmp agent without the ustScalarSet mib module compiled in directly):

    • % snmpget localhost UCD-SNMP-TUTORIAL-MIB::ustSSSimpleString.0

      ustSSSimpleString.0 = No Such Object available on this agent
      	    

  3. Then, run snmpset to create a new row in the dlmod table:

    • % snmpset localhost UCD-DLMOD-MIB::dlmodStatus.1 i create

      dlmodStatus.1 = create(6)
      

  4. See that the row was created:

    • % snmptable localhost UCD-DLMOD-MIB::dlmodTable

      SNMP table: dlmodTable
      
       dlmodName dlmodPath dlmodError dlmodStatus
                                         unloaded
      

  5. Then set the properties of the row up to point to our new object and to give it a name:

    • % snmpset localhost UCD-DLMOD-MIB::dlmodName.1 s "ustScalarSet" UCD-DLMOD-MIB::dlmodPath.1 s "/path/to/ustScalarSet.so"

      dlmodName.1 = "ustScalarSet" 
      dlmodName.1 = "/path/to/ustScalarSet.so"
      
    • % snmptable localhost UCD-DLMOD-MIB::dlmodTable

      SNMP table: dlmodTable
      
          dlmodName dlmodPath                 dlmodError   dlmodStatus
       ustScalarSet /path/to/ustScalarSet.so                  unloaded
      

  6. Finally, load the shared object into the running agent:

    • % snmpset localhost UCD-DLMOD-MIB::dlmodStatus.1 i load

      dlmodName.1 = ustScalarSet
      dlmodName.1 = /path/to/ustScalarSet.so
      
    • % snmptable localhost UCD-DLMOD-MIB::dlmodTable

      SNMP table: dlmodTable
      
          dlmodName                      dlmodPath dlmodError dlmodStatus
       ustScalarSet /path/to/ustScalarSet.so                 loaded
      

  7. If everything above was done correctly, then the following command should work and will access the shared object's data:

    • % snmpget localhost UCD-SNMP-TUTORIAL-MIB::ustSSSimpleString.0

      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.

Valid CSS!


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.