ohai 16.3.2 → 16.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/lib/ohai/application.rb +2 -2
  4. data/lib/ohai/loader.rb +1 -2
  5. data/lib/ohai/log.rb +1 -1
  6. data/lib/ohai/mixin/os.rb +1 -1
  7. data/lib/ohai/mixin/softlayer_metadata.rb +1 -1
  8. data/lib/ohai/plugins/aix/network.rb +2 -1
  9. data/lib/ohai/plugins/aix/uptime.rb +1 -1
  10. data/lib/ohai/plugins/cloud.rb +1 -1
  11. data/lib/ohai/plugins/cpu.rb +1 -1
  12. data/lib/ohai/plugins/docker.rb +2 -2
  13. data/lib/ohai/plugins/dragonflybsd/platform.rb +2 -4
  14. data/lib/ohai/plugins/ec2.rb +3 -2
  15. data/lib/ohai/plugins/filesystem.rb +7 -13
  16. data/lib/ohai/plugins/fips.rb +1 -5
  17. data/lib/ohai/plugins/freebsd/platform.rb +2 -4
  18. data/lib/ohai/plugins/gce.rb +1 -1
  19. data/lib/ohai/plugins/hostname.rb +4 -4
  20. data/lib/ohai/plugins/kernel.rb +1 -1
  21. data/lib/ohai/plugins/linux/hostnamectl.rb +1 -2
  22. data/lib/ohai/plugins/linux/lsb.rb +1 -2
  23. data/lib/ohai/plugins/linux/lspci.rb +1 -2
  24. data/lib/ohai/plugins/linux/machineid.rb +2 -2
  25. data/lib/ohai/plugins/linux/network.rb +11 -3
  26. data/lib/ohai/plugins/linux/platform.rb +14 -17
  27. data/lib/ohai/plugins/netbsd/network.rb +4 -8
  28. data/lib/ohai/plugins/netbsd/platform.rb +2 -4
  29. data/lib/ohai/plugins/network.rb +4 -3
  30. data/lib/ohai/plugins/openbsd/network.rb +4 -8
  31. data/lib/ohai/plugins/openbsd/platform.rb +2 -4
  32. data/lib/ohai/plugins/openstack.rb +2 -1
  33. data/lib/ohai/plugins/packages.rb +1 -1
  34. data/lib/ohai/plugins/passwd.rb +2 -1
  35. data/lib/ohai/plugins/rackspace.rb +3 -2
  36. data/lib/ohai/plugins/root_group.rb +1 -1
  37. data/lib/ohai/plugins/ruby.rb +4 -15
  38. data/lib/ohai/plugins/scaleway.rb +1 -1
  39. data/lib/ohai/plugins/shard.rb +1 -1
  40. data/lib/ohai/plugins/solaris2/dmi.rb +2 -3
  41. data/lib/ohai/plugins/solaris2/memory.rb +1 -2
  42. data/lib/ohai/plugins/solaris2/network.rb +2 -6
  43. data/lib/ohai/plugins/solaris2/platform.rb +1 -2
  44. data/lib/ohai/plugins/solaris2/virtualization.rb +2 -5
  45. data/lib/ohai/plugins/uptime.rb +1 -1
  46. data/lib/ohai/plugins/windows/dmi.rb +2 -2
  47. data/lib/ohai/plugins/windows/drivers.rb +1 -1
  48. data/lib/ohai/plugins/windows/memory.rb +1 -1
  49. data/lib/ohai/plugins/windows/network.rb +1 -1
  50. data/lib/ohai/plugins/windows/virtualization.rb +1 -1
  51. data/lib/ohai/runner.rb +1 -1
  52. data/lib/ohai/util/ip_helper.rb +2 -2
  53. data/lib/ohai/version.rb +1 -1
  54. data/ohai.gemspec +0 -1
  55. metadata +2 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7be1477adf0e463ac6149e5e3bb02ea983b8ea39197a84baf414472071b9f829
4
- data.tar.gz: a928b3b5b11a6230bed0a235cd06210c1d98c1c08f347d85390270d02123cdd5
3
+ metadata.gz: 68766eeef1353df87e6a89c047bfe2d056be75698cf3e5db73f093a0d40059c5
4
+ data.tar.gz: 39b483600849fe31706da87bf2c70eda6a7fa7dec69f1155d12ce49e124581c6
5
5
  SHA512:
6
- metadata.gz: 4033840091985804ad19aab09e79c516e2811149f4165d3b904cb497743e552757bf32b0d32f574c2451866f8267bf451c12f8f993677b509c7ab71d0446c9dd
7
- data.tar.gz: 4b889129b7d4838410f936182615ef4b071ca4edd53fbfd8a374a349f39d6a2e6e842499167fd39aa5ae38b5bd7ebf2d64d25b6564c5fbf8dbbc4b16b40d91c3
6
+ metadata.gz: 7730a85e74744663d1d7d282e07dbc249a4be8cfa0be63ee68b0e2fc09140c4053c0a97892295fcbf769c7653327898f77d1df482eb08734ce791cf4f6713aba
7
+ data.tar.gz: a299e3ebccb093d8bde8a0941ece0e8f085b496610623265e149aeefb545020cbfb497db85de53d0e1e1c640d2edce8f724b508d467d1cfdbbbea35a1edc0ef7
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
  # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
6
6
  group :development do
7
7
  gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
8
+ gem "rubocop-performance", "1.7.1"
8
9
  gem "rake", ">= 10.1.0"
9
10
  gem "rspec-core", "~> 3.0"
10
11
  gem "rspec-expectations", "~> 3.0"
@@ -24,4 +25,4 @@ group :debug do
24
25
  gem "pry-byebug"
25
26
  gem "pry-stack_explorer", "~> 0.4.0" # pin until we drop ruby < 2.6
26
27
  gem "rb-readline"
27
- end
28
+ end
@@ -18,9 +18,9 @@
18
18
  require "chef-config/path_helper"
19
19
  require "chef-config/workstation_config_loader"
20
20
  require_relative "../ohai"
21
- require_relative "log"
21
+ require_relative "log" unless defined?(Ohai::Log)
22
22
  require "mixlib/cli" unless defined?(Mixlib::CLI)
23
- require "benchmark"
23
+ require "benchmark" unless defined?(Benchmark)
24
24
 
25
25
  # The Application class is what is called by the Ohai CLI binary. It handles:
26
26
  # - CLI options and attribute arguments
@@ -71,8 +71,7 @@ module Ohai
71
71
  from = [ Ohai.config[:plugin_path], from].flatten
72
72
  plugin_files_by_dir(from).collect do |plugin_file|
73
73
  logger.trace "Loading additional plugin: #{plugin_file}"
74
- plugin = load_plugin_class(plugin_file)
75
- load_v7_plugin(plugin)
74
+ load_v7_plugin(load_plugin_class(plugin_file))
76
75
  end
77
76
  end
78
77
 
@@ -16,7 +16,7 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "mixlib/log"
19
+ require "mixlib/log" unless defined?(Mixlib::Log)
20
20
 
21
21
  module Ohai
22
22
  # the Ohai Logger which is just Mixlib::Log defaulting to STDERR and :info level
@@ -17,7 +17,7 @@
17
17
  # limitations under the License.
18
18
  #
19
19
 
20
- require "rbconfig"
20
+ require "rbconfig" unless defined?(RbConfig)
21
21
 
22
22
  module Ohai
23
23
  module Mixin
@@ -17,7 +17,7 @@
17
17
  # See the License for the specific language governing permissions and
18
18
  # limitations under the License.
19
19
 
20
- require "net/https"
20
+ require "net/http" unless defined?(Net::HTTP)
21
21
  require "uri" unless defined?(URI)
22
22
 
23
23
  # https://softlayer.github.io/reference/services/SoftLayer_Resource_Metadata/
@@ -19,7 +19,6 @@
19
19
  #
20
20
 
21
21
  Ohai.plugin(:Network) do
22
- require "ipaddr"
23
22
  require_relative "../../mixin/network_helper"
24
23
 
25
24
  provides "network", "counters/network", "macaddress"
@@ -27,6 +26,8 @@ Ohai.plugin(:Network) do
27
26
  include Ohai::Mixin::NetworkHelper
28
27
 
29
28
  collect_data(:aix) do
29
+ require "ipaddr" unless defined?(IPAddr)
30
+
30
31
  # Loads following information.
31
32
  # :default_interface, :default_gateway - route -n get 0
32
33
  # :interfaces
@@ -21,7 +21,7 @@ Ohai.plugin(:Uptime) do
21
21
  provides "uptime", "uptime_seconds"
22
22
 
23
23
  collect_data(:aix) do
24
- require "date"
24
+ require "date" unless defined?(DateTime)
25
25
  # below we're going to assume that PID 1 is init (this is true 99.99999% of the time)
26
26
  # output will look like this
27
27
  # 1148-20:54:50
@@ -320,7 +320,7 @@ Ohai.plugin(:Cloud) do
320
320
  end
321
321
 
322
322
  collect_data do
323
- require "ipaddr"
323
+ require "ipaddr" unless defined?(IPAddr)
324
324
 
325
325
  @cloud_attr_obj = CloudAttrs.new
326
326
 
@@ -377,7 +377,7 @@ Ohai.plugin(:CPU) do
377
377
  end
378
378
 
379
379
  collect_data(:windows) do
380
- require "wmi-lite/wmi"
380
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
381
381
 
382
382
  cpu Mash.new
383
383
  cores = 0
@@ -16,8 +16,6 @@
16
16
  #
17
17
 
18
18
  Ohai.plugin(:Docker) do
19
- require "json"
20
-
21
19
  provides "docker"
22
20
  depends "virtualization"
23
21
 
@@ -50,6 +48,8 @@ Ohai.plugin(:Docker) do
50
48
  end
51
49
 
52
50
  collect_data do
51
+ require "json" unless defined?(JSON)
52
+
53
53
  if virtualization[:systems][:docker]
54
54
  docker_ohai_data(docker_info_json)
55
55
  end
@@ -20,10 +20,8 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
 
22
22
  collect_data(:dragonflybsd) do
23
- so = shell_out("uname -s")
24
- platform so.stdout.split($/)[0].downcase
25
- so = shell_out("uname -r")
26
- platform_version so.stdout.split($/)[0]
23
+ platform shell_out("uname -s").stdout.split($/)[0].downcase
24
+ platform_version shell_out("uname -r").stdout.split($/)[0]
27
25
  platform_family "dragonflybsd"
28
26
  end
29
27
  end
@@ -28,7 +28,6 @@
28
28
  Ohai.plugin(:EC2) do
29
29
  require_relative "../mixin/ec2_metadata"
30
30
  require_relative "../mixin/http_helper"
31
- require "base64"
32
31
 
33
32
  include Ohai::Mixin::Ec2Metadata
34
33
  include Ohai::Mixin::HttpHelper
@@ -82,7 +81,7 @@ Ohai.plugin(:EC2) do
82
81
  # @return [Boolean] do we have a Xen Identifying Number or not?
83
82
  def has_ec2_identifying_number?
84
83
  if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
85
- require "wmi-lite/wmi"
84
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
86
85
  wmi = WmiLite::Wmi.new
87
86
  if /^ec2/.match?(wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"])
88
87
  logger.trace("Plugin EC2: has_ec2_identifying_number? == true")
@@ -115,6 +114,8 @@ Ohai.plugin(:EC2) do
115
114
  end
116
115
 
117
116
  collect_data do
117
+ require "base64"
118
+
118
119
  if looks_like_ec2?
119
120
  logger.trace("Plugin EC2: looks_like_ec2? == true")
120
121
  ec2 Mash.new
@@ -23,8 +23,6 @@
23
23
  # limitations under the License.
24
24
  #
25
25
 
26
- require "set"
27
-
28
26
  Ohai.plugin(:Filesystem) do
29
27
  provides "filesystem"
30
28
 
@@ -286,12 +284,10 @@ Ohai.plugin(:Filesystem) do
286
284
 
287
285
  # Grab filesystem data from df
288
286
  run_with_check("df") do
289
- so = shell_out("df -P")
290
- fs.merge!(parse_common_df(so.stdout))
287
+ fs.merge!(parse_common_df(shell_out("df -P").stdout))
291
288
 
292
289
  # Grab filesystem inode data from df
293
- so = shell_out("df -iP")
294
- so.stdout.each_line do |line|
290
+ shell_out("df -iP").stdout.each_line do |line|
295
291
  case line
296
292
  when /^Filesystem\s+Inodes/
297
293
  next
@@ -310,8 +306,7 @@ Ohai.plugin(:Filesystem) do
310
306
 
311
307
  # Grab mount information from /bin/mount
312
308
  run_with_check("mount") do
313
- so = shell_out("mount")
314
- so.stdout.each_line do |line|
309
+ shell_out("mount").stdout.each_line do |line|
315
310
  if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
316
311
  key = "#{$1},#{$2}"
317
312
  fs[key] ||= Mash.new
@@ -346,8 +341,7 @@ Ohai.plugin(:Filesystem) do
346
341
  # this is to allow machines with large amounts of attached LUNs
347
342
  # to respond back to the command successfully
348
343
  run_with_check(cmdtype) do
349
- so = shell_out(cmd, timeout: 60)
350
- so.stdout.each_line do |line|
344
+ shell_out(cmd, timeout: 60).stdout.each_line do |line|
351
345
  parsed = parse_line(line, cmdtype)
352
346
  next if parsed.nil?
353
347
 
@@ -383,7 +377,6 @@ Ohai.plugin(:Filesystem) do
383
377
  # we have to non-block read dev files. Ew.
384
378
  f = File.open("/proc/mounts")
385
379
  loop do
386
-
387
380
  data = f.read_nonblock(4096)
388
381
  mounts << data
389
382
  # We should just catch EOFError, but the kernel had a period of
@@ -392,9 +385,9 @@ Ohai.plugin(:Filesystem) do
392
385
  # whatever data we might have
393
386
  rescue Exception
394
387
  break
395
-
396
388
  end
397
389
  f.close
390
+
398
391
  mounts.each_line do |line|
399
392
  if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/
400
393
  key = "#{$1},#{$2}"
@@ -718,7 +711,8 @@ Ohai.plugin(:Filesystem) do
718
711
  end
719
712
 
720
713
  collect_data(:windows) do
721
- require "wmi-lite/wmi"
714
+ require "set" unless defined?(Set)
715
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
722
716
  require_relative "../mash"
723
717
 
724
718
  fs = merge_info(logical_info, encryptable_info)
@@ -29,10 +29,6 @@ Ohai.plugin(:Fips) do
29
29
  fips Mash.new
30
30
 
31
31
  require "openssl" unless defined?(OpenSSL)
32
- if defined?(OpenSSL.fips_mode) && OpenSSL.fips_mode && !$FIPS_TEST_MODE
33
- fips["kernel"] = { "enabled" => true }
34
- else
35
- fips["kernel"] = { "enabled" => false }
36
- end
32
+ fips["kernel"] = { "enabled" => OpenSSL::OPENSSL_FIPS }
37
33
  end
38
34
  end
@@ -20,10 +20,8 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
 
22
22
  collect_data(:freebsd) do
23
- so = shell_out("uname -s")
24
- platform so.stdout.split($/)[0].downcase
25
- so = shell_out("uname -r")
26
- platform_version so.stdout.split($/)[0]
23
+ platform shell_out("uname -s").stdout.split($/)[0].downcase
24
+ platform_version shell_out("uname -r").stdout.split($/)[0]
27
25
  platform_family "freebsd"
28
26
  end
29
27
  end
@@ -49,7 +49,7 @@ Ohai.plugin(:GCE) do
49
49
  # @return [Boolean] Are the manufacturer and model Google?
50
50
  def has_gce_system_info?
51
51
  if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
52
- require "wmi-lite/wmi"
52
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
53
53
  wmi = WmiLite::Wmi.new
54
54
  computer_system = wmi.first_of("Win32_ComputerSystem")
55
55
  if computer_system["Manufacturer"] =~ /^Google/ && computer_system["Model"] =~ /^Google/
@@ -26,9 +26,6 @@
26
26
  #
27
27
 
28
28
  Ohai.plugin(:Hostname) do
29
- require "socket" unless defined?(Socket)
30
- require "ipaddr"
31
-
32
29
  provides "domain", "hostname", "fqdn", "machinename"
33
30
 
34
31
  # hostname : short hostname
@@ -47,6 +44,9 @@ Ohai.plugin(:Hostname) do
47
44
  # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
48
45
  # this is ipv6-safe, works on ruby 1.8.7+
49
46
  def resolve_fqdn
47
+ require "socket" unless defined?(Socket)
48
+ require "ipaddr" unless defined?(IPAddr)
49
+
50
50
  hostname = from_cmd("hostname")
51
51
  addrinfo = Socket.getaddrinfo(hostname, nil).first
52
52
  iaddr = IPAddr.new(addrinfo[3])
@@ -161,7 +161,7 @@ Ohai.plugin(:Hostname) do
161
161
  end
162
162
 
163
163
  collect_data(:windows) do
164
- require "wmi-lite/wmi"
164
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
165
165
  require "socket" unless defined?(Socket)
166
166
 
167
167
  wmi = WmiLite::Wmi.new
@@ -252,7 +252,7 @@ Ohai.plugin(:Kernel) do
252
252
 
253
253
  collect_data(:windows) do
254
254
  require "win32ole" unless defined?(WIN32OLE)
255
- require "wmi-lite/wmi"
255
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
256
256
 
257
257
  WIN32OLE.codepage = WIN32OLE::CP_UTF8
258
258
 
@@ -24,8 +24,7 @@ Ohai.plugin(:Hostnamectl) do
24
24
 
25
25
  hostnamectl_path = which("hostnamectl")
26
26
  if hostnamectl_path
27
- hostnamectl_cmd = shell_out(hostnamectl_path)
28
- hostnamectl_cmd.stdout.split("\n").each do |line|
27
+ shell_out(hostnamectl_path).stdout.split("\n").each do |line|
29
28
  key, val = line.split(":")
30
29
  hostnamectl[key.chomp.lstrip.tr(" ", "_").downcase] = val.chomp.lstrip
31
30
  end
@@ -24,8 +24,7 @@ Ohai.plugin(:LSB) do
24
24
 
25
25
  if File.exist?("/usr/bin/lsb_release")
26
26
  # From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu
27
- so = shell_out("lsb_release -a")
28
- so.stdout.lines do |line|
27
+ shell_out("lsb_release -a").stdout.lines do |line|
29
28
  case line
30
29
  when /^Distributor ID:\s+(.+)$/
31
30
  lsb[:id] = $1
@@ -24,7 +24,6 @@ Ohai.plugin(:Lspci) do
24
24
 
25
25
  collect_data(:linux) do
26
26
  devices = Mash.new
27
- lspci = shell_out("lspci -vnnmk")
28
27
 
29
28
  h = /[0-9a-fA-F]/ # any hex digit
30
29
  hh = /#{h}#{h}/ # any 2 hex digits
@@ -46,7 +45,7 @@ Ohai.plugin(:Lspci) do
46
45
  end
47
46
  end
48
47
 
49
- lspci.stdout.split("\n").each do |line|
48
+ shell_out("lspci -vnnmk").stdout.split("\n").each do |line|
50
49
  dev = line.scan(/^(.*):\s(.*)$/)[0]
51
50
  next if dev.nil?
52
51
 
@@ -20,12 +20,12 @@ Ohai.plugin(:Machineid) do
20
20
  provides "machine_id"
21
21
 
22
22
  collect_data(:linux) do
23
- mid = nil
24
-
25
23
  if ::File.exist?("/etc/machine-id")
26
24
  mid = ::File.read("/etc/machine-id").chomp
27
25
  elsif ::File.exist?("/var/lib/dbus/machine-id")
28
26
  mid = ::File.read("/var/lib/dbus/machine-id").chomp
27
+ else
28
+ mid = nil
29
29
  end
30
30
 
31
31
  if mid
@@ -478,7 +478,7 @@ Ohai.plugin(:Network) do
478
478
 
479
479
  # returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
480
480
  def get_mac_for_interface(interfaces, interface)
481
- interfaces[interface][:addresses].select { |k, v| v["family"] == "lladdr" }.first.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
481
+ interfaces[interface][:addresses].find { |k, v| v["family"] == "lladdr" }.first unless interfaces[interface][:addresses].nil? || interfaces[interface][:flags].include?("NOARP")
482
482
  end
483
483
 
484
484
  # returns the default route with the lowest metric (unspecified metric is 0)
@@ -516,8 +516,16 @@ Ohai.plugin(:Network) do
516
516
  # if the route destination is a default route, it's good
517
517
  return true if route[:destination] == "default"
518
518
 
519
+ return false if default_route[:via].nil?
520
+
521
+ dest_ipaddr = IPAddr.new(route[:destination])
522
+ default_route_via = IPAddr.new(default_route[:via])
523
+
524
+ # check if nexthop is the same address family
525
+ return false if dest_ipaddr.ipv4? != default_route_via.ipv4?
526
+
519
527
  # the default route has a gateway and the route matches the gateway
520
- !default_route[:via].nil? && IPAddress(route[:destination]).include?(IPAddress(default_route[:via]))
528
+ dest_ipaddr.include?(default_route_via)
521
529
  end
522
530
 
523
531
  # ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
@@ -569,7 +577,7 @@ Ohai.plugin(:Network) do
569
577
  # If the 'ip' binary is available, this plugin may set {ip,mac,ip6}address. The network plugin should not overwrite these.
570
578
  # The older code section below that relies on the deprecated net-tools, e.g. netstat and ifconfig, provides less functionality.
571
579
  collect_data(:linux) do
572
- require "ipaddr"
580
+ require "ipaddr" unless defined?(IPAddr)
573
581
 
574
582
  iface = Mash.new
575
583
  net_counters = Mash.new
@@ -20,21 +20,6 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
  depends "lsb"
22
22
 
23
- # the platform mappings between the 'ID' field in /etc/os-release and the value
24
- # ohai uses. If you're adding a new platform here and you want to change the name
25
- # you'll want to add it here and then add a spec for the platform_id_remap method
26
- PLATFORM_MAPPINGS ||= {
27
- "rhel" => "redhat",
28
- "amzn" => "amazon",
29
- "ol" => "oracle",
30
- "sles" => "suse",
31
- "sles_sap" => "suse",
32
- "opensuse-leap" => "opensuseleap",
33
- "xenenterprise" => "xenserver",
34
- "cumulus-linux" => "cumulus",
35
- "archarm" => "arch",
36
- }.freeze
37
-
38
23
  # @deprecated
39
24
  def get_redhatish_platform(contents)
40
25
  contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase
@@ -122,8 +107,20 @@ Ohai.plugin(:Platform) do
122
107
  # this catches the centos guest shell in the nexus switch which identifies itself as centos
123
108
  return "nexus_centos" if id == "centos" && os_release_file_is_cisco?
124
109
 
125
- # remap based on the hash of platforms
126
- PLATFORM_MAPPINGS[id] || id
110
+ # the platform mappings between the 'ID' field in /etc/os-release and the value
111
+ # ohai uses. If you're adding a new platform here and you want to change the name
112
+ # you'll want to add it here and then add a spec for the platform_id_remap method
113
+ {
114
+ "rhel" => "redhat",
115
+ "amzn" => "amazon",
116
+ "ol" => "oracle",
117
+ "sles" => "suse",
118
+ "sles_sap" => "suse",
119
+ "opensuse-leap" => "opensuseleap",
120
+ "xenenterprise" => "xenserver",
121
+ "cumulus-linux" => "cumulus",
122
+ "archarm" => "arch",
123
+ }[id] || id
127
124
  end
128
125
 
129
126
  #
@@ -26,8 +26,7 @@ Ohai.plugin(:Network) do
26
26
  counters Mash.new unless counters
27
27
  counters[:network] ||= Mash.new
28
28
 
29
- so = shell_out("route -n get default")
30
- so.stdout.lines do |line|
29
+ shell_out("route -n get default").stdout.lines do |line|
31
30
  if line =~ /(\w+): ([\w\.]+)/
32
31
  case $1
33
32
  when "gateway"
@@ -39,9 +38,8 @@ Ohai.plugin(:Network) do
39
38
  end
40
39
 
41
40
  iface = Mash.new
42
- so = shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a")
43
41
  cint = nil
44
- so.stdout.lines do |line|
42
+ shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a").stdout.lines do |line|
45
43
  if line =~ /^([0-9a-zA-Z\.]+):\s+/
46
44
  cint = $1
47
45
  iface[cint] = Mash.new
@@ -85,8 +83,7 @@ Ohai.plugin(:Network) do
85
83
  end
86
84
  end
87
85
 
88
- so = shell_out("arp -an")
89
- so.stdout.lines do |line|
86
+ shell_out("arp -an").stdout.lines do |line|
90
87
  if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
91
88
  next unless iface[$3] # this should never happen
92
89
 
@@ -102,8 +99,7 @@ Ohai.plugin(:Network) do
102
99
  # Show the state of all network interfaces or a single interface
103
100
  # which have been auto-configured (interfaces statically configured
104
101
  # into a system, but not located at boot time are not shown).
105
- so = shell_out("netstat -idn")
106
- so.stdout.lines do |line|
102
+ shell_out("netstat -idn").stdout.lines do |line|
107
103
  # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop
108
104
  # em0 1500 <Link> 00:11:25:2d:90:be 3719557 0 3369969 0 0 0
109
105
  # $1 $2 $3 $4 $5 $6 $7 $8
@@ -20,10 +20,8 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
 
22
22
  collect_data(:netbsd) do
23
- so = shell_out("uname -s")
24
- platform so.stdout.split($/)[0].downcase
25
- so = shell_out("uname -r")
26
- platform_version so.stdout.split($/)[0]
23
+ platform shell_out("uname -s").stdout.split($/)[0].downcase
24
+ platform_version shell_out("uname -r").stdout.split($/)[0]
27
25
  platform_family "netbsd"
28
26
  end
29
27
  end
@@ -17,7 +17,6 @@
17
17
  #
18
18
 
19
19
  Ohai.plugin(:NetworkAddresses) do
20
- require "ipaddress"
21
20
  require_relative "../mixin/network_helper"
22
21
  include Ohai::Mixin::NetworkHelper
23
22
 
@@ -88,9 +87,9 @@ Ohai.plugin(:NetworkAddresses) do
88
87
  r = gw_if_ips.first
89
88
  else
90
89
  # checking network masks
91
- r = gw_if_ips.select do |v|
90
+ r = gw_if_ips.find do |v|
92
91
  network_contains_address(network[gw_attr], v[:ipaddress], v[:iface])
93
- end.first
92
+ end
94
93
  if r.nil?
95
94
  r = gw_if_ips.first
96
95
  logger.trace("Plugin Network: [#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}")
@@ -134,6 +133,8 @@ Ohai.plugin(:NetworkAddresses) do
134
133
  # time as ipaddress. if ipaddress is set and macaddress is nil, that means
135
134
  # the interface ipaddress is bound to has the NOARP flag
136
135
  collect_data do
136
+ require "ipaddress" unless defined?(IPAddress)
137
+
137
138
  results = {}
138
139
 
139
140
  network Mash.new unless network
@@ -26,8 +26,7 @@ Ohai.plugin(:Network) do
26
26
  counters Mash.new unless counters
27
27
  counters[:network] ||= Mash.new
28
28
 
29
- so = shell_out("route -n get default")
30
- so.stdout.lines do |line|
29
+ shell_out("route -n get default").stdout.lines do |line|
31
30
  if line =~ /(\w+): ([\w\.]+)/
32
31
  case $1
33
32
  when "gateway"
@@ -39,9 +38,8 @@ Ohai.plugin(:Network) do
39
38
  end
40
39
 
41
40
  iface = Mash.new
42
- so = shell_out( "#{Ohai.abs_path( "/sbin/ifconfig" )} -a" )
43
41
  cint = nil
44
- so.stdout.lines do |line|
42
+ shell_out( "#{Ohai.abs_path( "/sbin/ifconfig" )} -a" ).stdout.lines do |line|
45
43
  if line =~ /^([0-9a-zA-Z\.]+):\s+/
46
44
  cint = $1
47
45
  iface[cint] = Mash.new
@@ -85,8 +83,7 @@ Ohai.plugin(:Network) do
85
83
  end
86
84
  end
87
85
 
88
- so = shell_out("arp -an")
89
- so.stdout.lines do |line|
86
+ shell_out("arp -an").stdout.lines do |line|
90
87
  if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
91
88
  next unless iface[$3] # this should never happen
92
89
 
@@ -102,8 +99,7 @@ Ohai.plugin(:Network) do
102
99
  # Show the state of all network interfaces or a single interface
103
100
  # which have been auto-configured (interfaces statically configured
104
101
  # into a system, but not located at boot time are not shown).
105
- so = shell_out("netstat -idn")
106
- so.stdout.lines do |line|
102
+ shell_out("netstat -idn").stdout.lines do |line|
107
103
  # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop
108
104
  # em0 1500 <Link> 00:11:25:2d:90:be 3719557 0 3369969 0 0 0
109
105
  # $1 $2 $3 $4 $5 $6 $7 $8
@@ -20,10 +20,8 @@ Ohai.plugin(:Platform) do
20
20
  provides "platform", "platform_version", "platform_family"
21
21
 
22
22
  collect_data(:openbsd) do
23
- so = shell_out("uname -s")
24
- platform so.stdout.split($/)[0].downcase
25
- so = shell_out("uname -r")
26
- platform_version so.stdout.split($/)[0]
23
+ platform shell_out("uname -s").stdout.split($/)[0].downcase
24
+ platform_version shell_out("uname -r").stdout.split($/)[0]
27
25
  platform_family "openbsd"
28
26
  end
29
27
  end
@@ -19,7 +19,6 @@
19
19
  Ohai.plugin(:Openstack) do
20
20
  require_relative "../mixin/ec2_metadata"
21
21
  require_relative "../mixin/http_helper"
22
- require "etc" unless defined?(Etc)
23
22
  include Ohai::Mixin::Ec2Metadata
24
23
  include Ohai::Mixin::HttpHelper
25
24
 
@@ -59,6 +58,8 @@ Ohai.plugin(:Openstack) do
59
58
  end
60
59
 
61
60
  collect_data do
61
+ require "etc" unless defined?(Etc)
62
+
62
63
  # fetch data if we look like openstack
63
64
  if openstack_hint? || openstack_virtualization?
64
65
  openstack Mash.new
@@ -79,7 +79,7 @@ Ohai.plugin(:Packages) do
79
79
  end
80
80
 
81
81
  when "arch"
82
- require "date"
82
+ require "date" unless defined?(DateTime)
83
83
 
84
84
  # Set LANG=C to force an easy to parse date format
85
85
  so = shell_out("LANG=C pacman -Qi")
@@ -1,6 +1,5 @@
1
1
 
2
2
  Ohai.plugin(:Passwd) do
3
- require "etc" unless defined?(Etc)
4
3
  provides "etc", "current_user"
5
4
  optional true
6
5
 
@@ -14,6 +13,8 @@ Ohai.plugin(:Passwd) do
14
13
  end
15
14
 
16
15
  collect_data do
16
+ require "etc" unless defined?(Etc)
17
+
17
18
  unless etc
18
19
  etc Mash.new
19
20
 
@@ -15,7 +15,6 @@
15
15
  # limitations under the License.
16
16
 
17
17
  Ohai.plugin(:Rackspace) do
18
- require "resolv"
19
18
  provides "rackspace"
20
19
 
21
20
  depends "kernel", "network/interfaces"
@@ -50,7 +49,7 @@ Ohai.plugin(:Rackspace) do
50
49
  def has_rackspace_manufacturer?
51
50
  return false unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
52
51
 
53
- require "wmi-lite/wmi"
52
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
54
53
  wmi = WmiLite::Wmi.new
55
54
  if wmi.first_of("Win32_ComputerSystem")["PrimaryOwnerName"] == "Rackspace"
56
55
  logger.trace("Plugin Rackspace: has_rackspace_manufacturer? == true")
@@ -147,6 +146,8 @@ Ohai.plugin(:Rackspace) do
147
146
  end
148
147
 
149
148
  collect_data do
149
+ require "resolv"
150
+
150
151
  # Adds rackspace Mash
151
152
  if looks_like_rackspace?
152
153
  rackspace Mash.new
@@ -19,7 +19,7 @@ Ohai.plugin(:RootGroup) do
19
19
  provides "root_group"
20
20
 
21
21
  collect_data(:windows) do
22
- require "wmi-lite/wmi"
22
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
23
23
 
24
24
  wmi = WmiLite::Wmi.new
25
25
  # Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@chef.io>)
3
- # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -43,6 +43,8 @@ Ohai.plugin(:Ruby) do
43
43
  host_vendor: "RbConfig::CONFIG['host_vendor']",
44
44
  bin_dir: "RbConfig::CONFIG['bindir']",
45
45
  ruby_bin: "::File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])",
46
+ gem_bin: "::File.join(RbConfig::CONFIG['bindir'], ::Gem.default_exec_format % 'gem')",
47
+ gems_dir: "::Gem.dir",
46
48
  }
47
49
 
48
50
  # Create a query string from above hash
@@ -52,25 +54,12 @@ Ohai.plugin(:Ruby) do
52
54
  end
53
55
 
54
56
  # Query the system ruby
55
- result = run_ruby "puts %Q(#{env_string})"
57
+ result = run_ruby "require 'rubygems'; puts %Q(#{env_string})"
56
58
 
57
59
  # Parse results to plugin hash
58
60
  result.split(",").each do |entry|
59
61
  key, value = entry.split("=")
60
62
  languages[:ruby][key.to_sym] = value || ""
61
63
  end
62
-
63
- # Perform one more (conditional) query
64
- bin_dir = languages[:ruby][:bin_dir]
65
- ruby_bin = languages[:ruby][:ruby_bin]
66
- gem_binaries = [
67
- run_ruby("require 'rubygems'; puts ::Gem.default_exec_format % 'gem'"),
68
- "gem",
69
- ].map { |bin| ::File.join(bin_dir, bin) }
70
- gem_binary = gem_binaries.find { |bin| ::File.exist? bin }
71
- if gem_binary
72
- languages[:ruby][:gems_dir] = run_ruby "puts %x{#{ruby_bin} #{gem_binary} env gemdir}.chomp!"
73
- languages[:ruby][:gem_bin] = gem_binary
74
- end
75
64
  end
76
65
  end
@@ -26,7 +26,7 @@ Ohai.plugin(:Scaleway) do
26
26
  # looks for `scaleway` keyword in kernel command line
27
27
  # @return [Boolean] do we have the keyword or not?
28
28
  def has_scaleway_cmdline?
29
- if ::File.read("/proc/cmdline") =~ /scaleway/
29
+ if ::File.exist?("/proc/cmdline") && /scaleway/.match?(::File.read("/proc/cmdline"))
30
30
  logger.trace("Plugin Scaleway: has_scaleway_cmdline? == true")
31
31
  return true
32
32
  end
@@ -94,7 +94,7 @@ Ohai.plugin(:ShardSeed) do
94
94
  end
95
95
 
96
96
  collect_data(:windows) do
97
- require "wmi-lite/wmi"
97
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
98
98
  wmi = WmiLite::Wmi.new
99
99
 
100
100
  create_seed do |src|
@@ -86,7 +86,7 @@ Ohai.plugin(:DMI) do
86
86
  "SUN_OEM_EXT_MEMARRAY" => 144, # phys memory array extended info
87
87
  "SUN_OEM_EXT_MEMDEVICE" => 145, # memory device extended info
88
88
  "SMB_TYPE_OEM_HI" => 256, # end of OEM-specific type range
89
- }
89
+ }.freeze
90
90
 
91
91
  # all output lines should fall within one of these patterns
92
92
  header_type_line = /^ID\s+SIZE\s+TYPE/
@@ -99,7 +99,6 @@ Ohai.plugin(:DMI) do
99
99
  dmi_record = nil
100
100
  field = nil
101
101
 
102
- so = shell_out("smbios")
103
102
  # ==== EXAMPLE: ====
104
103
  # ID SIZE TYPE
105
104
  # 0 40 SMB_TYPE_BIOS (BIOS information)
@@ -111,7 +110,7 @@ Ohai.plugin(:DMI) do
111
110
  # SMB_BIOSFL_PCI (PCI is supported)
112
111
  # ... similar lines trimmed
113
112
  # note the second level of indentation is via a *tab*
114
- so.stdout.lines do |raw_line|
113
+ shell_out("smbios").stdout.lines do |raw_line|
115
114
  next if header_type_line.match(raw_line)
116
115
  next if blank_line.match(raw_line)
117
116
 
@@ -20,8 +20,7 @@ Ohai.plugin(:Memory) do
20
20
  collect_data(:solaris2) do
21
21
  memory Mash.new
22
22
  memory[:swap] = Mash.new
23
- meminfo = shell_out("prtconf | grep Memory").stdout
24
- memory[:total] = "#{meminfo.split[2].to_i * 1024}kB"
23
+ memory[:total] = "#{shell_out("prtconf | grep Memory").stdout.split[2].to_i * 1024}kB"
25
24
 
26
25
  tokens = shell_out("swap -s").stdout.strip.split
27
26
  used_swap = tokens[8][0..-1].to_i # strip k from end
@@ -54,13 +54,11 @@
54
54
  # inet6 fe80::203:baff:fe17:4444/128
55
55
 
56
56
  # Extracted from http://illumos.org/hcl/
57
- unless defined?(ETHERNET_ENCAPS)
58
- ETHERNET_ENCAPS = %w{ afe amd8111s arn atge ath bfe bge bnx bnxe ce cxgbe
57
+ ETHERNET_ENCAPS ||= %w{ afe amd8111s arn atge ath bfe bge bnx bnxe ce cxgbe
59
58
  dmfe e1000g efe elxl emlxs eri hermon hme hxge igb
60
59
  iprb ipw iwh iwi iwk iwp ixgb ixgbe mwl mxfe myri10ge
61
60
  nge ntxn nxge pcn platform qfe qlc ral rge rtls rtw rwd
62
61
  rwn sfe tavor vr wpi xge yge aggr}.freeze
63
- end
64
62
 
65
63
  Ohai.plugin(:Network) do
66
64
  require_relative "../../mixin/network_helper"
@@ -102,10 +100,8 @@ Ohai.plugin(:Network) do
102
100
  counters Mash.new unless counters
103
101
  counters[:network] ||= Mash.new
104
102
 
105
- so = shell_out("ifconfig -a")
106
103
  cint = nil
107
-
108
- so.stdout.lines do |line|
104
+ shell_out("ifconfig -a").stdout.lines do |line|
109
105
  # regex: https://rubular.com/r/ZiIHbsnfiWPW1p
110
106
  if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+)(?: index (\d+))?/
111
107
  cint = $1
@@ -26,8 +26,7 @@ Ohai.plugin(:Platform) do
26
26
  uname_exec = "uname"
27
27
  end
28
28
 
29
- so = shell_out("#{uname_exec} -X")
30
- so.stdout.lines do |line|
29
+ shell_out("#{uname_exec} -X").stdout.lines do |line|
31
30
  case line
32
31
  when /^Release =\s+(.+)$/
33
32
  platform_version $1
@@ -25,9 +25,7 @@ Ohai.plugin(:Virtualization) do
25
25
  depends "dmi"
26
26
 
27
27
  def collect_solaris_guestid
28
- command = "/usr/sbin/zoneadm list -p"
29
- so = shell_out(command)
30
- so.stdout.split(":").first
28
+ shell_out("/usr/sbin/zoneadm list -p").stdout.split(":").first
31
29
  end
32
30
 
33
31
  collect_data(:solaris2) do
@@ -56,8 +54,7 @@ Ohai.plugin(:Virtualization) do
56
54
 
57
55
  if File.executable?("/usr/sbin/zoneadm")
58
56
  zones = Mash.new
59
- so = shell_out("zoneadm list -pc")
60
- so.stdout.lines do |line|
57
+ shell_out("zoneadm list -pc").stdout.lines do |line|
61
58
  info = line.chomp.split(/:/)
62
59
  zones[info[1]] = {
63
60
  "id" => info[0],
@@ -84,7 +84,7 @@ Ohai.plugin(:Uptime) do
84
84
  end
85
85
 
86
86
  collect_data(:windows) do
87
- require "wmi-lite/wmi"
87
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
88
88
  wmi = WmiLite::Wmi.new
89
89
  last_boot_up_time = wmi.first_of("Win32_OperatingSystem")["lastbootuptime"]
90
90
  uptime_seconds Time.new.to_i - Time.parse(last_boot_up_time).to_i
@@ -45,8 +45,8 @@ Ohai.plugin(:DMI) do
45
45
  ].freeze
46
46
 
47
47
  collect_data(:windows) do
48
- require "ohai/common/dmi"
49
- require "wmi-lite/wmi"
48
+ require_relative "../../common/dmi"
49
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
50
50
  wmi = WmiLite::Wmi.new
51
51
 
52
52
  dmi Mash.new
@@ -22,7 +22,7 @@ Ohai.plugin(:Drivers) do
22
22
  collect_data(:windows) do
23
23
  if configuration(:enabled)
24
24
 
25
- require "wmi-lite/wmi"
25
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
26
26
 
27
27
  kext = Mash.new
28
28
  pnp_drivers = Mash.new
@@ -17,7 +17,7 @@ Ohai.plugin(:Memory) do
17
17
  provides "memory"
18
18
 
19
19
  collect_data(:windows) do
20
- require "wmi-lite/wmi"
20
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
21
21
 
22
22
  memory Mash.new
23
23
  memory[:swap] = Mash.new
@@ -118,7 +118,7 @@ Ohai.plugin(:Network) do
118
118
 
119
119
  collect_data(:windows) do
120
120
 
121
- require "wmi-lite/wmi"
121
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
122
122
 
123
123
  iface = Mash.new
124
124
  iface_config = Mash.new
@@ -24,7 +24,7 @@ Ohai.plugin(:Virtualization) do
24
24
  include Ohai::Mixin::DmiDecode
25
25
 
26
26
  collect_data(:windows) do
27
- require "wmi-lite/wmi"
27
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
28
28
 
29
29
  virtualization Mash.new unless virtualization
30
30
  virtualization[:systems] ||= Mash.new
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  require_relative "dsl"
21
- require "benchmark"
21
+ require "benchmark" unless defined?(Benchmark)
22
22
 
23
23
  module Ohai
24
24
  class Runner
@@ -14,11 +14,11 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "ipaddress"
18
-
19
17
  module Ohai
20
18
  module Util
21
19
  module IpHelper
20
+ require "ipaddress" unless defined?(IPAddress)
21
+
22
22
  # Corresponding to RFC 4192 + RFC 4193
23
23
  IPV6_LINK_LOCAL_UNICAST_BLOCK = IPAddress("fe80::/10")
24
24
  IPV6_PRIVATE_ADDRESS_BLOCK = IPAddress("fc00::/7")
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "16.3.2".freeze
21
+ VERSION = "16.4.11".freeze
22
22
  end
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.required_ruby_version = ">= 2.5"
16
16
 
17
- s.add_dependency "systemu", "~> 2.6.4"
18
17
  s.add_dependency "ffi-yajl", "~> 2.2"
19
18
  s.add_dependency "mixlib-cli", ">= 1.7.0" # 1.7+ needed to support passing multiple options
20
19
  s.add_dependency "mixlib-config", ">= 2.0", "< 4.0"
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 16.3.2
4
+ version: 16.4.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-28 00:00:00.000000000 Z
11
+ date: 2020-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: systemu
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 2.6.4
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 2.6.4
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: ffi-yajl
29
15
  requirement: !ruby/object:Gem::Requirement