Difference between revisions of "Writing your own MIBs"
(Created page with "{{GoodAnswer}} == Question == I need to write my own MIB What do I need to know? (Note: This answer is about writing a MIB, which defines objects and their syntax. It is not...") |
(No difference)
|
Latest revision as of 17:09, 19 December 2013
This is a Good Answer article. It was likely created as a response to a question on a Net-SNMP Mailing List and written up here for others to see. It likely covers material not yet in the FAQ or in the Tutorial but may someday be moved there
Contents
Question
I need to write my own MIB What do I need to know? (Note: This answer is about writing a MIB, which defines objects and their syntax. It is not about implementing a MIB for the Net-SNMP agent, which is covered elsewhere.)
Answer
What does a MIB look like?
If you aren't familiar with MIBs, take a look at the Net-SNMP examples MIB. It is an example of a simple MIB you can read to get a feel for what a basic MIB looks like. It contains scalars, a table and some notification objects.
What goes into a MIB?
The most important thing you'll need for your own MIB is the list of objects you need to represent in the MIB. Once you have this list, you can organize them. SNMP MIBs have a tree structure, and the root of the tree and a good number of standard objects are defined by the IETF. You'll need a place in the tree to insert your MIB.
Getting your own enterprise OID
If you are going to define a MIB that you are going to share with the world, you need a place in the tree that wont conflict with any other MIBs written by others. The enterprises branch of the tree is specifically for organizations (and individuals) to define their own objects. You can apply for your own enterprise OID on the IANA Pen Application page.
If you are defining a MIB that will only be used internally, you could also insert your MIB in the experimental tree. Just be aware that confusion can ensue if management applications try to load multiple MIBs which contain overlapping OIDs.
Writing the MIB
One simple way to start is to take an existing MIB and modify it for your own use. For example, use the Net-SNMP examples mib, and start by moving it to your own branch. Here is an example that moves it into the netSnmpPlaypen, which is a branch we've defined for private testing purposes. No "public" management objects should ever be defined within this tree. It is provided for private experimentation, prior to transferring a MIB structure to another part of the overall OID tree.
xyzSnmpExamples MODULE-IDENTITY LAST-UPDATED "201312190000Z" ORGANIZATION "www.example.com" CONTACT-INFO "postal: John Doe 123 Main Street Anytown, CA 00000 email: xyz-mib@example.com" DESCRIPTION "Example MIB objects for agent module example implementations" DESCRIPTION "First draft" ::= { netSnmpPlaypen 42 } -- or "enterprises XXXX" where XXXX with your assigned enterprise OID
Now you can change the names and definitions of the object and experiment.
Validating your MIB
Once you have a MIB, you should run it through a MIB syntax checker to make sure it can be compiled. We recommend using smilint from libsmi. Check their pages for usage information.
External References
The syntax for a MIB and the process of actually writing a MIB are too complex to cover in a basic wiki page, so at this point we're going to hand you off to some resources that cover the topic in much more depth.
- Buy Understanding SNMP MIBs, by Dave Perkins
- If you are on a budget, there is a free PDF of the precursor to this book, which only covers SNMP version 1. It will help you understand the basic concepts, but we strongly recommend you get the book, which covers SNMP version 2.
- Buy SNMP MIB Handbook by Larry Walsh
Implementing a MIB in Net-SNMP
Once you have a MIB written, there are several resources in the wiki for implementing the MIB with Net-SNMP.