In Part 1, I summarized the basic concepts of SNMP and defined the terms and acronyms used in this post. Now, I will show how to use SNMP to monitor actual devices. As an example, I will monitor an enterprise-grade uninterruptible power supply (UPS) and power distribution unit (PDUs) from Tripp-Lite. These devices have an SNMPWEBCARD installed to support communication over Ethernet.
Command-line tools for SNMP communication should be available for any Linux distribution (or any other UNIX-derived OS). Documentation for the basic SNMP tools is available online. The challenge with SNMP is figuring out what parameters are supported by a particular device. Most devices support a set of standard OIDs that return basic information such as device name, uptime, etc.
Step 1: Configure device for SNMP
First, configure the device to respond to SNMP queries. This process varies for different devices and manufacturers, and may involve an old-school serial port connection. Once you get into the device, configure its network interface and verify that it responds to pings. The SNMP service must be enabled, and often you must specifically enable each version of SNMP (v1, v2c, and/or v3). You will also need to set a “community name” for version 1 and 2c, or the user ID and password for version 3. The default community name is often public, Public, or PUBLIC. Note that devices can also be controlled by SNMP commands. I strongly suggest disabling the versions of SNMP that you are not using, and enabling “read only” access. For monitoring, I usually enable only version 2c.
Step 2 (optional): Find an MIB for the device
If you want to read SNMP objects that are specific to a certain device, such as the run-time available on a UPS battery, you should check if the manufacturer offers their own MIB. This file is often available from their support web site, or from web sites that collect MIB information such as MIBsearch or MIBdepot.com. Note that an MIB is not strictly necessary to use SNMP; it just helps you read object IDs as descriptive text strings instead of numbers.
On Linux, copy the MIB file(s) to /usr/share/snmp/mibs and set the permissions as follows:
-rw-r--r--. 1 root root 106K Apr 14 12:01 TRIPPLITE-MIB.txt -rw-r--r--. 1 root root 71K Apr 14 12:01 UPS-MIB.txt
Step 3: Use snmpwalk to find object IDs
The snmpwalk tool can show you some or all of the OIDs that a device supports. To dump all of the objects in the Tripp-Lite MIB file (lots of output), run:
snmpwalk -v2c -c tripplite pdu-01 TRIPPLITE-MIB::tripplite
For generic UPS objects:
snmpwalk -v2c -c tripplite pdu-01 UPS-MIB::upsMIB
This output is not too long:
UPS-MIB::upsIdentManufacturer.0 = STRING: TRIPP LITE UPS-MIB::upsIdentModel.0 = STRING: PDUMNV20 UPS-MIB::upsIdentUPSSoftwareVersion.0 = STRING: 6926160C UPS-MIB::upsIdentAgentSoftwareVersion.0 = STRING: 12.06.0061 UPS-MIB::upsIdentName.0 = STRING: Device 1 UPS-MIB::upsIdentAttachedDevices.0 = STRING: ,,,,,,,,,,,,,,,,,,,,,,, UPS-MIB::upsInputNumLines.0 = INTEGER: 1 UPS-MIB::upsInputLineIndex.1 = INTEGER: 1 UPS-MIB::upsInputFrequency.1 = INTEGER: 5990 0.1 Hertz UPS-MIB::upsInputVoltage.1 = INTEGER: 1171 RMS Volts UPS-MIB::upsOutputSource.0 = INTEGER: normal(3) UPS-MIB::upsOutputNumLines.0 = INTEGER: 1 UPS-MIB::upsOutputLineIndex.1 = INTEGER: 1 UPS-MIB::upsOutputCurrent.1 = INTEGER: 60 0.1 RMS Amp UPS-MIB::upsAlarmsPresent.0 = INTEGER: 1 UPS-MIB::upsAlarmId.3 = INTEGER: 3 UPS-MIB::upsAlarmDescr.3 = OID: SNMPv2-SMI::enterprises.8126.96.36.199.3.4 UPS-MIB::upsAlarmTime.3 = Timeticks: (7100) 0:01:11.00
Step 4: Use snmpget to access a specific OID
Now that we know what is available, we can monitor specific items with the snmpget tool. Let’s check the total output current from the PDU, which will help us avoid overloading the circuit that feeds the PDU.
snmpget -v2c -c tripplite pdu-01 UPS-MIB::upsOutputCurrent.1
UPS-MIB::upsOutputCurrent.1 = INTEGER: 50 0.1 RMS Amp
The output is a little tricky. Note that the units are “0.1 RMS Amp.” The output is 50 tenths of an amp, or 5.0 amps-well below the capacity of the 20A breaker on this circuit.
Now, let’s look at the UPS. Running snmpwalk on the UPS will reveal a few parameters that are not present on the PDU, such as:
UPS-MIB::upsBatteryStatus.0 = INTEGER: batteryNormal(2) UPS-MIB::upsEstimatedMinutesRemaining.0 = INTEGER: 15 minutes UPS-MIB::upsEstimatedChargeRemaining.0 = INTEGER: 100 percent UPS-MIB::upsBatteryVoltage.0 = INTEGER: 546 0.1 Volt DC UPS-MIB::upsBatteryTemperature.0 = INTEGER: 390 degrees Centigrade
We can monitor the remaining battery run time:
snmpget -v2c -c tripplite ups-01 UPS-MIB::upsEstimatedMinutesRemaining.0
UPS-MIB::upsEstimatedMinutesRemaining.0 = INTEGER: 15 minutes
Wouldn’t it be great if we could somehow monitor these parameters automatically, and get an alert when the current draw gets too high, or the power goes out? In my next post, I’ll cover how to integrate SNMP with the Nagios monitoring framework.