Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim out bogus data in system_profile plugin #1263

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions lib/ohai/plugins/darwin/hardware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ def system_profiler(datatype)
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")
Expand Down
38 changes: 19 additions & 19 deletions lib/ohai/plugins/darwin/system_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
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
Expand All @@ -52,21 +51,22 @@
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