module Ohai::Common::DMI
Constants
- ID_TO_CAPTURE
list of IDs to collect from config or default to a sane list that prunes away some of the less useful IDs
- ID_TO_DESCRIPTION
List of IDs and what they translate to from 'man 8 dmidecode' all-lowercase, all non-alphanumeric converted to '_' 128-255 are 'oem_data_' Everything else is 'unknown'
Public Class Methods
create simplified convenience access keys for each record type for single occurrences of one type, copy to top level all fields and values for multiple occurrences of same type, copy to top level all fields and values that are common to all records
# File lib/ohai/common/dmi.rb, line 117 def convenience_keys(dmi) dmi.each do |type, records| in_common = Mash.new next unless records.class.to_s == "Mash" next unless records.key?("all_records") records[:all_records].each do |record| record.each do |field, value| next if value.class.to_s == "Mash" next if field.to_s == "application_identifier" next if field.to_s == "size" next if field.to_s == "record_id" translated = field.downcase.gsub(/[^a-z0-9]/, "_") value = value.strip if in_common.key?(translated) in_common[translated] = nil unless in_common[translated] == value else in_common[translated] = value end end end in_common.each do |field, value| next if value.nil? dmi[type][field] = value.strip end end end
the human readable description from a DMI
ID
@param id [String, Integer] the ID to lookup
@return [String]
# File lib/ohai/common/dmi.rb, line 99 def id_lookup(id) id = id.to_i if (id >= 128) && (id <= 255) id = "oem_data_#{id}" elsif DMI::ID_TO_DESCRIPTION.key?(id) id = DMI::ID_TO_DESCRIPTION[id] else Ohai::Log.debug("unrecognized header id; falling back to 'unknown'") id = "unknown_dmi_id_#{id}" end rescue Ohai::Log.debug("failed to look up id #{id}, returning unchanged") id end
the whitelisted DMI
IDs. This is combination of the defaults + any additional IDs defined in the :additional_dmi_ids config
@return [Array] the list of DMI
IDs to capture
# File lib/ohai/common/dmi.rb, line 83 def whitelisted_ids if Ohai.config[:additional_dmi_ids] if [ Integer, Array ].include?(Ohai.config[:additional_dmi_ids].class) return ID_TO_CAPTURE + Array(Ohai.config[:additional_dmi_ids]) else Ohai::Log.warn("The DMI plugin additional_dmi_ids config must be an array of IDs!") end end ID_TO_CAPTURE end
Private Instance Methods
create simplified convenience access keys for each record type for single occurrences of one type, copy to top level all fields and values for multiple occurrences of same type, copy to top level all fields and values that are common to all records
# File lib/ohai/common/dmi.rb, line 117 def convenience_keys(dmi) dmi.each do |type, records| in_common = Mash.new next unless records.class.to_s == "Mash" next unless records.key?("all_records") records[:all_records].each do |record| record.each do |field, value| next if value.class.to_s == "Mash" next if field.to_s == "application_identifier" next if field.to_s == "size" next if field.to_s == "record_id" translated = field.downcase.gsub(/[^a-z0-9]/, "_") value = value.strip if in_common.key?(translated) in_common[translated] = nil unless in_common[translated] == value else in_common[translated] = value end end end in_common.each do |field, value| next if value.nil? dmi[type][field] = value.strip end end end
the human readable description from a DMI
ID
@param id [String, Integer] the ID to lookup
@return [String]
# File lib/ohai/common/dmi.rb, line 99 def id_lookup(id) id = id.to_i if (id >= 128) && (id <= 255) id = "oem_data_#{id}" elsif DMI::ID_TO_DESCRIPTION.key?(id) id = DMI::ID_TO_DESCRIPTION[id] else Ohai::Log.debug("unrecognized header id; falling back to 'unknown'") id = "unknown_dmi_id_#{id}" end rescue Ohai::Log.debug("failed to look up id #{id}, returning unchanged") id end
the whitelisted DMI
IDs. This is combination of the defaults + any additional IDs defined in the :additional_dmi_ids config
@return [Array] the list of DMI
IDs to capture
# File lib/ohai/common/dmi.rb, line 83 def whitelisted_ids if Ohai.config[:additional_dmi_ids] if [ Integer, Array ].include?(Ohai.config[:additional_dmi_ids].class) return ID_TO_CAPTURE + Array(Ohai.config[:additional_dmi_ids]) else Ohai::Log.warn("The DMI plugin additional_dmi_ids config must be an array of IDs!") end end ID_TO_CAPTURE end