Class: ApcSnmp
- Inherits:
-
Object
- Object
- ApcSnmp
- Defined in:
- lib/apc.rb
Constant Summary collapse
- MIBDIR =
File.dirname(__FILE__) + "/mibs"
Instance Method Summary collapse
-
#getFirmwareVersion ⇒ Object
Get the firmware revision of the PDU.
-
#getLoadAmps ⇒ Object
Get total Amp load on PDU.
-
#getLoadDetail(phase) ⇒ Object
Get the load on a phase return load, max load and warning load.
-
#getLocation ⇒ Object
Get the location of the PDU.
-
#getModelNumber ⇒ Object
Get the model number of a PDU.
-
#getNumPhases ⇒ Object
Get number of phases on this PDU.
-
#getOutletName(outlet = 0) ⇒ Object
Get the name of a particular outlet or of all outlets if not specified.
-
#getOutletStatus(outlet = 0) ⇒ Object
Get the status of a particular outlet or of all outlets if not specified.
-
#getPDUName ⇒ Object
Get the name of the PDU.
-
#getSerialNumber ⇒ Object
Get the serial number of a PDU.
-
#initialize(host, community = 'public', write_community = 'private') ⇒ ApcSnmp
constructor
A new instance of ApcSnmp.
-
#numOutlets ⇒ Object
Get the number of outlets from rPDUOutletDevNumCntrlOutlets.
-
#outletOff(outlet) ⇒ Object
Turn an outlet off.
-
#outletOn(outlet) ⇒ Object
Turn an outlet on.
-
#readValue(oid) ⇒ Object
Read a single OID or an array of OIDs over SNMP.
-
#setOutletName(outlet, name) ⇒ Object
Set the name of an outlet.
-
#setPDUName(name) ⇒ Object
Change the name of a PDU.
-
#writeValue(name, value) ⇒ Object
Write a single OID with a new value.
Constructor Details
#initialize(host, community = 'public', write_community = 'private') ⇒ ApcSnmp
Returns a new instance of ApcSnmp.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/apc.rb', line 14 def initialize (host, community='public', write_community='private') @mib = SNMP::MIB.new @mib.load_module("PowerNet-MIB", MIBDIR) @mib.load_module("RFC1213-MIB", MIBDIR) @manager = SNMP::Manager.new( :host => host, :version => :SNMPv1, :community => community, :write_community => write_community, :mib_dir => MIBDIR, :mib_modules => [ "PowerNet-MIB", "RFC1213-MIB" ]) end |
Instance Method Details
#getFirmwareVersion ⇒ Object
Get the firmware revision of the PDU
116 117 118 |
# File 'lib/apc.rb', line 116 def getFirmwareVersion () return readValue("sPDUIdentFirmwareRev.0") end |
#getLoadAmps ⇒ Object
Get total Amp load on PDU
121 122 123 |
# File 'lib/apc.rb', line 121 def getLoadAmps () return readValue("rPDULoadStatusLoad.1") end |
#getLoadDetail(phase) ⇒ Object
Get the load on a phase return load, max load and warning load
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/apc.rb', line 136 def getLoadDetail(phase) load = Hash.new loaddata = readValue(["rPDULoadStatusLoad.#{phase}", "rPDULoadPhaseConfigOverloadThreshold.#{phase}", "rPDULoadPhaseConfigNearOverloadThreshold.#{phase}"]) load['used'] = loaddata[0].to_i/10 # Is reported as 2.9amps being 29 load['max'] = loaddata[1] load['warn'] = loaddata[2] return load end |
#getLocation ⇒ Object
Get the location of the PDU
131 132 133 |
# File 'lib/apc.rb', line 131 def getLocation () return readValue("RFC1213-MIB::sysLocation.0") end |
#getModelNumber ⇒ Object
Get the model number of a PDU
111 112 113 |
# File 'lib/apc.rb', line 111 def getModelNumber () return readValue("rPDUIdentModelNumber.0") end |
#getNumPhases ⇒ Object
Get number of phases on this PDU
126 127 128 |
# File 'lib/apc.rb', line 126 def getNumPhases () return readValue("rPDULoadDevNumPhases.0") end |
#getOutletName(outlet = 0) ⇒ Object
Get the name of a particular outlet or of all outlets if not specified
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/apc.rb', line 73 def getOutletName (outlet=0) if outlet == 0 outletList = Array.new outlets = numOutlets() for i in 1..outlets do outletList.push("sPDUOutletName.#{i}") end return readValue(outletList) else begin return readValue("sPDUOutletName.#{outlet}") rescue NullValueException raise NonExistentPortException end end end |
#getOutletStatus(outlet = 0) ⇒ Object
Get the status of a particular outlet or of all outlets if not specified
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/apc.rb', line 55 def getOutletStatus (outlet=0) if outlet == 0 outletList = Array.new outlets = numOutlets() for i in 1..outlets do outletList.push("sPDUOutletCtl.#{i}") end return readValue(outletList) else begin return readValue("sPDUOutletCtl.#{outlet}") rescue NullValueException raise NonExistentPortException end end end |
#getPDUName ⇒ Object
Get the name of the PDU
96 97 98 |
# File 'lib/apc.rb', line 96 def getPDUName () return readValue("rPDUIdentName.0") end |
#getSerialNumber ⇒ Object
Get the serial number of a PDU
106 107 108 |
# File 'lib/apc.rb', line 106 def getSerialNumber () return readValue("rPDUIdentSerialNumber.0") end |
#numOutlets ⇒ Object
Get the number of outlets from rPDUOutletDevNumCntrlOutlets
50 51 52 |
# File 'lib/apc.rb', line 50 def numOutlets () return readValue("rPDUOutletDevNumCntrlOutlets.0").to_i end |
#outletOff(outlet) ⇒ Object
Turn an outlet off
148 149 150 |
# File 'lib/apc.rb', line 148 def outletOff (outlet) return writeValue("sPDUOutletCtl.#{outlet}", SNMP::Integer.new(2)) end |
#outletOn(outlet) ⇒ Object
Turn an outlet on
153 154 155 156 |
# File 'lib/apc.rb', line 153 def outletOn (outlet) puts "Sending 'On' to sPDUOutletCtl.#{outlet}" return writeValue("sPDUOutletCtl.#{outlet}", SNMP::Integer.new(1)) end |
#readValue(oid) ⇒ Object
Read a single OID or an array of OIDs over SNMP
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/apc.rb', line 27 def readValue (oid) response = @manager.get(oid) data = Array.new response.each_varbind do |varbind| data.push(varbind.value.to_s) end if data.length == 1 raise NullValueException if data[0] == 'Null' return data[0] else return data end end |
#setOutletName(outlet, name) ⇒ Object
Set the name of an outlet
91 92 93 |
# File 'lib/apc.rb', line 91 def setOutletName (outlet, name) writeValue("sPDUOutletName.#{outlet}", SNMP::OctetString.new(name)) end |
#setPDUName(name) ⇒ Object
Change the name of a PDU
101 102 103 |
# File 'lib/apc.rb', line 101 def setPDUName (name) return writeValue("rPDUIdentName.0", SNMP::OctetString.new(name)) end |
#writeValue(name, value) ⇒ Object
Write a single OID with a new value
42 43 44 45 46 47 |
# File 'lib/apc.rb', line 42 def writeValue (name, value) oid = @mib.oid(name) varbind = SNMP::VarBind.new(oid, value) puts varbind return @manager.set(varbind) end |