Tuesday, November 1, 2011

Turn Outlets On & Off via SNMP


APC makes a line of switched rack PDUs that is very popular amongst home network labs.  These PDUs have the ability to selectively turn individual outlets on and off.  The units also have a display on them that shows the current AMP usage flowing though the PDU.
The PDU has a RJ-45 network interface that allows you to connect to the web interface where you can configure the unit as well as interact with it to turn outlets on and off.
While it is possible to do it from the web interface, I prefer to turn the outlets on and off via a snmp script.
You need some kind of SNMP client capable of sending snmpset commands
  • Net-SNMP is a good client, they have a version for Windows so I’m down with that one
If you are installing on Windows you will also need to install the following items:
So after you get all that setup, you need to configure your PDU to allow SNMP ( I’m using SNMP v 2c in tis example… ).  Then make a batch file and add this stuff, obviously change it to cd where every you have snmpset is installed.
@echo off
cd C:\tools\usr\bin
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.1 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.2 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.3 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.4 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.5 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.6 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.7 integer 1
snmpset -v 2c -c <COMMUNITYSTRING> <PDU-IPADDRESS> 1.3.6.1.4.1.318.1.1.4.4.2.1.3.8 integer 1
exit

This script above will shutoff the ports on the 8 port pdu, if you have the 16 port PDU instead just double all those statements and change the last number in the OID to the port numbers.  If you want to turn off the ports instead change the integer to 2.  Now you can turn your lab on or off with the click of a file instead of logging on and all that other who-ha to get them on.  I have have added it to a lab startup script that launches that script and then loads some other stuff after a while after things have booted up.

Try it out, it makes a fun sound… click click boom !!!! OK no boom but it’s pretty cool.