drothlis/stb-tester — pull request #165 by abaharna (2014-05-23 17:23:10+00:00)
Title: stbt power: Support ATEN network-controlled PDU's

While ATEN PDU's have a web interface they also support SNMP, which is a
more direct and reliable way of controlling them. This commit implements
support for ATEN PDU's over SNMP in a new `aten()` function. It also
updates the regex to recognise the `aten` as a valid model. To query and
control the PDU, it makes use of the `snmpget` and `snmpset` commands
from Net-SNMP [1] (Fedora package: `net-snmp-utils`).

The relevant SNMP OID's were found using ATEN's MIB file v1.1.109 [2],
which applies to *all* ATEN PDU's:

outlet1Status enterprises.21317.1.3.2.2.2.2.2.0
outlet2Status enterprises.21317.1.3.2.2.2.2.3.0
outlet3Status enterprises.21317.1.3.2.2.2.2.4.0
... ...
outlet42Status enterprises.21317.1.3.2.2.2.2.44.0

Each outlet status is an integer that can take a value from 1-8. From
the MIB file:

Display and control outlet status. Can't set pending status.

Enumerations:
1 - off
2 - on
3 - pending
4 - reboot
5 - fault
6 - noauth
7 - not-support
8 - pop

When querying the outlet status, this implementation maps 1->OFF and
2->ON. It also maps 3->PENDING, because this is the status that is
returned in the first few seconds during a transition from OFF to ON,
and it seemed misleading to map it to either OFF or ON.

The Net-SNMP commands use SNMPv2c because it is faster than SNMPv1 and
unlike SNMPv3 it doesn't require authentication (which would also be
slower).

When `snmpget` or `snmpset` operate on an OID that is not known to the
device, they do not fail with non-zero status but instead print: "No
Such Object available on this agent at this OID". In stbt-power this
should only happen if (1) the device is not an ATEN PDU or (2) the
outlet was specified incorrectly (non-integer, less than 1, or greater
than the device's number of actual outlets).

Note that the SNMPv2 read & write community is hard-coded to
"administrator", which is the default on ATEN PDU's.

This was tested on an ATEN PE610G 8-outlet PDU and Net-SNMP v5.7.2.

[1] http://net-snmp.sourceforge.net/docs/man/
[2] http://www.aten.com/export.php?mid=20130906165112002&type=driver