summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-10-10 11:43:38 -0700
committerGitHub <noreply@github.com>2018-10-10 11:43:38 -0700
commit818585af2f51f2976f4e1bc5a3aa65bcb187d88d (patch)
tree01d1aec46d38106622c63890ae721d373a50d4ef
parentd366484b7f4cdf7c6f383ce1895ba6d2df047059 (diff)
parentff3cafa5d8850c7aaea9b9714b15a8256168120a (diff)
downloadohai-818585af2f51f2976f4e1bc5a3aa65bcb187d88d.tar.gz
Merge pull request #1263 from chef/mac
Trim out bogus data in system_profile plugin
-rw-r--r--lib/ohai/plugins/darwin/hardware.rb8
-rw-r--r--lib/ohai/plugins/darwin/system_profiler.rb38
2 files changed, 20 insertions, 26 deletions
diff --git a/lib/ohai/plugins/darwin/hardware.rb b/lib/ohai/plugins/darwin/hardware.rb
index c522090f..dab7957d 100644
--- a/lib/ohai/plugins/darwin/hardware.rb
+++ b/lib/ohai/plugins/darwin/hardware.rb
@@ -34,13 +34,7 @@ Ohai.plugin(:Hardware) do
next
end
- begin
- require "plist"
- rescue LoadError => e
- # In case the plist gem isn't present, skip this plugin.
- logger.trace("Plugin Hardware: Can't load gem: #{e}. Cannot continue.")
- next
- end
+ require "plist"
hw_hash = system_profiler("SPHardwareDataType")
hw_hash[0]["_items"][0].delete("_name")
diff --git a/lib/ohai/plugins/darwin/system_profiler.rb b/lib/ohai/plugins/darwin/system_profiler.rb
index 61000474..ee1ab298 100644
--- a/lib/ohai/plugins/darwin/system_profiler.rb
+++ b/lib/ohai/plugins/darwin/system_profiler.rb
@@ -20,13 +20,12 @@ Ohai.plugin(:SystemProfile) do
provides "system_profile"
collect_data(:darwin) do
- begin
- require "plist"
+ require "plist"
- system_profile Array.new
- items = Array.new
- detail_level = {
- "mini" => %w{
+ system_profile Array.new
+ items = Array.new
+ detail_level = {
+ "mini" => %w{
SPParallelATAData
SPAudioData
SPBluetoothData
@@ -52,21 +51,22 @@ SPThunderboltData
SPUSBData
SPWWANData
SPAirPortData},
- "full" => [
- "SPHardwareDataType",
- ],
- }
+ "full" => [
+ "SPHardwareDataType",
+ ],
+ }
- detail_level.each do |level, data_types|
- so = shell_out("system_profiler -xml -detailLevel #{level} #{data_types.join(' ')}")
- Plist.parse_xml(so.stdout).each do |e|
- items << e
- end
+ detail_level.each do |level, data_types|
+ so = shell_out("system_profiler -xml -detailLevel #{level} #{data_types.join(' ')}")
+ Plist.parse_xml(so.stdout).each do |e|
+ # delete some bogus timing data and then keep the rest
+ e.delete("_SPCompletionInterval")
+ e.delete("_SPResponseTime")
+ e.delete("_SPCommandLineArguments")
+ items << e
end
-
- system_profile ( items.sort_by { |h| h["_dataType"] } ) # rubocop: disable Lint/ParenthesesAsGroupedExpression
- rescue LoadError => e
- logger.trace("Can't load gem: #{e})")
end
+
+ system_profile ( items.sort_by { |h| h["_dataType"] } ) # rubocop: disable Lint/ParenthesesAsGroupedExpression
end
end