Class: Rubyipmi::Freeipmi::Sensors

Inherits:
BaseCommand show all
Defined in:
lib/rubyipmi/freeipmi/commands/sensors.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#cmd, #lastcall, #max_retry_count, #options, #passfile, #result

Instance Method Summary collapse

Methods inherited from BaseCommand

#find_fix, #makecommand, #max_retry_count, #setpass, #validate_status

Methods inherited from BaseCommand

#dump_command, #find_fix, #locate_command, #makecommand, #removepass, #run, #runcmd, #setpass, #update, #validate_status

Constructor Details

#initialize(opts = ObservableHash.new) ⇒ Sensors

Returns a new instance of Sensors.



5
6
7
8
9
10
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 5

def initialize(opts = ObservableHash.new)
  super("ipmi-sensors", opts)
  @options["no-header-output"] = false
  @options["output-sensor-state"] = false
  @options["entity-sensor-names"] = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



60
61
62
63
64
65
66
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 60

def method_missing(method, *args, &block)
  if not list.has_key?(method.to_s)
    raise NoMethodError
  else
    list[method.to_s]
  end
end

Instance Method Details

#countObject



21
22
23
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 21

def count
  list.count
end

#fanlist(refreshdata = false) ⇒ Object

returns a hash of fan sensors where the key is fan name and value is the sensor



30
31
32
33
34
35
36
37
38
39
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 30

def fanlist(refreshdata=false)
  refresh if refreshdata
  flist = {}
  list.each do | name,sensor |
    if name =~ /.*fan.*/
      flist[name] = sensor
    end
  end
  return flist
end

#getsensorsObject



53
54
55
56
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 53

def getsensors
  value = runcmd
  return @result
end

#listObject



17
18
19
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 17

def list
  @sensors ||= parse(getsensors)
end

#namesObject



25
26
27
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 25

def names
  list.keys
end

#refreshObject



12
13
14
15
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 12

def refresh
  @sensors = nil
  list
end

#templist(refreshdata = false) ⇒ Object

returns a hash of sensors where each key is the name of the sensor and the value is the sensor



42
43
44
45
46
47
48
49
50
51
# File 'lib/rubyipmi/freeipmi/commands/sensors.rb', line 42

def templist(refreshdata=false)
  refresh if refreshdata
  tlist = {}
  list.each do | name , sensor |
    if sensor[:unit] =~ /.*degree.*/ || name =~ /.*temp.*/
      tlist[name] = sensor
    end
  end
  return tlist
end