Zabbix Network Monitoring(Second Edition)
上QQ阅读APP看书,第一时间看更新

Adding new MIBs

One way to discover usable OIDs is to redirect the full SNMP tree output to a file, find out what interesting and useful information the device exposes, and determine what the OIDs are from that. It's all good as long as the MIB files shipped with Net-SNMP provide the required descriptors, but SNMP MIBs are extensible—anybody can add new information, and many vendors do. In such a case, your file might be filled with lines like this:

SNMPv2-SMI::enterprises.318.1.1.1.1.2.3.0 = STRING: "QS0547120198"

That's quite cryptic. While the output is in the short, textual form, part of it is numeric. This means that there is no MIB definition for this part of the SNMP tree. Enterprise number 318 is assigned to APC and, luckily, APC offers an MIB for download from their site, so it can be added to Net-SNMP configured MIBs. But how?

Tip

Getting SNMP MIBs isn't always easy. A certain large printer manufacturer representative claimed that they do not provide SNMP MIBs, and everybody should use their proprietary printer-management application. Most manufacturers do provide MIBs, though, and in some cases, freely accessible MIB collection sites can help better than official vendor sites.

After downloading a new MIB, you have to place it in a location where Net-SNMP will search for MIB files and configure them as well. Net-SNMP searches for MIBs in two locations: .snmp/mibs in the user's home directory and /usr/share/snmp/mibs; which one you use is your decision. If you want something for the current user only, or don't have access to the /usr directory, you can use .snmp/mibs; otherwise, use /usr/share/snmp/mibs. Whichever you choose, that's not enough—you also have to instruct tools to include this MIB.

Note

While Zabbix server uses the same directory to look for MIBs, specifying MIBs to be used is only required for the Net-SNMP tools—Zabbix server loads all MIBs found.

The first method is to pass MIB names directly to the called command. But hey, we don't know the MIB name yet. To find out what a particular name in some file is, open the file in a text editor and look for MIB DEFINITIONS ::= BEGIN near the beginning of the file. The string before this text will be the MIB name we are looking for. Here's an example:

PowerNet-MIB DEFINITIONS ::= BEGIN

So, APC has chosen to name its MIB PowerNet-MIB. Armed with this knowledge, we can instruct any command to include this file:

$ snmpget -m +PowerNet-MIB -v 1 -c public <IP address> SNMPv2-SMI::enterprises.318.1.1.1.1.2.3.0
PowerNet-MIB::upsAdvIdentSerialNumber.0 = STRING: "QS0547120198"

Excellent; snmpget included the correct MIB and obtained the full textual string, which confirms our suspicion that this might be a serial number. You can now use the same flag for snmpwalk and obtain a file with much better value names. Quite often, you will be able to search such a file for interesting strings such as serial number and find the correct OID.

Tip

The + sign instructs us to include the specified MIBs in addition to otherwise configured ones. If you omit the +, the MIB list will be replaced with the one you specified.

Feel free to look at the MIB files in the /usr/share/snmp/mibs directory. As you can see, most files here have their filename the same as their MIB name without the extension, which is not required. Actually, the filename has nothing to do with the MIB name; thus, sometimes, you might have to resort to tools such as grep to find out which file contains which MIB.

While passing individual MIB names on the command line is nice for a quick one-time query, it gets very tedious once you have to perform these actions more often and the MIB list grows. There's another method, somewhat more durable—the MIB's environment variable. In this case, the variable could be set like this:

$ export MIBS=+PowerNet-MIB

In the current shell, individual commands do not need the MIB names passed to them anymore. All the MIBs specified in the variable will be included upon every invocation.

Of course, that's also not that permanent. While you can specify this variable in profile scripts, it can get tedious to manage for all the users on a machine. This is where a third method comes in: configuration files.

Again, you can use per-user configuration files, located in .snmp/snmp.conf in their home directories, or you can use the global /etc/snmp/snmp.conf file.

Tip

The location of the global configuration file and MIB directory can be different if you have compiled Net-SNMP from source. They might reside in /usr/local.

The syntax to add MIBs is similar to the one used in the environment variable—you only have to prefix each line with mibs, like so:

mibs +PowerNet-MIB

If you want to specify multiple MIB names in any of these locations, you have to separate them with a colon. Let's say you also need a generic UPS MIB; in that case, the MIB name string would be as follows:

+PowerNet-MIB:UPS-MIB

Tip

In some Net-SNMP versions, lines in configuration files might be silently cut at 1024 characters, including newline characters. You can specify multiple mibs lines to get around this limitation.

And if you feel lazy, you can make Net-SNMP include all the MIB files located in those directories by setting mibs to ALL—this works in all three locations. Beware that this might impact performance and also lead to some problems if some parts are declared in multiple locations, including warnings from Net-SNMP tools and incorrect definitions being used.

Note

Zabbix server always loads all available MIBs. When a new MIB is added, Zabbix server must be restarted to pick it up.