X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/d1523ca3533017306b1587db23638d188f2db524..8da30477d3cb48132c68297060dd37e4da30f3d1:/cookbooks/hardware/templates/default/ohai.rb.erb diff --git a/cookbooks/hardware/templates/default/ohai.rb.erb b/cookbooks/hardware/templates/default/ohai.rb.erb index 87560b8dd..e8e01845e 100644 --- a/cookbooks/hardware/templates/default/ohai.rb.erb +++ b/cookbooks/hardware/templates/default/ohai.rb.erb @@ -61,9 +61,10 @@ Ohai.plugin(:Hardware) do end def pci_devices + devices = {} device = nil - IO.popen(["lspci", "-Dkvmm"]).each_with_object(Mash.new) do |line, devices| + IO.popen(["lspci", "-Dkvmm"]).each do |line| if line =~ /^Slot:\s+((\h{4}):(\h{2}):(\h{2}).(\h))\s*$/ device = { :slot => Regexp.last_match(1), @@ -90,6 +91,24 @@ Ohai.plugin(:Hardware) do device = nil end end + + IO.popen(["lspci", "-Dkvmmn"]).each do |line| + if line =~ /^Slot:\s+((\h{4}):(\h{2}):(\h{2}).(\h))\s*$/ + device = devices[Regexp.last_match(1)] + elsif device && line =~ /^([A-Z]+):\s+(.*)\s*$/i + case Regexp.last_match(1) + when "Class" then device[:class_id] = Regexp.last_match(2) + when "Vendor" then device[:vendor_id] = Regexp.last_match(2) + when "Device" then device[:device_id] = Regexp.last_match(2) + when "SVendor" then device[:subsystem_vendor_id] = Regexp.last_match(2) + when "SDevice" then device[:subsystem_device_id] = Regexp.last_match(2) + end + elsif device && line =~ /^\s*$/ + device = nil + end + end + + devices end def network_devices @@ -758,6 +777,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 +799,6 @@ Ohai.plugin(:Hardware) do hardware[:network] = network_devices hardware[:memory] = memory_devices hardware[:disk] = disk_devices + hardware[:psu] = psu_devices end end