From: Tom Hughes Date: Mon, 14 Dec 2015 09:52:00 +0000 (+0000) Subject: Gather information on power supplies X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/ffb2ea73b92aefb06bfbff9911c934f47af0a1b4 Gather information on power supplies --- diff --git a/cookbooks/hardware/templates/default/ohai.rb.erb b/cookbooks/hardware/templates/default/ohai.rb.erb index 87560b8dd..24a844a7f 100644 --- a/cookbooks/hardware/templates/default/ohai.rb.erb +++ b/cookbooks/hardware/templates/default/ohai.rb.erb @@ -758,6 +758,21 @@ Ohai.plugin(:Hardware) do end end + def psu_devices + device = nil + + IO.popen(["dmidecode", "-t", "39"]).each_with_object([]) do |line, devices| + if line =~ /^System Power Supply\s*$/ + device = {} + elsif device && line =~ /^\s+([A-Z ]+):\s+(.*)\s*$/i + device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2).strip + elsif device && line =~ /^\s*$/ + devices << device + device = nil + end + end + end + collect_data(:default) do hardware Mash.new @@ -765,5 +780,6 @@ Ohai.plugin(:Hardware) do hardware[:network] = network_devices hardware[:memory] = memory_devices hardware[:disk] = disk_devices + hardware[:psu] = psu_devices end end