Logo
Home page Net-SNMP

Archive Search:

Require all words?

Site Search:
Google
Net-SNMP Tutorial -- dynamic module loading

NET-SNMP Tutorial -- Dynamic Module Creation for the net-snmp agent

First off, you need to write a mib module first before you can do this part of the tutorial. We assume you have read and completed the mib module portion of the toolkit tutorial. This part of the tutorial shows how to install a dynamic module into the agent, assuming you already have written a mib-module which we'll then compile into a dynamic module. For example purposes, we'll refer to some example MIB objects and code: the NET-SNMP-TUTORIAL-MIB MIB, and the example mib module and it's header file.

Note: For this to work, you must have compiled the net-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). You can check for support in 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: 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).

Download the example files as follows:

git clone https://github.com/net-snmp/subagent-example.git

The shared object loader calls the "init_nstAgentPluginObject()" function in the above code when it gets loaded, and calls the "deinit_nstAgentPluginObject()" 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.

Build the shared object as follows: make nstAgentPluginObject.so.

Steps to test the shared object:

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

    • % snmpd -f -L -DnstAgentPluginObject,dlmod

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

    • % snmpget localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0

      nstAgentPluginObject.0 = No Such Object available on this agent at this OID
      	    

  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 "nstAgentPluginObject" UCD-DLMOD-MIB::dlmodPath.1 s "/path/to/nstAgentPluginObject.so"

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

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

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

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

      dlmodStatus.1 = loaded(1)
      
    • % snmptable localhost UCD-DLMOD-MIB::dlmodTable

      SNMP table: dlmodTable
      
          dlmodName                      dlmodPath dlmodError dlmodStatus
       nstAgentPluginObject /path/to/nstAgentPluginObject.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 NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0

      nstAgentPluginObject.0 = INTEGER: 3
      


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 nstAgentPluginObject /path/to/nstAgentPluginObject.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: Friday, 03-Jul-2020 23:07:48 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.