summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2006-06-14 00:35:17 +0000
committerweasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede>2006-06-14 00:35:17 +0000
commit26fb381299a4842acb4a0ad7d01958bd90f5e153 (patch)
tree000a4c6c80828d6462ec65b7b32ec53569cb45ec
parent16fab876efa75f9c64ae76df5e9b9eb384b1585c (diff)
work around ipmitool aborts
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@126 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
-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