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