Let’s have a little background on this in order to understand the requirements a bit better.

I’m currently building a small Gentoo box with iperf for scheduled bandwith measurement which can be monitored via Nagios/Icinga over SNMP. The box will be placed in a branch office with two internet lines to the hub datacenter in each region. So we will have 2 iperf rounds per server with dualtest. This means we need to record the incoming and outgoing speed of each server per uplink and a timestamp to watch for freshness.

Okay there are possibilities to get the values from the iperf checks into Nagios with agents or SNMP passthrough but they seemed more like a workaround than a clean solution. First of all I don’t want to have agents on my Gentoo box as they might need some maintenance and the customer wanted to have a clean SNMP table so the solution led us to write our own MIB.

Initially I thought this would be easy as you just need to write some sort of text file, right? Wrong, it’s far more complex than I have thought and it’s hard to find an entry point to get in the right direction.

But here’s a short summary what needs to be done to complete this simple requirement in no time.

1. Private Enterprise Number

We need a PEN from IANA in order to mess around with the data types we need and don’t depend on other MIBs. You can abuse another PEN but don’t do this as this leads to trouble and applying for a PEN is probably the easiest part here.Just go to http://pen.iana.org/pen/PenApplication.page and fill in your details and send the application off for approval. This will probably take some time in order to process your request but there are no fees attached to it.

2. MIB File

Okay, now get your hands dirty and write your MIB file. There are Editors out there but for my quest I couldn’t justify to spend ~1k EUR for just a few OIDs so I just took the NET-SNMP-EXAMPLES-MIB and modified it to my needs. The MIB can be found either on the linux system or on the awesome net-snmp website where you can find more tutorials for this mission.

3. Create a subagent

This took me quite some time to get it straight. It sounds frightening but you have to create C code for the local snmp agent to understand what he’s supposed to provide when a snmp request for our MIB arrives. As I’m no programmer and my C skills are limited to just some basics I put my faith into mib2c. This binary will create a header file (.h) and a (.c) file based on my handwritten MIB. Obviously there are more options to compile depending on what objects you want to create and how advanced this will be, for my request however it’s sufficient.

Once we have done this we need to compile the new sources into the subagent.

Before starting the subagent check if the snmpd.conf has the master agent enabled so the subagent will attach to it. If this is the case just go ahead by starting the binary

4. Setting the variables

Now we’re ready to set the variables according our MIB definitions this happens with a simple set command.

The available datatypes are as follows:

5. Reading the table

Now you are ready to harvest the fruits of your hard labor and check the values with

I hope this is useful information for some of you in order to get startet. For more information I highly recommend visiting the net-snmp website. There’s also a separate section for writing the subagent and a lot more for more advanced usage, lso quite nice was the website from Oracle.

So here’s a list of the most useful webpages:

Leave a reply

Go top