TUT:mib2c General Overview

From Net-SNMP Wiki
Jump to: navigation, search

This brief tutorial presents an overview of generating skeleton C code for a SNMP MIB using the mib2c utility.

For mib2c to work, it needs to be able to find the MIB file that defines the MIB for which it will be generating code. Running mib2c without arguments informs you of this:

 You didn't give mib2c a valid OID to start with.  IE, I could not find
 any information about the mib node "".  This could be caused
 because you supplied an incorrectly node, or by the MIB that you're
 trying to generate code from isn't loaded.  To make sure your mib is
 loaded, run mib2c using this as an example:
 
    env MIBS="+MY-PERSONAL-MIB" mib2c
 
 You might wish to start by reading the MIB loading tutorial at:
      
 http://www.net-snmp.org/wiki/index.php/TUT:Using_and_loading_MIBS
 
 And making sure you can get snmptranslate to display information about
 your MIB node.  Once snmptranslate works, then come back and try mib2c
 again.

So, if you are interested in generating code for your table XYZTable, make sure that

 snmptranslate -IR XYZTable

works first.

When you run mib2c, you must specify a MIB node for it to process. You can also specify which configuration file you would like it to use to generate the code. The available options are:

 mib2c.array-user.conf 
 mib2c.create-dataset.conf 
 mib2c.int_watch.conf
 mib2c.iterate.conf 
 mib2c.iterate_access.conf 
 mib2c.mfd.conf 
 mib2c.notify.conf 
 mib2c.old-api.conf 
 mib2c.scalar.conf

Running mib2c without specifying a configuration file will prompt you with some questions to help determine which one might be appropriate for your situation.

One thing many people get confuse about is what to do after running mib2c. Contrary to popular belief, simply running mib2c on a MIB does not generate a complete implementation for the module, as indicated by this warning printed after running mib2c without specifying a configuration file:

 **********************************************************************
 * NOTE WELL: The code generated by mib2c is only a template.  *YOU*  *
 * must fill in the code before it'll work most of the time.  In many *
 * cases, spots that MUST be edited within the files are marked with  *
 * /* XXX */ or /* TODO */ comments.                                  *
 **********************************************************************

So once you've generated the template (aka skeleton) code for your mib, you need to edit the code and implement the portions of the code specific to your module. As more elaborate configuration files are developed, it should become simpler to identify the what/when/where portions of the code (the MFD configuration file is the latest step towards this goal - see the MFD tutorial here).

The next section covers the shell script mib2c-update, which is a wrapper around mib2c to help you take advantage of updates to the configuration file you chose for your mib module.

Tutorial Sections

About the SNMP Protocol

These tutorial links talk about SNMP generically and how the protocol itself works. They are good introductory reading material and the concepts are important to understand before diving into the later tutorials about Net-SNMP itself.

Net-SNMP Command Line Applications

These tutorial pages discuss the command line tools provided in the Net-SNMP suite of tools. Nearly all the example commands in these tutorials works if you try it yourself, as they're all examples that talk to our online Net-SNMP test agent. Given them a shot!

Application Configuration

All of our applications support configuration to allow you to customize how they behave.

Net-SNMP Daemons

Net-SNMP comes with two long-running daemons: a SNMP agent (snmpd) for responding to management requests and a notification receiver (snmptrapd) for receiving SNMP notifications.

Coding Tutorials

Net-SNMP comes with a highly flexible and extensible API. The API allows you to create your own commands, add extensions to the agent to support your own MIBs and perform specialized processing of notifications.

Debugging SNMP Applications and Agents

All our tools and applications have extensive debugging output. These tutorials talk about how the debugging system works and how you can add your own debugging statements to you code:

Operating System Specific Tutorials