summaryrefslogtreecommitdiff
path: root/munin/ipmi_sensor_
diff options
context:
space:
mode:
Diffstat (limited to 'munin/ipmi_sensor_')
-rwxr-xr-xmunin/ipmi_sensor_84
1 files changed, 56 insertions, 28 deletions
diff --git a/munin/ipmi_sensor_ b/munin/ipmi_sensor_
index f364fc7..c2e0876 100755
--- a/munin/ipmi_sensor_
+++ b/munin/ipmi_sensor_
@@ -22,6 +22,7 @@ VALID_UNITS = %w{volts degrees_c rpm amps watts}
CACHEDIR = "/var/lib/munin/plugin-state"
CACHEFILE = "plugin-ipmi_sensor.cache"
CACHE_AGE = 275
+IPMITOOL = '/usr/bin/ipmitool'
def bail_out(m)
STDERR.puts "#{$0}: #{m}"
@@ -64,36 +65,63 @@ def get_sensor_data
data = []
names = {}
- IO.popen("ipmitool -I open sensor") do |f|
- f.each do |line|
- line.strip!
- # cpu1.vtt-s3 | 1.200 | Volts | ok | na | 1.080 | na | na | 1.320 | na
- # CPU0 IERR | 0x0 | discrete | 0x0100| na | na | na | na | na | na········
- items = line.split(/\s*\|\s*/)
- unless items.size == 10
- bail_out "Got weird number of fields in ipmitool output. Expected 10 but got #{items.size} for line '#{line}'."
- end
- (name, value, unit, status, lower_non_recov, lower_crit, lower_non_crit, upper_non_crit, upper_crit, upper_non_recv) = items
- nname = normalize_sensor name;
- if names.has_key?(nname)
- bail_out "Sensor name #{name} (normalized to #{nname}) appears more than once in ipmitool output."
- end
- names[nname] = 1
- data << {
- :name => name,
- :value => value,
- :unit => unit,
- :status => status,
- :lower_non_recov => lower_non_recov,
- :lower_crit => lower_crit,
- :lower_non_crit => lower_non_crit,
- :upper_non_crit => upper_non_crit,
- :upper_crit => upper_crit,
- :upper_non_recv => upper_non_recv,
- :line => line
- }
+
+ rdout, wrout = IO.pipe
+ rderr, wrerr = IO.pipe
+
+ pid = fork
+ unless pid
+ # child
+ rdout.close
+ rderr.close
+ STDOUT.reopen wrout
+ STDERR.reopen wrerr
+ exec(IPMITOOL, '-I', 'open', 'sensor')
+ bail_out("fell through exec(). WTF.")
+ end
+ wrout.close
+ wrerr.close
+
+
+ out = []
+ err = []
+ tout = Thread.new { out = rdout.readlines }
+ terr = Thread.new { err = rderr.readlines }
+ tout.join
+ terr.join
+ Process.wait pid
+
+ bail_out("ipmitool printed stuff on stdout: "+err.join('')) if (err.length > 0)
+
+ out.each do |line|
+ line.strip!
+ # cpu1.vtt-s3 | 1.200 | Volts | ok | na | 1.080 | na | na | 1.320 | na
+ # CPU0 IERR | 0x0 | discrete | 0x0100| na | na | na | na | na | na········
+ items = line.split(/\s*\|\s*/)
+ unless items.size == 10
+ bail_out "Got weird number of fields in ipmitool output. Expected 10 but got #{items.size} for line '#{line}'."
+ end
+ (name, value, unit, status, lower_non_recov, lower_crit, lower_non_crit, upper_non_crit, upper_crit, upper_non_recv) = items
+ nname = normalize_sensor name;
+ if names.has_key?(nname)
+ bail_out "Sensor name #{name} (normalized to #{nname}) appears more than once in ipmitool output."
end
+ names[nname] = 1
+ data << {
+ :name => name,
+ :value => value,
+ :unit => unit,
+ :status => status,
+ :lower_non_recov => lower_non_recov,
+ :lower_crit => lower_crit,
+ :lower_non_crit => lower_non_crit,
+ :upper_non_crit => upper_non_crit,
+ :upper_crit => upper_crit,
+ :upper_non_recv => upper_non_recv,
+ :line => line
+ }
end
+
write_cache data
data
end