TUT:mib2c config files

From Net-SNMP Wiki
Revision as of 22:13, 31 January 2007 by Wes (Talk | contribs) (Additional reading material)

Jump to: navigation, search

mib2c is actually very poorly named. It was originally designed as a mechanism for producing C-code from a MIB file. However, it really is just a template system. You can produce just about anything from a MIB if you can write a template about how you want the output to be. For example:

 mib2c -c mib2c.genhtml.conf ifTable

The above command writes a html summary of the ifTable branch of the mib tree. It's probably much more readable than the average MIB file to many people.

Writing your own .conf file

The mib2c configuration file language is fairly easy to understand. See the mib2c configuration file manual page for details.

A quick preview: If you have a file that looks like this:

 @open -@
 @foreach $t table@
   In table $t we have the following indexes:
   @foreach $i index@
     $i
       (at $i.subid) which is of type $i.type
   @end@
   And the following columns:
   @foreach $i nonindex@
     $i
       (at $i.subid) which is of type $i.type
   @end@
 @end@

and we run mib2c pointing to that file we get:

 > mib2c -c MYFILE.conf ifTable
 writing to -
   In table ifTable we have the following indexes:
     ifIndex
       (at 1) which is of type ASN_INTEGER
   And the following columns:
     ifDescr
       (at 2) which is of type ASN_OCTET_STR
     ifType
       (at 3) which is of type ASN_INTEGER
     ifMtu
       (at 4) which is of type ASN_INTEGER
     ifSpeed
       (at 5) which is of type ASN_GAUGE
     ifPhysAddress
       (at 6) which is of type ASN_OCTET_STR
     ifAdminStatus
       (at 7) which is of type ASN_INTEGER
     ifOperStatus
       (at 8) which is of type ASN_INTEGER
     ifLastChange
       (at 9) which is of type ASN_TIMETICKS
     ifInOctets
       (at 10) which is of type ASN_COUNTER
     ifInUcastPkts
       (at 11) which is of type ASN_COUNTER
     ifInNUcastPkts
       (at 12) which is of type ASN_COUNTER
     ifInDiscards
       (at 13) which is of type ASN_COUNTER
     ifInErrors
       (at 14) which is of type ASN_COUNTER
     ifInUnknownProtos
       (at 15) which is of type ASN_COUNTER
     ifOutOctets
       (at 16) which is of type ASN_COUNTER
     ifOutUcastPkts
       (at 17) which is of type ASN_COUNTER
     ifOutNUcastPkts
       (at 18) which is of type ASN_COUNTER
     ifOutDiscards
       (at 19) which is of type ASN_COUNTER
     ifOutErrors
       (at 20) which is of type ASN_COUNTER
     ifOutQLen
       (at 21) which is of type ASN_GAUGE
     ifSpecific
       (at 22) which is of type ASN_OBJECT_ID

As you can see, we can change a MIB into just about anything.

Additional reading material