SNMP Tutorial – APC PDUs

I’ve been meaning to re-write an internal tool we I use at work to manage our APC PDU’s. Much to my surprise, there seemed to be lack of good SNMP resources including how to install MIBs and determine the OID’s I needed.

First we must install the necessary packages. I’ll be using debian squeeze so this may or may not work for you! This tutorial assumes you’ve got a APC pdu setup and SNMP configured to public community set to read and private community set to write+.

Install snmp

sudo apt-get install snmp

Install MIBs – Due to licensing reasons in Squeeze, the MIBs need to be installed separately.

sudo apt-get install libsnmp-base

sudo apt-get install snmp-mibs-downloader

Edit /etc/snmp/snmp.conf and comment out the line starting with 'mibs :'

Next ensure the MIBs installed properly. You should be able to run the following SNMPwalk.

snmpwalk -v 1 -c public 10.1.0.100

With the MIB’s installed the beginning of each line should be pre-fixed with SNMPv2-MIB.


SNMPv2-MIB::sysDescr.0 = STRING: APC Web/SNMP Management Card (MB:v3.8.6 PF:v3.5.8 PN:apc_hw02_aos_358.bin AF1:v3.5.7 AN1:apc_hw02_rpdu_357.bin MN:AP7930 HR:B2 SN: ZA0822009513 MD:05/30/2008)
SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.318.1.3.4.5
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (254515010) 29 days, 10:59:10.10
SNMPv2-MIB::sysContact.0 = STRING: ISI
SNMPv2-MIB::sysName.0 = STRING: pdu1.domain.com
SNMPv2-MIB::sysLocation.0 = STRING: My Fancy PDU

Much like IP space, OID’s are registered via IANA as a private “Enterprise” number. These numbers are used, among other things, for defining private SNMP MIBs. These OID’s will always begin with 1.3.6.1.4.1. Memorize this or all your friends will make fun of you!

To determine a devices OID run the following:

snmpwalk -v 1 -c public 10.1.0.100

Within the output you will see a line containing text such as “SNMPv2-SMI::enterprises”

SNMPv2-MIB::sysObjectID.0 = OID: SNMPv2-SMI::enterprises.318.1.3.4.5

With the MIBs installed, 1.3.6.1.4.1 is translated into “enterprises”, followed by your Vendors assigned number. In this case, “318” is registered to APC.

If you can’t remember the number you can also run the following to get the same output.

snmpwalk -v 1 -c public 10.1.0.100 enterprises

Now while this is all ponies and sunshine, snmpwalk’n still spits out a bunch of stuff that really isn’t helpful. We still need to install the APC vendor specific MIB. You can grab a copy of the MIB’s on APC’s download site or on my github page.
git://github.com/joshuatobin/dotfiles.git

In order to active the mib, grep for DEFINITION:

# grep DEFINITION .snmp/mibs/powernet403.mib
PowerNet-MIB DEFINITIONS ::= BEGIN

We’re almost done, next activate the Definition “PowerNet-MIB” by adding the following line to .snmp/snmp.conf

mibs PowerNet-MIB

Now when we run the the SNMPwalk command the output looks a bit different, with verbose descriptions of the properties available. (Note that I’m tacking on .318, the APC’s assigned OID.)

# snmpwalk -v 1 -c public 10.1.9.104 enterprises.318
PowerNet-MIB::sPDUIdentHardwareRev.0 = STRING: "B2"
PowerNet-MIB::sPDUIdentFirmwareRev.0 = STRING: "v3.5.7"
PowerNet-MIB::sPDUIdentDateOfManufacture.0 = STRING: "05/30/2008"
PowerNet-MIB::sPDUIdentModelNumber.0 = STRING: "AP7930"
...
...
...
PowerNet-MIB::sPDUOutletCtl.1 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.2 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.3 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.4 = INTEGER: outletOn(1)
PowerNet-MIB::sPDUOutletCtl.5 = INTEGER: outletOn(1)
....
....

Once all the MIBs are in place, walking the device you should be able to determine which each of the OIDs do. If you’re unsure you can use snmptranslate (see below) to describe what each OID is cabable of.

A quick walk of the device shows a property called sPDUOutletCtl followed by a port number.
PowerNet-MIB::sPDUOutletCtl.1

Next get a confirmation and descriptions= of the options that can be passed to the object:
snmptranslate -Td PowerNet-MIB::sPDUOutletCtl.1

A quick glance shows that passing a value of (1) will turn the port on, (2) turn the port off, and (3) reboot.

Lets power off port 22 using the snmpset command:

# snmpset -v 1 -c private 10.1.0.100 PowerNet-MIB::sPDUOutletCtl.22 i 2

The command above is quite simple. Its using the “community group” set to private. Basically an auth group that has write privileges. The MIB DEFINITION and the property and lastly the “i” to specify an integer type of “2”.

And turning the port back on, passing it the value of “1”.

# snmpset -v 1 -c private 10.1.0.100 PowerNet-MIB::sPDUOutletCtl.22 i 1

Lastly there is one more tool that is super helpful, snmptranslate.

Sometimes the MIB descriptions can be a bit vague. Use snmptranslate to get a man page:
# snmptranslate -Td PowerNet-MIB::sPDUOutletCtl.1

PowerNet-MIB::sPDUOutletCtl.1
sPDUOutletCtl OBJECT-TYPE
— FROM PowerNet-MIB
SYNTAX INTEGER {outletOn(1), outletOff(2), outletReboot(3), outletUnknown(4), outletOnWithDelay(5), outletOffWithDelay(6), outletRebootWithDelay(7)}
MAX-ACCESS read-write
STATUS mandatory
DESCRIPTION “Getting this variable will return the outlet state. If
the outlet is on, the outletOn (1) value will be returned.
If the outlet is off, the outletOff (2) value will be
returned.



Its also sometimes helpful to translate a MIB to an OID:
$ snmptranslate -On PowerNet-MIB::sPDUOutletCtl.1
.1.3.6.1.4.1.318.1.1.4.4.2.1.3.1

About Joshua Tobin

I'm a Systems Engineer living and working in San Francisco for Linden Lab. I love cooking, traveling, python, chicken wings and New York pizza.
This entry was posted in Linux, Python and tagged , , . Bookmark the permalink.

12 Responses to SNMP Tutorial – APC PDUs

  1. r3d91ll says:

    thanks for the this short tutorial…it really set me on the right track

  2. g$ says:

    much thanks!

  3. Bill says:

    Hi Josha,
    I attempted your snmp tutorial on ubuntu 11.04. Everything worked as expected right down to “ponies and sunshine”. I commented out the entry in /etc/snmp/snmp.conf. Downloaded powernet403.mib into ~/.snmp/mibs. Added “mibs PowerNet-MIB” to ~/.snmp/snmp.conf. Restarted the daemon.
    I know that the daemon is reading ~./snmp/snmp.conf because the output changes when I comment out/in the entry. However, I never see any output from ‘snmpwalk -v1 -c public localhost enterprises’ for “PowerNet”.
    I started the daemon with a ‘-D’ but didn’t see any output concerning powernet in the syslog file. I know I should upgrade my OS but I hate the new user interface. Would you have any other suggestions?
    Thanks.

    • Joshua Tobin says:

      Bill – Its possible your device is newer than whats available in that MIB? I’d suggest grabbing the latest version from APC. Also make sure the firmware on your device is up to date as well. You shouldn’t need to update your OS in order for this to work. Hope that helps.

      -j

    • elpedrosk says:

      Not sure if I am understanding the problem correctly. But I assume a situation that is you want to “snmpwalk” a device nothing works.

      First you probably should check where your mibs is:
      Run:
      pedro@rohace$ net-snmp-config –snmpconfpath
      I get:
      /etc/snmp:/usr/share/snmp:/usr/lib/snmp:/home/pedro/.snmp:/var/lib/snmp
      So notice here that I have a path ” /home/pedro/.snmp”
      In my case I created “.snmp” directory under my home and copied here my “powernet410.mib” (which is a newer MIB I downloaded from APC website).
      I also have a “snmp.conf”in this directory
      if you list the directory:

      pedro@rohace:~/.snmp$ ls -la
      total 2308
      drwxr-xr-x 3 pedro pedro 4096 Apr 2 18:44 .
      drwxr-xr-x 96 pedro pedro 36864 Apr 2 17:00 ..
      drwxr-xr-x 2 pedro pedro 4096 Apr 1 00:31 mibs
      -rw-r–r– 1 pedro pedro 2302475 Mar 31 23:15 powernet410.mib
      -rw-r–r– 1 pedro pedro 20 Apr 2 18:44 snmp.conf

      my snmp.conf has this single line in here
      mibs powernet410.mib

      NOTE: I have the same content in the subdirectory mibs. I noticed that at some boots the path point to: /home/pedro/.snmp/mibs

      so let say I want to know the temperature from my environmental AP9612, AP9619 cards and run for either of the OID I should get:
      The olderr OID (this works only for the AP9612 not for AP9619)

      pedro@rohace:~/.snmp$snmpget -v1 -c public 10.0.0.33 .1.3.6.1.4.1.318.1.1.2.1.1.0
      you should get something like this, where 23 is temperature 23C
      SNMPv2-SMI::enterprises.318.1.1.2.1.1.0 = Gauge32: 23

      or
      pedro@rohace:~/.snmp$ snmpget -v1 -c public 10.0.0.33 .1.3.6.1.4.1.318.1.1.10.1.3.3.1.4.1
      Where 23 is the temperature in deg C
      SNMPv2-SMI::enterprises.318.1.1.10.1.3.3.1.4.1 = INTEGER: 23

      Hope this helps

      ed

  4. You are seriously the man! This helped so much. I couldn’t really find any good documentation on what MIBs were supported with our specific PDUs. This let me pull every single MIB the PDU offers and then look up what they were with the snmptranslate. Now I can assign universal device pollers to these nodes in SolarWinds and be able to monitor them through it. Yay! Many thanks

  5. Igor says:

    Thanks for such detailed explanation. It was very, very helpfull !!!

  6. Pingback: Monitoring APC UPS in Nagios with SNMP and Custom Checks | syshead

  7. Anyone have a CENTOS version of this?

  8. Naama says:

    Thank you so so much. I was completely lost until I found this tutorial.

  9. cameron says:

    Excellent info! Thanks 🙂

  10. Tim Tester says:

    Helped me, thanks..

Leave a reply to Dallan Wagner Cancel reply