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.


UCD-SNMP Tutorial -- MIB Module

Here we discuss how to write a simple mib module, to extend the agent using C code.

Here are the files discussed in this example so you can download them:

FileDescription
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

This example builds the C code necessary to implement the UCD-SNMP-TUTORIAL-MIB MIB. The majority of the code was written using the mib2c program, not discussed here.

The API for the mib module code is fully discussed in http://www.csc.liv.ac.uk/~daves/Misc/UCD/guide.html and is highly recommended reading material.

The MIB is a simple one (also not discussed extensively here). It contains only two variables: a string, and the time since the string was last modified. The string can be set using an SNMP-SET, which then updates the archived value and resets the timer.

To use it, get the ucd-snmp source code and extract it. Then download the ustScalarSet.h and ustScalarSet.c that make up the code for the mib module. Place them in the ucd-snmp source directory under the agent/mibgroups sub-directory. Configure the ucd-snmp package to include them when it is compiled by adding an argument to the configure script:

% ./configure --with-mib-modules=ustScalarSet
    

Note that ustScalarSet is the prefix to our .c and .h files.

Build your new agent with the tutorial code by running make:

% make
    

Finally, install the whole lot by running make install:

% make install
    

Lets use a horrible (security wise) snmpd.conf file so we're all consistent. Download it and place it in /usr/local/share/snmp/snmpd.conf.

Lets talk about the important pieces in these files: ...

Set Processing

To process an SNMP-SET, the agent must use a series of calls to the mib module code to ensure that processing of all sets in the incoming packet can be successful. This gives you or other mib modules the chance to bail out early on in the transaction sequence and thus stop all of the transactions in the set from happening. This is important for continuity. However, it makes set code processing a bit more complex. Let's examine a simple state diagram that the master agent uses at each step of the way:

In a perfect operation with no failures, we take the vertical path on the left. If any of the mib modules being acted upon returns an error of any kind, we will branch to the right to one of the failure states where you must clean up and possibly undo what you did in previous steps.


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.