Class: Pdu43V6145

Inherits:
Object
  • Object
show all
Defined in:
rlib/pdu43V6145.rb

Overview

Queries for IBM 43V6145 PDU, which some queries need to be done through XML query. Some data is available using SNMP.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Pdu43V6145) initialize(pdu_hostname, auth_key, mode = :power)

Create a Pdu43V6145 class

Parameters:

  • pdu_hostname (String)

    The pdu we will be querying

  • auth_key (String)

    The pdu's web password



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'rlib/pdu43V6145.rb', line 16

def initialize(pdu_hostname, auth_key, mode = :power)
  wb = WebBrowser.new(pdu_hostname)

  begin
  #Login to PDU
    wb.http_session(80) do 
      wb.post_page('login.htm', {'User' => 'ADMIN', 'Password' => auth_key, 'B1' => 'Login'})
    end
    #Fetch the XML data from the PDU
    wb.http_session(80) do
      if mode == :power
        @env = wb.get_page('ibmframe_4.xml')
      else #Then temperature
        @env = wb.get_page('env_status.xml')
      end
    end
    @xml = Nokogiri::XML(@env)

    wb.http_session(80) do 
      wb.get_page('logout_wait.htm')
    end
  rescue Exception => error
    $stderr.puts "Pdu43V6145.new('#{pdu_hostname}', key) error => #{error}"
  end
end

Class Method Details

+ (Float) current_usage_snmp(hostname, community)

Class level function to retrieve the current power being used via SNMP, rather than A web XML request

Parameters:

  • hostname (String)

    The pdu's hostname

  • community (String)

    The pdu's snmp read community string.

Returns:

  • (Float)

    Power being used in KW



46
47
48
49
50
51
52
53
# File 'rlib/pdu43V6145.rb', line 46

def self.current_usage_snmp(hostname, community)
  #SNMPv2-SMI::enterprises
  power_usage_amps = 0.0
  SNMP::Manager.snmp_walk(hostname, community, ["1.3.6.1.4.1.2.6.223.8.2.2.1.7"]) do |k,v| #Total power used, since last PDU reset
    power_usage_amps += v.to_f #Should be just the twelve responses
  end
  return (power_usage_amps * 0.230)/1000.0 #In VA/1000 Apparent Power KW
end

Instance Method Details

- (Float) accumulated_power_used

Power used since the PDU was last reset (generally this is since the power was first turned on)

Returns:

  • (Float)

    KWHours



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'rlib/pdu43V6145.rb', line 77

def accumulated_power_used
  power_total = 0.0

  begin
    (1..3).each do |ipdp|
      (1..4).each do |eg|
        power_reading = @xml.xpath("//XMLdata//info8_IPDP#{ipdp}_eg#{eg}")[0].content.to_f
        #$stderr.puts "Power Reading Phase #{ipdp} Socket #{eg} Energy #{power_reading}KJ"
        power_total += power_reading
      end
    end
    return power_total/3600.0
    
  rescue #If something is wrong with the data
    return 0.0
  end
end

- (Float) current_power_usage

retrieve the current power usage (point in time)

Returns:

  • (Float)

    Power being used in KW



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'rlib/pdu43V6145.rb', line 57

def current_power_usage
  begin
    power_being_used = 0.0

    (1..3).each do |ipdp|
      (1..4).each do |ap|
        power_reading = @xml.xpath("//XMLdata//info8_IPDP#{ipdp}_ap#{ap}")[0].content.to_f
        power_being_used += power_reading #in Watts
      end
    end

    return power_being_used/1000.0 #in KW

  rescue #If something is wrong with the data
    return 0.0
  end
end

- (Float) current_temperature

retrieve the current temperature from the sensor attached to the PDU (assuming there is one)

Returns:

  • (Float)

    Temperature in C, though the PDU can be told to use F.



97
98
99
100
101
102
103
# File 'rlib/pdu43V6145.rb', line 97

def current_temperature
  begin
    return @xml.xpath("//XMLdata//ibmsys_envstat_tempature")[0].content.to_f  
  rescue #If something is wrong with the data
    return 0.0
  end
end