diff options
author | Pete Higgins <pete@peterhiggins.org> | 2020-04-08 18:25:55 -0700 |
---|---|---|
committer | Pete Higgins <pete@peterhiggins.org> | 2020-04-15 16:51:50 -0700 |
commit | 64b4979503f070d0da7f6ae2fd138cb9a41d67b0 (patch) | |
tree | 685f4bb67168f9880d8b523ad2efb4fc0b1929d6 | |
parent | 82de2071e08066314fdffbb11593a96471159373 (diff) | |
download | ohai-64b4979503f070d0da7f6ae2fd138cb9a41d67b0.tar.gz |
Do some key munging so stuff resembles other stuff.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r-- | lib/ohai/common/dmi.rb | 2 | ||||
-rw-r--r-- | lib/ohai/plugins/windows/dmi.rb | 31 |
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb index cc9f4c10..b5a139db 100644 --- a/lib/ohai/common/dmi.rb +++ b/lib/ohai/common/dmi.rb @@ -122,7 +122,7 @@ module Ohai records[:all_records].each do |record| record.each do |field, value| - next if value.is_a?(Mash) + next unless value.is_a?(String) next if field.to_s == "application_identifier" next if field.to_s == "size" next if field.to_s == "record_id" diff --git a/lib/ohai/plugins/windows/dmi.rb b/lib/ohai/plugins/windows/dmi.rb index 73741535..e9c2dc76 100644 --- a/lib/ohai/plugins/windows/dmi.rb +++ b/lib/ohai/plugins/windows/dmi.rb @@ -41,16 +41,43 @@ Ohai.plugin(:DMI) do base_board: "BaseBoard", } + SPLIT_REGEX = /[A-Z][a-z0-9]+|[A-Z]{2,}(?=[A-Z][a-z0-9])|[A-Z]{2,}/ + collect_data(:windows) do + require "ohai/common/dmi" require "wmi-lite/wmi" wmi = WmiLite::Wmi.new dmi Mash.new DMI_TO_WIN32OLE.each do |dmi_key, ole_key| - properties = wmi.first_of("Win32_#{ole_key}").instance_variable_get("@property_map") + wmi_object = wmi.first_of("Win32_#{ole_key}").wmi_ole_object + + properties = wmi_object.properties_.each.with_object({}) do |property, hash| + split_name = property.name.scan(SPLIT_REGEX).join(" ") + + hash[split_name] = wmi_object.invoke(property.name) + end + + dmi[dmi_key] = Mash.new(all_records: [Mash.new(properties)]) + end + + Ohai::Common::DMI.convenience_keys(dmi) + + dmi.each_value do |records| + new_all_records = [] + + records[:all_records].each do |record| + new_record = Mash.new + + record.each do |key, value| + new_record[key.split(/\s+/).join] = value + end + + new_all_records << new_record + end - dmi[dmi_key] = Mash.new(properties) + records[:all_records] = new_all_records end end end |