MIB Creation guide
First, say that this is basically a quick 'n' dirty guide to create a MIB file needed if you want to implement some specific SNMP monitoring on your own. Don't take it too seriously or trustable/standard way to implement things.
Comments start with '–' (two dashes) until EOL.
Start, header, imports and closing
First line should define the MIB name (i.e. TEST-MIB), and indicate the start its definition. The entire defintion (and hence the file) should end with END
;)
TEST-MIB DEFINITIONS ::= BEGIN (...) END
Immeditaley after that, we should indicate which SNMP modules (either other MIBS, types definitions formats, … we need to use and on which MIBs they are found. This is done with IMPORTS
, and we specify the type of element to import, elements to import and from which MIB, like:
IMPORTS MODULE-IDENTITY, OBJECT-TYPE,Counter32, Gauge32, enterprises FROM SNMPv2-SMI TEXTUAL-CONVENTION, DisplayString, FROM SNMPv2-TC MODULE-COMPLIANCE, OBJECT-GROUP, FROM SNMPv2-CONF
You will always need to import something, as your MIB will 'hang' (inherit) from another MIB tree you should import at least that MIB to indicat you are hangingover that tree. Usually enterprises
Module definition
Start naming and defining our stuff, the name of the module with some other informative data;
testMIB MODULE-IDENTITY LAST-UPDATED "200304121008Z" ORGANIZATION "Lady 3Jane" CONTACT-INFO "Marc Franquesa Lady 3Jane Vic" DESCRIPTION "Descripció de vàries línies del MIB" REVISION "200304121008Z" ::= { enterprises 5505 }
Some important details on that:
- The last line
::=
is important: it defines from which point of the tree the MIB will hang, in this case below enterprises with number 5505, so the OID of the root of our MIB will be .1.3.6.1.4.1.5505 - Dates are UTC format and seems is checked that LAST-UPDATED matches REVISION
Structural Element
Frist there are branch nodes, which serve only to structure the tree hierarchy in different branches inside our tree. They don't contian any information, are simply 'structural' nodes:
testMIBObjects OBJECT IDENTIFIER ::= { testMIB 1 } testConformance OBJECT IDENTIFIER ::= { testMIB 2 } testGroups OBJECT IDENTIFIER ::= { testConformance 1 }
Object element
Let's start defining something really useful, and object which can hold data.
testItem OBJECT-TYPE SYNTAX Counter32 MAX-ACCESS read-only STATUS current DESCRIPTION "Descripció del valor" ::= { testMIB 1 }
Notes:
SYNTAX | type of data stored, this should have been imported before (see IMPORTS) |
---|---|
MAX-ACCESS | read-only , not-accessible o read-write . Not realted to access permissions, simply report if the value can be written or only read |
STATUS | current by default. Used to indicat if is obsoleted, or not |
The last part ::= { name #num }
indicates from which object will hang the element and on which index.
Tables
Table definition
First the table itself should be defined:
ifTable OBJECT-TYPE SYNTAX SEQUENCE OF IfEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "A list of interface entries. The number of entries is given by the value of ifNumber." ::= { interfaces 2 }
Like an object, but note the SYNTAX is now a SEQUENCE of something, let's go to define that:
Table entry and index definiton
The 'Entry' need to be defined to indicate which filed will be used as an Index:
ifEntry OBJECT-TYPE SYNTAX IfEntry MAX-ACCESS not-accessible STATUS current DESCRIPTION "An entry containing management information applicable to a particular interface." INDEX { ifIndex } ::= { ifTable 1 }
Also like an object, but this time note the INDEX part which indicate which part of the object will bu used to index it inside the table.
Table index
The Index needs to be defined as well:
ifIndex OBJECT-TYPE SYNTAX InterfaceIndex MAX-ACCESS read-only STATUS current DESCRIPTION "A unique value, greater than zero, for each interface. It is recommended that values are assigned contiguously starting from 1. The value for each interface sub-layer must remain constant at least from one re-initialization of the entity's network management system to the next re- initialization." ::= { ifEntry 1 }
Table Element
Finally we define the elements inside an Entry:
IfEntry ::= SEQUENCE { ifIndex InterfaceIndex, ifDescr DisplayString, ifType IANAifType, ifMtu Integer32, ifSpeed Gauge32, ifPhysAddress PhysAddress, ifAdminStatus INTEGER, ifOperStatus INTEGER, ifLastChange TimeTicks, ifInOctets Counter32 }
Note that you should define now each filed separatedly too.