TUT:Using and loading MIBS
Using local MIBs
The net-snmp tools can translate numeric object identifies (OIDs) into textual object identifiers using the MIB description files. The net-snmp toolkit provides a few of the standard MIBs, but certainly doesn't contain all the MIBs known to man.
First off, you should know about the paths that the tools load MIBs from. By default, it loads things from the following list of directories:
- $HOME/.snmp/mibs
- /usr/local/share/snmp/mibs
Note that many distributions change the default paths. To find out which directories are used on your system, run the following command:
net-snmp-config --default-mibdirs
(if that doesn't work because your distribution didn't repackage net-snmp-config you can use this instead:)
snmptranslate -Dinit_mib .1.3 2>&1 |grep MIBDIR
So, lets say you have a MIB called CISCO-RHINO-MIB that you want parsed (it really exists, and I particularly liked the name so I'm using it in the tutorial). Place the file in one of the above two directories. If you pulled it from another file (like an RFC), make sure it doesn't contain anything non-MIB related (like the text leading up to it, and the page separators). The very first line in the file should begin with something like "CISCO-RHINO-MIB DEFINITIONS ::= BEGIN", and the very last line of the file should be "END"
Now, pick a node in the file that you want to translate that currently isn't being translated. From the CISCO-RHINO-MIB, I'll pick the ciscoLS1010ChassisFanLed node.
First, lets verify that our handy snmptranslate command (discussed snmptranslate) doesn't yet know about this node:
% snmptranslate -IR -On ciscoLS1010ChassisFanLed Unknown object identifier: ciscoLS1010ChassisFanLed
Nope, it doesn't. So, first we need to download the CISCO-RHINO-MIB file and place it in a directory that our snmp tools can find it in. So, I'm going to place the file in $HOME/.snmp/mibs.
Now, lets use the -m flag to snmptranslate to tell it to load that mib. We'll use "-m +CISCO-RHINO-MIB" to indicate that we want the tool to load not only the default set of mibs, but the CISCO-RHINO-MIB as well (the leading '+' plus means "also").
% snmptranslate -m +CISCO-RHINO-MIB -IR -On ciscoLS1010ChassisFanLed Cannot find module (CISCO-SMI): At line 31 in $HOME/.snmp/mibs/CISCO-RHINO-MIB.my Unlinked OID in CISCO-RHINO-MIB: ciscoLS1010ChassisMIB ::= { workgroup 11 } Cannot adopt OID in CISCO-RHINO-MIB: ciscoAtmSwitchInvalidCellHeader ::= { ciscoAtmSwitchInvalidCellHeaderEntry 2 } ... rest of output truncated ...</i>
Wait a minute... What the heck is all that stuff? Errors! Well, the first line is the most important and it's telling us that we're missing the CISCO-SMI MIB as well. So, if we go download that MIB file and place it in our $HOME/.snmp/mibs directory as well the command should suddenly work:
% snmptranslate -m +CISCO-RHINO-MIB -IR -On ciscoLS1010ChassisFanLed .1.3.6.1.4.1.9.5.11.1.1.12
Success!
One last comment: You can also force loading of a given MIB and its node in one fell swoop (and this method is the one most highly recommended by Niels Baggesen, one of our primary core developers):
% snmptranslate -On CISCO-RHINO-MIB::ciscoLS1010ChassisFanLed .1.3.6.1.4.1.9.5.11.1.1.12
So, there you have it. A complete example for how to get your own insert-spiffy-mib-here loaded into the net-snmp tools.
Yes, but how do I make it happen all the time?
Good question. And of course, we have multiple options for you. We support a number of ways of doing this.
- First, you can put the following lines in a snmp.conf file. This file can be placed in the system-wide configuration location (EG, /usr/local/share/snmp.conf) or in a personal file (EG, $HOME/.snmp/snmp.conf). The system-wide configuration file location will depend on how Net-SNMP was built on your system. Run net-snmp-config --snmpconfpath to display the list of paths.
mibs +CISCO-RHINO-MIB mibs +SOME-OTHER-SPIFFY-MIB
- You can also use the MIBS environment variable to specify things (example assumes a /bin/sh style shell):
MIBS=+CISCO-RHINO-MIB:SOME-OTHER-SPIFFY-MIB export MIBS
- For the brave you can load all MIB files in your system-wide location - This can save you time, but may give you errors as shown below.
To snmp.conf:
mibs +ALL
And to run it:
% snmpwalk -v2c -c public 192.168.1.100 Warning: Module MAU-MIB was in /usr/share/snmp/mibs//DOT3-MAU-MIB.txt now is /usr/share/snmp/mibs//RFC2668-MIB.txt Warning: Module DISMAN-EVENT-MIB was in /usr/share/snmp/mibs//EVENT-MIB.txt now is /usr/share/snmp/mibs//DISMAN-EVENT-MIB.txt Warning: Module P-BRIDGE-MIB was in /usr/share/snmp/mibs//P-BRIDGE-MIB.txt now is /usr/share/snmp/mibs//P-BRIDGE.txt
Although, with enabling so many SNMP MIBs at once comes a consequence as seen above. Pipe the stderr to null for cleaner output.
% snmpwalk -v2c -c public 192.168.1.100 2>/dev/null SNMPv2-MIB::sysDescr.0 = STRING: Linux server1 2.4.34-pre2 #170 Fri Sep 15 20:10:21 CEST 2006 mips SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-TC::linux DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (706980) 1:57:49.80
Ethereal/Wireshark Notes
Note to Wireshark users (previously known as Ethereal):
You must use one of these methods in this section for Wireshark since it won't support the -m and -M options discussed previously.
See Also
Please note the following sections of the FAQ as well:
- How do I add a MIB
- How do I add a MIB to the tools?
- I'm getting answers, but they're all numbers. Why?
- ... (Read the entire FAQ Please!)
- Writing your own MIBs
Tutorial Sections
About the SNMP Protocol
These tutorial links talk about SNMP generically and how the protocol itself works. They are good introductory reading material and the concepts are important to understand before diving into the later tutorials about Net-SNMP itself.
- How SNMP Works: About the protocol itself (GETs, GETNEXTs, etc)
- What data is in SNMP: All about SNMP Management Information Bases (MIBs)
- Securing SNMP: How to use the SNMP protocol securely
Net-SNMP Command Line Applications
These tutorial pages discuss the command line tools provided in the Net-SNMP suite of tools. Nearly all the example commands in these tutorials works if you try it yourself, as they're all examples that talk to our online Net-SNMP test agent. Given them a shot!
- snmptranslate: learning about the MIB tree.
- snmpget: retrieving data from a host.
- snmpgetnext: retrieving unknown indexed data.
- snmpwalk: retrieving lots of data at once!
- snmptable: displaying a table.
- snmpset: peforming write operations.
- snmpbulkget: communicates with a network entity using SNMP GETBULK request
- snmpbulkwalk: retrieve a sub-tree of management values using SNMP GETBULK requests.
- snmptrap: Sending and receiving traps, and acting upon them.
- Traps/informs with SNMPv3/USM: Sending and receiving SNMPv3/USM TRAPs and INFORMs
- Sending Traps/Informs via AgentX: Sending notifications from the command line through snmpd
- Common command line options:
- Using and loading MIBS
- SNMPv3/USM Options
- Using SNMPv3 over TLS and DTLS
- Customized Output Formats
- Writing mib2c config files
Application Configuration
All of our applications support configuration to allow you to customize how they behave.
Net-SNMP Daemons
Net-SNMP comes with two long-running daemons: a SNMP agent (snmpd) for responding to management requests and a notification receiver (snmptrapd) for receiving SNMP notifications.
- SNMP Agent (snmpd) Configuration
- SNMP Notification Receiver (snmptrapd)
- Agent Monitoring
Coding Tutorials
Net-SNMP comes with a highly flexible and extensible API. The API allows you to create your own commands, add extensions to the agent to support your own MIBs and perform specialized processing of notifications.
- Client / Manager Coding Tutorials
- Agent Coding Tutorials
- The Agent Architecture page might be worth reading before or after the agent coding tutorials, and describes how the Agent Helpers work under the hood.
- Writing a mib module to serve information described by an SNMP MIB, and how to compile it into the net-snmp snmpd agent.
- Writing a Dynamically Loadable Object that can be loaded into the SNMP agent.
- Writing a Subagent that can be run to attach to the snmpd master agent.
- Writing a perl plugin to extend the agent using the NetSNMP::agent module.
- Writing shell scripts to extend the agent
- Using mib2c to help write an agent code template for you
- Header files and autoconf
Debugging SNMP Applications and Agents
All our tools and applications have extensive debugging output. These tutorials talk about how the debugging system works and how you can add your own debugging statements to you code:
- Debugging output printed using the -D command line option
- Using -Ddump to display packet breakdowns
- Debugging using GDB
Operating System Specific Tutorials
- Building With Visual Studio 2005 Express
- Building Net-SNMP 64-bit with Visual C++ 2010 Express
- Net-Snmp on Ubuntu
- Net-SNMP and lm-sensors on Ubuntu 10.04
- Net-SNMP for windows: