ohai 13.1.0 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +15 -6
  3. data/lib/ohai/common/dmi.rb +11 -13
  4. data/lib/ohai/dsl/plugin.rb +6 -8
  5. data/lib/ohai/dsl/plugin/versionvi.rb +1 -1
  6. data/lib/ohai/dsl/plugin/versionvii.rb +4 -4
  7. data/lib/ohai/mash.rb +1 -1
  8. data/lib/ohai/mixin/command.rb +3 -3
  9. data/lib/ohai/mixin/dmi_decode.rb +1 -1
  10. data/lib/ohai/mixin/ec2_metadata.rb +10 -10
  11. data/lib/ohai/mixin/os.rb +11 -11
  12. data/lib/ohai/mixin/softlayer_metadata.rb +2 -2
  13. data/lib/ohai/mixin/string.rb +1 -1
  14. data/lib/ohai/plugins/azure.rb +2 -2
  15. data/lib/ohai/plugins/c.rb +9 -10
  16. data/lib/ohai/plugins/darwin/cpu.rb +24 -20
  17. data/lib/ohai/plugins/darwin/hardware.rb +15 -9
  18. data/lib/ohai/plugins/digital_ocean.rb +2 -2
  19. data/lib/ohai/plugins/ec2.rb +5 -5
  20. data/lib/ohai/plugins/elixir.rb +1 -1
  21. data/lib/ohai/plugins/erlang.rb +2 -2
  22. data/lib/ohai/plugins/eucalyptus.rb +2 -2
  23. data/lib/ohai/plugins/go.rb +1 -1
  24. data/lib/ohai/plugins/hostname.rb +7 -10
  25. data/lib/ohai/plugins/ip_scopes.rb +2 -0
  26. data/lib/ohai/plugins/java.rb +19 -21
  27. data/lib/ohai/plugins/kernel.rb +1 -1
  28. data/lib/ohai/plugins/linux/cpu.rb +4 -0
  29. data/lib/ohai/plugins/linux/filesystem.rb +43 -30
  30. data/lib/ohai/plugins/linux/lsb.rb +1 -1
  31. data/lib/ohai/plugins/linux/mdadm.rb +9 -1
  32. data/lib/ohai/plugins/linux/network.rb +8 -12
  33. data/lib/ohai/plugins/linux/platform.rb +9 -1
  34. data/lib/ohai/plugins/linux/systemd_paths.rb +39 -0
  35. data/lib/ohai/plugins/mono.rb +1 -1
  36. data/lib/ohai/plugins/nodejs.rb +1 -1
  37. data/lib/ohai/plugins/openstack.rb +5 -5
  38. data/lib/ohai/plugins/packages.rb +8 -2
  39. data/lib/ohai/plugins/perl.rb +1 -1
  40. data/lib/ohai/plugins/php.rb +1 -1
  41. data/lib/ohai/plugins/powershell.rb +1 -1
  42. data/lib/ohai/plugins/python.rb +1 -1
  43. data/lib/ohai/plugins/rackspace.rb +4 -4
  44. data/lib/ohai/plugins/rust.rb +1 -1
  45. data/lib/ohai/plugins/solaris2/dmi.rb +3 -3
  46. data/lib/ohai/plugins/solaris2/network.rb +2 -2
  47. data/lib/ohai/plugins/ssh_host_key.rb +1 -1
  48. data/lib/ohai/plugins/uptime.rb +1 -1
  49. data/lib/ohai/plugins/{solaris2/zpools.rb → zpools.rb} +39 -16
  50. data/lib/ohai/util/file_helper.rb +2 -2
  51. data/lib/ohai/version.rb +1 -1
  52. data/spec/data/plugins/lslpp.output +1 -0
  53. data/spec/unit/plugins/darwin/cpu_spec.rb +66 -19
  54. data/spec/unit/plugins/darwin/hardware_spec.rb +2 -14
  55. data/spec/unit/plugins/linux/cpu_spec.rb +47 -0
  56. data/spec/unit/plugins/linux/filesystem_spec.rb +99 -9
  57. data/spec/unit/plugins/linux/mdadm_spec.rb +26 -1
  58. data/spec/unit/plugins/linux/network_spec.rb +8 -26
  59. data/spec/unit/plugins/linux/platform_spec.rb +41 -0
  60. data/spec/unit/plugins/linux/systemd_paths_spec.rb +122 -0
  61. data/spec/unit/plugins/packages_spec.rb +4 -0
  62. data/spec/unit/plugins/rackspace_spec.rb +3 -3
  63. data/spec/unit/plugins/zpools_spec.rb +242 -0
  64. metadata +7 -5
  65. data/spec/unit/plugins/solaris2/zpools_spec.rb +0 -153
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a790e9dca44c313d60c13521eddb5f71fb17d95
4
- data.tar.gz: b42fe376d2bc0ae29386b3d5e90607e65f47050a
3
+ metadata.gz: 2c77bbdaf5110dc3837d208227d35171c3abd7d7
4
+ data.tar.gz: 2781b142b0bf7b9201edbbb01b82d005f0703165
5
5
  SHA512:
6
- metadata.gz: 9280f45b479f112e18e8118db63f9b091c94eab2a08756f3e306ee4fc23d4bba4246550c6c1e5d9fb2e2293eaeeac11da6946af12778258b3f96c5c236b13910
7
- data.tar.gz: 94e260d4a12d569b9a8c3a0cef67359f05b82760b636f30f10658ebb73adcbcd9bd2af5a33681a715ce4c743d1ca3dc2292d83edcb8cb2fa5b0b0a023b01833a
6
+ metadata.gz: 4b0e442fe9e3506dac3b41c9f2cd239c04f649581df61f4302fe510e898f5dd4fff1ec8741704c0075025f3f76d98f5af55fb6beb8e5abd899803ffda6c014f2
7
+ data.tar.gz: e18343490101bc00c3f385b13d875f56c12c4724a404a2b1a30d863975fac898ce193330f600ef8d9a652eb7bff3a97df367ad2137fd73f914dcbaef3e2cff08
data/Gemfile CHANGED
@@ -2,18 +2,27 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
+ # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
5
6
  group :development do
6
7
  gem "chefstyle"
7
- gem "overcommit", ">= 0.34.1"
8
- gem "pry-byebug"
9
- gem "pry-stack_explorer"
10
- gem "rb-readline"
11
- gem "rake", ">= 10.1.0", "< 12.0.0"
8
+ gem "rake", ">= 10.1.0"
12
9
  gem "rspec-core", "~> 3.0"
13
10
  gem "rspec-expectations", "~> 3.0"
14
11
  gem "rspec-mocks", "~> 3.0"
15
12
  gem "rspec-collection_matchers", "~> 1.0"
13
+ gem "ipaddr_extensions"
14
+ end
15
+
16
+ group :ci do
16
17
  gem "rspec_junit_formatter"
18
+ end
19
+
20
+ group :changelog do
17
21
  gem "github_changelog_generator", git: "https://github.com/chef/github-changelog-generator"
18
- gem "ipaddr_extensions"
19
22
  end
23
+
24
+ instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
25
+
26
+ # If you want to load debugging tools into the bundle exec sandbox,
27
+ # add these additional dependencies into Gemfile.local
28
+ eval_gemfile(__FILE__ + ".local") if File.exist?(__FILE__ + ".local")
@@ -78,20 +78,18 @@ module Ohai
78
78
 
79
79
  # look up DMI ID
80
80
  def id_lookup(id)
81
- begin
82
- id = id.to_i
83
- if (id >= 128) && (id <= 255)
84
- id = "oem_data_#{id}"
85
- elsif DMI::ID_TO_DESCRIPTION.has_key?(id)
86
- id = DMI::ID_TO_DESCRIPTION[id]
87
- else
88
- Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
89
- id = "unknown"
90
- end
91
- rescue
92
- Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
93
- id
81
+ id = id.to_i
82
+ if (id >= 128) && (id <= 255)
83
+ id = "oem_data_#{id}"
84
+ elsif DMI::ID_TO_DESCRIPTION.has_key?(id)
85
+ id = DMI::ID_TO_DESCRIPTION[id]
86
+ else
87
+ Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
88
+ id = "unknown"
94
89
  end
90
+ rescue
91
+ Ohai::Log.debug("failed to look up id #{id}, returning unchanged")
92
+ id
95
93
  end
96
94
 
97
95
  # create simplified convenience access keys for each record type
@@ -180,14 +180,12 @@ module Ohai
180
180
 
181
181
  # emulates the old plugin loading behavior
182
182
  def safe_run
183
- begin
184
- self.run
185
- rescue Ohai::Exceptions::Error => e
186
- raise e
187
- rescue => e
188
- Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}")
189
- e.backtrace.each { |line| Ohai::Log.debug( line ) }
190
- end
183
+ run
184
+ rescue Ohai::Exceptions::Error => e
185
+ raise e
186
+ rescue => e
187
+ Ohai::Log.debug("Plugin #{name} threw #{e.inspect}")
188
+ e.backtrace.each { |line| Ohai::Log.debug( line ) }
191
189
  end
192
190
 
193
191
  def method_missing(name, *args)
@@ -44,7 +44,7 @@ module Ohai
44
44
  end
45
45
 
46
46
  def self.collect_contents(contents)
47
- define_method(:run_plugin) { self.instance_eval(contents) }
47
+ define_method(:run_plugin) { instance_eval(contents) }
48
48
  end
49
49
 
50
50
  def provides(*paths)
@@ -85,11 +85,11 @@ module Ohai
85
85
  platform = collect_os
86
86
 
87
87
  if collector.has_key?(platform)
88
- self.instance_eval(&collector[platform])
88
+ instance_eval(&collector[platform])
89
89
  elsif collector.has_key?(:default)
90
- self.instance_eval(&collector[:default])
90
+ instance_eval(&collector[:default])
91
91
  else
92
- Ohai::Log.debug("Plugin #{self.name}: No data to collect. Skipping...")
92
+ Ohai::Log.debug("Plugin #{name}: No data to collect. Skipping...")
93
93
  end
94
94
  end
95
95
 
@@ -122,7 +122,7 @@ module Ohai
122
122
  # Memory => ["", "Memory"]
123
123
  # NetworkListeners => ["", "Network", "", "Listeners"]
124
124
  # SSHHostKey => ["SSH", "Host", "", "Key"]
125
- parts = self.name.to_s.split(/([A-Z][a-z]+)/)
125
+ parts = name.to_s.split(/([A-Z][a-z]+)/)
126
126
  # ["DMI"] => ["DMI"]
127
127
  # ["", "Memory"] => ["Memory"]
128
128
  # ["", "Network", "", "Listeners"] => ["Network", "Listeners"]
@@ -135,7 +135,7 @@ class Mash < Hash
135
135
  #
136
136
  # @return [Mash] A new mash with the hash values merged in.
137
137
  def merge(hash)
138
- self.dup.update(hash)
138
+ dup.update(hash)
139
139
  end
140
140
 
141
141
  # @param key<Object>
@@ -37,13 +37,13 @@ module Ohai
37
37
  so = Mixlib::ShellOut.new(cmd, options)
38
38
  begin
39
39
  so.run_command
40
- Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and returned #{so.exitstatus}")
40
+ Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}")
41
41
  so
42
42
  rescue Errno::ENOENT => e
43
- Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and failed #{e.inspect}")
43
+ Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}")
44
44
  raise Ohai::Exceptions::Exec, e
45
45
  rescue Mixlib::ShellOut::CommandTimeout => e
46
- Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
46
+ Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds")
47
47
  raise Ohai::Exceptions::Exec, e
48
48
  end
49
49
  end
@@ -46,6 +46,6 @@ module ::Ohai::Mixin::DmiDecode
46
46
  return "veertu"
47
47
  end
48
48
  end
49
- return nil
49
+ nil
50
50
  end
51
51
  end
@@ -49,24 +49,24 @@ module Ohai
49
49
 
50
50
  def best_api_version
51
51
  @api_version ||= begin
52
- Ohai::Log.debug("ec2 metadata mixin: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release")
52
+ Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release")
53
53
  response = http_client.get("/")
54
54
  if response.code == "404"
55
- Ohai::Log.debug("ec2 metadata mixin: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
55
+ Ohai::Log.debug("Mixin EC2: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
56
56
  return "latest"
57
57
  elsif response.code != "200"
58
- raise "Unable to determine EC2 metadata version (returned #{response.code} response)"
58
+ raise "Mixin EC2: Unable to determine EC2 metadata version (returned #{response.code} response)"
59
59
  end
60
60
  # Note: Sorting the list of versions may have unintended consequences in
61
61
  # non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12.
62
62
  versions = response.body.split("\n").sort
63
63
  until versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last)
64
64
  pv = versions.pop
65
- Ohai::Log.debug("ec2 metadata mixin: EC2 lists metadata version: #{pv} not yet supported by Ohai") unless pv == "latest"
65
+ Ohai::Log.debug("Mixin EC2: EC2 lists metadata version: #{pv} not yet supported by Ohai") unless pv == "latest"
66
66
  end
67
- Ohai::Log.debug("ec2 metadata mixin: Latest supported EC2 metadata version: #{versions.last}")
67
+ Ohai::Log.debug("Mixin EC2: Latest supported EC2 metadata version: #{versions.last}")
68
68
  if versions.empty?
69
- raise "Unable to determine EC2 metadata version (no supported entries found)"
69
+ raise "Mixin EC2: Unable to determine EC2 metadata version (no supported entries found)"
70
70
  end
71
71
  versions.last
72
72
  end
@@ -88,16 +88,16 @@ module Ohai
88
88
  # `nil` and continue the run instead of failing it.
89
89
  def metadata_get(id, api_version)
90
90
  path = "/#{api_version}/meta-data/#{id}"
91
- Ohai::Log.debug("ec2 metadata mixin: Fetching http://#{EC2_METADATA_ADDR}#{path}")
91
+ Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}#{path}")
92
92
  response = http_client.get(path)
93
93
  case response.code
94
94
  when "200"
95
95
  response.body
96
96
  when "404"
97
- Ohai::Log.debug("ec2 metadata mixin: Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.")
97
+ Ohai::Log.debug("Mixin EC2: Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.")
98
98
  nil
99
99
  else
100
- raise "Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)"
100
+ raise "Mixin EC2: Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)"
101
101
  end
102
102
  end
103
103
 
@@ -169,7 +169,7 @@ module Ohai
169
169
  end
170
170
 
171
171
  def fetch_userdata
172
- Ohai::Log.debug("ec2 metadata mixin: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/")
172
+ Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/")
173
173
  response = http_client.get("/#{best_api_version}/user-data/")
174
174
  response.code == "200" ? response.body : nil
175
175
  end
@@ -26,32 +26,32 @@ module Ohai
26
26
  def collect_os
27
27
  case ::RbConfig::CONFIG["host_os"]
28
28
  when /aix(.+)$/
29
- return "aix"
29
+ "aix"
30
30
  when /darwin(.+)$/
31
- return "darwin"
31
+ "darwin"
32
32
  when /hpux(.+)$/
33
- return "hpux"
33
+ "hpux"
34
34
  when /linux/
35
- return "linux"
35
+ "linux"
36
36
  when /freebsd(.+)$/
37
- return "freebsd"
37
+ "freebsd"
38
38
  when /openbsd(.+)$/
39
- return "openbsd"
39
+ "openbsd"
40
40
  when /netbsd(.*)$/
41
- return "netbsd"
41
+ "netbsd"
42
42
  when /dragonfly(.*)$/
43
- return "dragonflybsd"
43
+ "dragonflybsd"
44
44
  when /solaris2/
45
- return "solaris2"
45
+ "solaris2"
46
46
  when /mswin|mingw32|windows/
47
47
  # After long discussion in IRC the "powers that be" have come to a consensus
48
48
  # that no Windows platform exists that was not based on the
49
49
  # Windows_NT kernel, so we herby decree that "windows" will refer to all
50
50
  # platforms built upon the Windows_NT kernel and have access to win32 or win64
51
51
  # subsystems.
52
- return "windows"
52
+ "windows"
53
53
  else
54
- return ::RbConfig::CONFIG["host_os"]
54
+ ::RbConfig::CONFIG["host_os"]
55
55
  end
56
56
  end
57
57
 
@@ -54,11 +54,11 @@ module ::Ohai::Mixin::SoftlayerMetadata
54
54
  if res.code.to_i.between?(200, 299)
55
55
  res.body
56
56
  else
57
- ::Ohai::Log.error("Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})")
57
+ ::Ohai::Log.error("Mixin Softlayer: Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})")
58
58
  nil
59
59
  end
60
60
  rescue => e
61
- ::Ohai::Log.error("Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.message}")
61
+ ::Ohai::Log.error("Mixin Softlayer: Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.message}")
62
62
  raise e
63
63
  end
64
64
  end
@@ -23,7 +23,7 @@ class String
23
23
  # This should implement the same functionality as underscore method in
24
24
  # ActiveSupport::CoreExtensions::String::Inflections
25
25
  def wmi_underscore
26
- self.gsub(/::/, "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
26
+ gsub(/::/, "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
27
27
  gsub(/([a-z\d])([A-Z])/, '\1_\2').tr("-", "_").downcase
28
28
  end
29
29
  end
@@ -41,7 +41,7 @@ Ohai.plugin(:Azure) do
41
41
  def has_waagent?
42
42
  if File.exist?("/usr/sbin/waagent") || Dir.exist?('C:\WindowsAzure')
43
43
  Ohai::Log.debug("Plugin Azure: Found waagent used by MS Azure.")
44
- return true
44
+ true
45
45
  end
46
46
  end
47
47
 
@@ -56,7 +56,7 @@ Ohai.plugin(:Azure) do
56
56
  end
57
57
  end
58
58
  end
59
- return has_245
59
+ has_245
60
60
  end
61
61
 
62
62
  end
@@ -123,18 +123,17 @@ Ohai.plugin(:C) do
123
123
 
124
124
  def collect_xlc
125
125
  # ibm xlc
126
- begin
127
- so = shell_out("xlc -qversion")
128
- if so.exitstatus == 0 || (so.exitstatus >> 8) == 249
129
- description = so.stdout.split($/).first
130
- if description =~ /V(\d+\.\d+)/
131
- @c[:xlc] = Mash.new
132
- @c[:xlc][:version] = $1
133
- @c[:xlc][:description] = description.strip
134
- end
126
+
127
+ so = shell_out("xlc -qversion")
128
+ if so.exitstatus == 0 || (so.exitstatus >> 8) == 249
129
+ description = so.stdout.split($/).first
130
+ if description =~ /V(\d+\.\d+)/
131
+ @c[:xlc] = Mash.new
132
+ @c[:xlc][:version] = $1
133
+ @c[:xlc][:description] = description.strip
135
134
  end
136
- rescue Ohai::Exceptions::Exec
137
135
  end
136
+ rescue Ohai::Exceptions::Exec
138
137
  end
139
138
 
140
139
  def collect_sunpro
@@ -22,25 +22,29 @@ Ohai.plugin(:CPU) do
22
22
 
23
23
  collect_data(:darwin) do
24
24
  cpu Mash.new
25
- so = shell_out("sysctl -n hw.packages")
26
- cpu[:real] = so.stdout.to_i
27
- so = shell_out("sysctl -n hw.physicalcpu")
28
- cpu[:cores] = so.stdout.to_i
29
- so = shell_out("sysctl -n hw.logicalcpu")
30
- cpu[:total] = so.stdout.to_i
31
- so = shell_out("sysctl -n hw.cpufrequency")
32
- cpu[:mhz] = so.stdout.to_i / 1000000
33
- so = shell_out("sysctl -n machdep.cpu.vendor")
34
- cpu[:vendor_id] = so.stdout.chomp
35
- so = shell_out("sysctl -n machdep.cpu.brand_string")
36
- cpu[:model_name] = so.stdout.chomp
37
- so = shell_out("sysctl -n machdep.cpu.model")
38
- cpu[:model] = so.stdout.to_i
39
- so = shell_out("sysctl -n machdep.cpu.family")
40
- cpu[:family] = so.stdout.to_i
41
- so = shell_out("sysctl -n machdep.cpu.stepping")
42
- cpu[:stepping] = so.stdout.to_i
43
- so = shell_out("sysctl -n machdep.cpu.features")
44
- cpu[:flags] = so.stdout.downcase.split(" ")
25
+ shell_out("sysctl -a").stdout.lines.each do |line|
26
+ case line
27
+ when /^hw.packages: (.*)$/
28
+ cpu[:real] = Regexp.last_match[1].to_i
29
+ when /^hw.physicalcpu: (.*)$/
30
+ cpu[:cores] = Regexp.last_match[1].to_i
31
+ when /^hw.logicalcpu: (.*)$/
32
+ cpu[:total] = Regexp.last_match[1].to_i
33
+ when /^hw.cpufrequency: (.*)$/
34
+ cpu[:mhz] = Regexp.last_match[1].to_i / 1000000
35
+ when /^machdep.cpu.vendor: (.*)$/
36
+ cpu[:vendor_id] = Regexp.last_match[1].chomp
37
+ when /^machdep.cpu.brand_string: (.*)$/
38
+ cpu[:model_name] = Regexp.last_match[1].chomp
39
+ when /^machdep.cpu.model: (.*)$/
40
+ cpu[:model] = Regexp.last_match[1].to_i
41
+ when /^machdep.cpu.family: (.*)$/
42
+ cpu[:family] = Regexp.last_match[1].to_i
43
+ when /^machdep.cpu.stepping: (.*)$/
44
+ cpu[:stepping] = Regexp.last_match[1].to_i
45
+ when /^machdep.cpu.features: (.*)$/
46
+ cpu[:flags] = Regexp.last_match[1].downcase.split(" ")
47
+ end
48
+ end
45
49
  end
46
50
  end
@@ -30,7 +30,7 @@ Ohai.plugin(:Hardware) do
30
30
  unless hardware
31
31
  hardware Mash.new
32
32
  else
33
- Ohai::Log.debug("Plugin Darwin Hardware: namespace already exists")
33
+ Ohai::Log.debug("Plugin Hardware: namespace already exists")
34
34
  next
35
35
  end
36
36
 
@@ -46,16 +46,22 @@ Ohai.plugin(:Hardware) do
46
46
  hw_hash[0]["_items"][0].delete("_name")
47
47
  hardware.merge!(hw_hash[0]["_items"][0])
48
48
 
49
- {
50
- "operating_system" => "sw_vers -productName",
51
- "operating_system_version" => "sw_vers -productVersion",
52
- "build_version" => "sw_vers -buildVersion",
53
- "architecture" => "uname -m",
54
- }.each do |var, cmd|
55
- os_info = shell_out(cmd).stdout
56
- hardware[var] = os_info.strip unless os_info.nil?
49
+ # ProductName: Mac OS X
50
+ # ProductVersion: 10.12.5
51
+ # BuildVersion: 16F73
52
+ shell_out("sw_vers").stdout.lines.each do |line|
53
+ case line
54
+ when /^ProductName:\s*(.*)$/
55
+ hardware["operating_system"] = Regexp.last_match[1].strip
56
+ when /^ProductVersion:\s*(.*)$/
57
+ hardware["operating_system_version"] = Regexp.last_match[1].strip
58
+ when /^BuildVersion:\s*(.*)$/
59
+ hardware["build_version"] = Regexp.last_match[1].strip
60
+ end
57
61
  end
58
62
 
63
+ hardware["architecture"] = shell_out("uname -m").stdout.strip
64
+
59
65
  # Storage queries
60
66
  storage = []
61
67
  storage_hash = system_profiler("SPStorageDataType")
@@ -38,13 +38,13 @@ Ohai.plugin(:DigitalOcean) do
38
38
  # dmi[:bios][:all_records][0][:Vendor] may not exist
39
39
  end
40
40
  Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == false")
41
- return false
41
+ false
42
42
  end
43
43
 
44
44
  def looks_like_digital_ocean?
45
45
  return true if hint?("digital_ocean")
46
46
  return true if has_do_dmi? && can_socket_connect?(Ohai::Mixin::DOMetadata::DO_METADATA_ADDR, 80)
47
- return false
47
+ false
48
48
  end
49
49
 
50
50
  collect_data do