现在的位置: 首页 > 综合 > 正文

snmp-snmptranslate and loading mibs

2019年05月29日 ⁄ 综合 ⁄ 共 4294字 ⁄ 字号 评论关闭

Using local MIBs

The net-snmp tools can translate numeric object identifies(OIDs) into textual object identifiers using the MIB descriptionfiles. The net-snmp toolkit provides a few of the standardMIBs, but certainly doesn't contain all the MIBs known to man.

First off, you should know about the paths that the tools loadMIBs from. By default, it loads things from the following listof directories:

  1. $HOME/.snmp/mibs
  2. /usr/local/share/snmp/mibs

Note that many distributions change the default paths. To find outwhich 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 calledCISCO-RHINO-MIBthat you want parsed (it really exists, and I particularly likedthe name so I'm using it
in the tutorial). Place the file inone of the above two directories. If you pulled it from anotherfile (like an RFC), make sure it doesn't contain anythingnon-MIB related (like the text leading up to it, and the pageseparators). The very first line in the
file should begin withsomething like "CISCO-RHINO-MIB DEFINITIONS ::= BEGIN", and thevery last line of the file should be "END"

Now, pick a node in the file that you want to translate thatcurrently isn't being translated. From the CISCO-RHINO-MIB, I'llpick the
ciscoLS1010ChassisFanLed node.

First, lets verify that our handy snmptranslate command(discussed
snmptranslate
) doesn'tyet 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 itin. So, I'm going to place the file in $HOME/.snmp/mibs.

Now, lets use the -m flag to snmptranslate to tell it toload that mib. We'll use
"-m +CISCO-RHINO-MIB" to indicate thatwe want the tool to load not only the default set of mibs, but theCISCO-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'remissing the CISCO-SMI MIB as well. So, if we godownload
that MIB file
and place it in our $HOME/.snmp/mibs directory aswell 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 andits node in one fell swoop (and this method is the one most highlyrecommended by Niels Baggesen, one of our primary coredevelopers):

 % 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 yourown 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 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 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

抱歉!评论已关闭.