From Net-SNMP Wiki
Jump to: navigation, search
Net-SNMP Tool
Manual: mib2c
Code: local/mib2c

The mib2c script is badly named. It really should have been named mib2anything, as it's actually can provide output tailored to anything you might want to change MIB data into.


mib2c Goals

mib2c was designed to:

  • Alleviate the task of producing identically similar code for each mib object
  • Be a generic MIB processing engine, capable of converting MIBs and MIB structures to any other format.
  • Provide an easy-as-possible getting started interface for new coders trying to write new code to support MIBs
Error creating thumbnail: Unable to save thumbnail to destination

Regeneratable Code

One second goal besides just generating code once and leaving it to the programmer to fill in the blanks, is to provide a framework for splitting code into two pieces:

  • code that needs to be maintained by a human implementing the MIB objects
  • code that needs only to be written by mib2c itself, and can be regenerated in the future to take advantage of new features produced by mib2c

Some of the mib2c output will contain both of these types of code, and code that can be regenerated/updated in the future is marked as such.

Development Process Using mib2c

The typical process for using mib2c follows this pattern:

  1. Write a MIB and objects for it (eg, tables and scalars)
  2. run mib2c on the MIB objects to generate code, producing:
    • code that should be edited to complete the implementation
    • code that should not be edited ("regeneratable").
  3. Edit the code to return value MIB data (or accept it when processing SETs)

Example mib2c input file

If you put this in file.conf:

 @open -@
 @foreach $t table@
     @foreach $c column@
         $c is a column of type $c.type at $c.objectID

And then run it on a table, such as the ifTable:

 # mib2c -c file.conf ifTable

You'll get this output to your screen (the '-' in '@open -'):

 writing to -
    ifIndex is a column of type ASN_INTEGER at .
    ifDescr is a column of type ASN_OCTET_STR at .
    ifType is a column of type ASN_INTEGER at .
    ifMtu is a column of type ASN_INTEGER at .
    ifSpeed is a column of type ASN_GAUGE at .
    ifPhysAddress is a column of type ASN_OCTET_STR at .
    ifAdminStatus is a column of type ASN_INTEGER at .
    ifOperStatus is a column of type ASN_INTEGER at .

Further Reading

Personal tools