This one is neat – you can control those APC PDU Power Poles over the network via SNMP. This works for the APC Switched Rack Unit PDU, but it may work for others.

I use this on a PDU with Network Management Card AOS version v2.6.4 and Rack PDU APP v2.6.5, so of course this is not guaranteed for any other versions.

First, set up the PDU on the network. Then, you need to configure the SNMP write string. You do this by navigating the menu (default username password is apc/apc):
Control Console->Network->SNMP

Change one of the strings to Write+ and preferable change it from public/private to your own string. You can also limit access from certain hosts for extra security. I always keep the APC PDUs on a private network since the APC telnet/web interface is so insecure.

Once you have that set up, your PDU is read to accept SNMP commands from your script of choice. I use PHP, so my examples use PHP code.

The APC MIB which controls the status of the power ports is: .1.3.6.1.4.1.318.1.1.12.3.3.1.1.4., where is the power port you wish to control.

I created a function that controls the port, it is as follows:

In config.php:

// translates APC IDs into their IP addresses
$apcids = array(
"APC01" => "10.0.1.2",
"APC02" => "10.0.1.6",
"APC03" => "10.0.1.10",
"APC04" => "10.0.1.14",
"APC05" => "10.0.1.18",
"APC06" => "10.0.1.22",
);

// This APC MIB is incomplete - must add the port number of the PDU at the end
$apcportcontrolmib = ".1.3.6.1.4.1.318.1.1.12.3.3.1.1.4.";

// This is your SNMP Write+ String
$apcsnmp = "rwstring";

In functions.php:
//
// string function displayPowerStatus
// $apcid = ID of the APC unit as defined in config.php
// $apcport = Port of the outlet on the APC Switch
// returns STRING On, Off, Rebooting, or Error
function displayPowerStatus($apcid, $apcport) {
include('config.php');
$ip = $apcids[$apcid];
$mib = $apcportcontrolmib.$apcport;
$a = trim(snmpget($ip, $apcsnmp, $mib, 20000), "INTEGER: ");
switch ($a) {
case 1:
return "On";
case 2:
return "Off";
case 3:
return "Rebooting";
default:
return "Error";
}
}

// bool function manageAPCPort
// $apcid = ID of the APC unit as defined in config.php
// $apcport = Port of the outlet on the APC Switch
// $apcpass = APC Pass (SNMP Community String)
// $action {
// immediateOn (1),
// immediateOff (2),
// immediateReboot (3),
// delayedOn (4),
// delayedOff (5),
// delayedReboot (6),
// cancelPendingCommand (7)
// }
// returns TRUE or FALSE
function manageAPCPort($apcid, $apcport, $apcpass, $action) {
include('config.php');
$ip = $apcids[$apcid];
$mib = $apcportcontrolmib.$apcport;
$VERIFY = snmpset($ip, $apcpass, $mib, i, $action);
return $VERIFY;
}

Note that this code required the php snmpset function, which is not compiled into php by default. If you receive some error about snmpset or snmpget function not found, this is why.

4 comments
  1. Wow, beautiful. I was trying to write a system utilizing PHP w/ the SSH2 PECL package, but the APC SSH system was just so incredibly slow, and the fact that I could not for the life of me get the SSH2 functions to work with it that I had to look for a SNMP solution.

    The code examples you have above allowed me to write a web interface which unifies fifteen individual PDU’s into one system.

    Thank you!

  2. Wow, beautiful. I was trying to write a system utilizing PHP w/ the SSH2 PECL package, but the APC SSH system was just so incredibly slow, and the fact that I could not for the life of me get the SSH2 functions to work with it that I had to look for a SNMP solution.

    The code examples you have above allowed me to write a web interface which unifies fifteen individual PDU’s into one system.

    Thank you!

Comments are closed.

You May Also Like

Problem installing PECL PHP extensions while /tmp is secured

I recently tried to install a PHP PECL extension on a server…

Firewall Ports to Open Up For DNS Servers

Everyone knows that DNS servers use UDP port 53 for queries, right?…

Analysis of a hacked machine

If you are a system administrator, you should dread any time you…

Change your default CPAN mirror

Changing your cpan mirror. Although it seems like it would be easy…