X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/463d6a9d03c74d1b01cfd920ed8d36277ff1ea86..9360c6961050e2730b750afc41ec3e240dda3f30:/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 b60d143f0..09a9bced0 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 @@ -314,7 +333,7 @@ Ohai.plugin(:Hardware) do devices[:disks] << disk controller[:disks] << disk[:id] array[:disks] << disk[:id] - elsif disk && line =~ /^ (\S[^:]+):\s+(\S.*\S)\s*$/ + elsif disk && line =~ /^ (\S[^:]+):\s+(.*\S)\s*$/ case Regexp.last_match(1) when "Interface Type" then disk[:interface] = Regexp.last_match(2) when "Size" then disk[:size] = Regexp.last_match(2) @@ -323,7 +342,7 @@ Ohai.plugin(:Hardware) do when "Serial Number" then disk[:serial_number] = Regexp.last_match(2) when "Model" then disk[:model] = Regexp.last_match(2) end - elsif array && line =~ /^ (\S[^:]+):\s+(\S.*\S)\s*$/ + elsif array && line =~ /^ (\S[^:]+):\s+(.*\S)\s*$/ case Regexp.last_match(1) when "Size" then array[:size] = Regexp.last_match(2) when "Fault Tolerance" then array[:raid_level] = Regexp.last_match(2) @@ -758,6 +777,43 @@ 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 + + def mc_device + device = {} + + IO.popen(["ipmitool", "mc", "info"]).each_with_object([]) do |line, devices| + if line =~ /(Manufacturer [A-Z ]+[A-Z])\s*:\s+(.*\S)\s+\(.*\)\s*$/i + device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2) + elsif line =~ /(Product [A-Z ]+[A-Z])\s*:\s+(.*\S)\s+\(.*\)\s*$/i + device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2) + elsif line =~ /([A-Z ]+[A-Z])\s*:\s+(.*\S)\s*$/i + device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2) + end + end + + IO.popen(["ipmitool", "mc", "guid"]).each_with_object([]) do |line, devices| + if line =~ /^System GUID\s*:\s+(\S+)\s*$/ + device[:system_guid] = Regexp.last_match(1) + end + end + + device + end + collect_data(:default) do hardware Mash.new @@ -765,5 +821,7 @@ Ohai.plugin(:Hardware) do hardware[:network] = network_devices hardware[:memory] = memory_devices hardware[:disk] = disk_devices + hardware[:psu] = psu_devices + hardware[:mc] = mc_device end end