ohai 16.2.1 → 16.4.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -1
  3. data/bin/ohai +0 -2
  4. data/lib/ohai/application.rb +2 -2
  5. data/lib/ohai/dsl/plugin.rb +1 -1
  6. data/lib/ohai/loader.rb +1 -2
  7. data/lib/ohai/log.rb +1 -1
  8. data/lib/ohai/mixin/command.rb +1 -1
  9. data/lib/ohai/mixin/dmi_decode.rb +2 -2
  10. data/lib/ohai/mixin/os.rb +1 -1
  11. data/lib/ohai/mixin/softlayer_metadata.rb +1 -1
  12. data/lib/ohai/plugins/aix/memory.rb +3 -3
  13. data/lib/ohai/plugins/aix/network.rb +2 -1
  14. data/lib/ohai/plugins/aix/uptime.rb +2 -2
  15. data/lib/ohai/plugins/aix/virtualization.rb +5 -5
  16. data/lib/ohai/plugins/azure.rb +1 -1
  17. data/lib/ohai/plugins/bsd/virtualization.rb +2 -2
  18. data/lib/ohai/plugins/c.rb +2 -2
  19. data/lib/ohai/plugins/cloud.rb +1 -1
  20. data/lib/ohai/plugins/cpu.rb +2 -2
  21. data/lib/ohai/plugins/darwin/network.rb +3 -3
  22. data/lib/ohai/plugins/darwin/virtualization.rb +1 -1
  23. data/lib/ohai/plugins/docker.rb +2 -2
  24. data/lib/ohai/plugins/dragonflybsd/platform.rb +2 -4
  25. data/lib/ohai/plugins/ec2.rb +8 -7
  26. data/lib/ohai/plugins/eucalyptus.rb +1 -1
  27. data/lib/ohai/plugins/filesystem.rb +11 -17
  28. data/lib/ohai/plugins/fips.rb +1 -5
  29. data/lib/ohai/plugins/freebsd/platform.rb +2 -4
  30. data/lib/ohai/plugins/gce.rb +3 -3
  31. data/lib/ohai/plugins/hostname.rb +16 -16
  32. data/lib/ohai/plugins/kernel.rb +1 -1
  33. data/lib/ohai/plugins/linux/hostnamectl.rb +1 -2
  34. data/lib/ohai/plugins/linux/interrupts.rb +1 -1
  35. data/lib/ohai/plugins/linux/lsb.rb +1 -2
  36. data/lib/ohai/plugins/linux/lspci.rb +1 -2
  37. data/lib/ohai/plugins/linux/machineid.rb +2 -2
  38. data/lib/ohai/plugins/linux/mdadm.rb +1 -1
  39. data/lib/ohai/plugins/linux/network.rb +19 -9
  40. data/lib/ohai/plugins/linux/platform.rb +22 -25
  41. data/lib/ohai/plugins/linux/virtualization.rb +12 -9
  42. data/lib/ohai/plugins/netbsd/network.rb +4 -8
  43. data/lib/ohai/plugins/netbsd/platform.rb +2 -4
  44. data/lib/ohai/plugins/network.rb +5 -4
  45. data/lib/ohai/plugins/openbsd/network.rb +4 -8
  46. data/lib/ohai/plugins/openbsd/platform.rb +2 -4
  47. data/lib/ohai/plugins/openstack.rb +3 -2
  48. data/lib/ohai/plugins/packages.rb +1 -1
  49. data/lib/ohai/plugins/passwd.rb +2 -1
  50. data/lib/ohai/plugins/rackspace.rb +5 -4
  51. data/lib/ohai/plugins/root_group.rb +1 -1
  52. data/lib/ohai/plugins/ruby.rb +4 -15
  53. data/lib/ohai/plugins/scaleway.rb +1 -1
  54. data/lib/ohai/plugins/shard.rb +1 -1
  55. data/lib/ohai/plugins/solaris2/dmi.rb +2 -3
  56. data/lib/ohai/plugins/solaris2/memory.rb +1 -2
  57. data/lib/ohai/plugins/solaris2/network.rb +2 -6
  58. data/lib/ohai/plugins/solaris2/platform.rb +1 -2
  59. data/lib/ohai/plugins/solaris2/virtualization.rb +3 -6
  60. data/lib/ohai/plugins/ssh_host_key.rb +1 -1
  61. data/lib/ohai/plugins/uptime.rb +1 -1
  62. data/lib/ohai/plugins/vmware.rb +2 -2
  63. data/lib/ohai/plugins/windows/dmi.rb +2 -2
  64. data/lib/ohai/plugins/windows/drivers.rb +1 -1
  65. data/lib/ohai/plugins/windows/memory.rb +1 -1
  66. data/lib/ohai/plugins/windows/network.rb +4 -4
  67. data/lib/ohai/plugins/windows/platform.rb +1 -1
  68. data/lib/ohai/plugins/windows/virtualization.rb +1 -1
  69. data/lib/ohai/provides_map.rb +2 -2
  70. data/lib/ohai/runner.rb +1 -1
  71. data/lib/ohai/util/ip_helper.rb +2 -2
  72. data/lib/ohai/util/win32.rb +1 -1
  73. data/lib/ohai/version.rb +1 -1
  74. data/ohai.gemspec +0 -1
  75. metadata +2 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37943a2c27d2555576202a2ffdcb3ed104e0cd84d0e36c3dedb5ff7bfc1a5cd4
4
- data.tar.gz: 50e8c6f17fc1560ab2c6a41c2e56adb1b800bf15ad64a1ce058334e3f491b0a3
3
+ metadata.gz: 6a41b8cc8fc0d00fb8816f241f080d183be4b5b4019be40a6e6ab5603d4ab5c5
4
+ data.tar.gz: adc92d0dcb0c5a5490aa842cd513c761fe984dc6a4aeb5cafdbc7cc8f705d61f
5
5
  SHA512:
6
- metadata.gz: 7f5592b7e32c859831984be689ddbdfe19411a3efdbec7223c4f48e905b81c06a261286e150007091522f6f9eb2a231f83bd86e79231a4fed710ff76c0acdfa0
7
- data.tar.gz: e516682f83325f096ebd89a12b197afb091fad3708cbd009e1936edc7597ed78e574786e4f306e53d1fb97626e0b92ffafbf78e79fac9d1f5d369baeb387a793
6
+ metadata.gz: dd143425b3e1bcd9ef730496e890f41107f9676185bede8b8a8ce2a26cb4f007326d9023121396526c85426f9d07de36a7a5d448e76ad3efe1dcbb0c6fffa186
7
+ data.tar.gz: 2b93a5ed54f74514be768879bbac6b068c697b09d735258d7716800c2367bad16522b9124a202b9824eb627b45021ab8404ae803f43109a3e5531aec35518f58
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
data/bin/ohai CHANGED
@@ -1,7 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  #
3
- # ./ohai - I'm in ur serverz, showin you the daters
4
- #
5
3
  # Author:: Adam Jacob (<adam@chef.io>)
6
4
  # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc.
7
5
  # License:: Apache License, Version 2.0
@@ -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
@@ -65,7 +65,7 @@ module Ohai
65
65
  #
66
66
  # @return [String]
67
67
  def self.dev_null
68
- if RUBY_PLATFORM =~ /mswin|mingw|windows/
68
+ if RUBY_PLATFORM.match?(/mswin|mingw|windows/)
69
69
  "NUL"
70
70
  else
71
71
  "/dev/null"
@@ -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
@@ -30,7 +30,7 @@ module Ohai
30
30
  options = options.dup
31
31
  # unless specified by the caller timeout after configured timeout (default 30 seconds)
32
32
  options[:timeout] ||= Ohai::Config.ohai[:shellout_timeout]
33
- unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
33
+ unless RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
34
34
  options[:env] = options.key?(:env) ? options[:env].dup : {}
35
35
  options[:env]["PATH"] ||= ((ENV["PATH"] || "").split(":") + %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}).join(":")
36
36
  end
@@ -26,7 +26,7 @@ module ::Ohai::Mixin::DmiDecode
26
26
  when /VMware/
27
27
  return "vmware"
28
28
  when /Microsoft/
29
- return "hyperv" if product =~ /Virtual Machine/
29
+ return "hyperv" if /Virtual Machine/.match?(product)
30
30
  when /Amazon EC2/
31
31
  return "amazonec2"
32
32
  when /QEMU/
@@ -40,7 +40,7 @@ module ::Ohai::Mixin::DmiDecode
40
40
  case product
41
41
  when /VirtualBox/
42
42
  return "vbox"
43
- when /OpenStack/ # yes this is here twice. Product catches Redhat's version
43
+ when /OpenStack/ # yes this is here twice. Product catches Red Hat's version
44
44
  return "openstack"
45
45
  when /(KVM|RHEV)/
46
46
  return "kvm"
@@ -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/
@@ -29,8 +29,8 @@ Ohai.plugin(:Memory) do
29
29
  memory[:total] = "#{total_in_mb.to_i * 1024}kB"
30
30
  memory[:free] = "#{free_in_mb.to_i * 1024}kB"
31
31
 
32
- swapinfo = shell_out("swap -s").stdout.split # returns swap info in 4K blocks
33
- memory[:swap]["total"] = "#{(swapinfo[2].to_i) * 4}kB"
34
- memory[:swap]["free"] = "#{(swapinfo[10].to_i) * 4}kB"
32
+ swap_info = shell_out("swap -s").stdout.split # returns swap info in 4K blocks
33
+ memory[:swap]["total"] = "#{(swap_info[2].to_i) * 4}kB"
34
+ memory[:swap]["free"] = "#{(swap_info[10].to_i) * 4}kB"
35
35
  end
36
36
  end
@@ -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
@@ -30,7 +30,7 @@ Ohai.plugin(:Uptime) do
30
30
  so = shell_out("LC_ALL=POSIX ps -o etime= -p 1").stdout.strip
31
31
 
32
32
  # Here we'll check our shell_out for a dash, which indicates there is a # of days involved
33
- # We'll chunk off the days, hours (where applicable), minutes, seconds into seperate vars
33
+ # We'll chunk off the days, hours (where applicable), minutes, seconds into separate vars
34
34
  # We also need to do this because ps -o etime= will not display days if the machine has been up for less than 24 hours
35
35
  # If the machine has been up for less than one hour, the shell_out will not output hours hence our else
36
36
  # see here: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds4/ps.htm#ps__row-d3e109655
@@ -57,7 +57,7 @@ Ohai.plugin(:Virtualization) do
57
57
  sections.each do |line|
58
58
  case title
59
59
  when "network"
60
- next if line =~ /^Interface|^---/
60
+ next if /^Interface|^---/.match?(line)
61
61
 
62
62
  splat = line.strip.split
63
63
  key = splat[0].downcase
@@ -68,7 +68,7 @@ Ohai.plugin(:Virtualization) do
68
68
  }
69
69
  wpars[wpar_name][title][key] = value
70
70
  when "user-specified routes"
71
- next if line =~ /^Type|^---/
71
+ next if /^Type|^---/.match?(line)
72
72
 
73
73
  splat = line.strip.split
74
74
  key = splat[2].downcase
@@ -78,7 +78,7 @@ Ohai.plugin(:Virtualization) do
78
78
  }
79
79
  wpars[wpar_name][title][key] = value
80
80
  when "file systems"
81
- next if line =~ /^MountPoint|^---/
81
+ next if /^MountPoint|^---/.match?(line)
82
82
 
83
83
  splat = line.strip.split
84
84
  key = splat[1].downcase
@@ -93,7 +93,7 @@ Ohai.plugin(:Virtualization) do
93
93
  privileges ||= ""
94
94
  wpars[wpar_name][title]["Privileges"] ||= []
95
95
 
96
- if line =~ /^Privileges/
96
+ if /^Privileges/.match?(line)
97
97
  privileges << line.split(":")[1].strip
98
98
  else
99
99
  privileges << line.strip
@@ -101,7 +101,7 @@ Ohai.plugin(:Virtualization) do
101
101
 
102
102
  wpars[wpar_name][title]["Privileges"] += privileges.split(",")
103
103
  when "device exports"
104
- next if line =~ /^Name|^---/
104
+ next if /^Name|^---/.match?(line)
105
105
 
106
106
  splat = line.strip.split
107
107
  key = splat[0].downcase
@@ -57,7 +57,7 @@ Ohai.plugin(:Azure) do
57
57
  has_245 = false
58
58
  if File.exist?("/var/lib/dhcp/dhclient.eth0.leases")
59
59
  File.open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
60
- if line =~ /unknown-245/
60
+ if /unknown-245/.match?(line)
61
61
  logger.trace("Plugin Azure: Found unknown-245 DHCP option used by Azure.")
62
62
  has_245 = true
63
63
  break
@@ -76,7 +76,7 @@ Ohai.plugin(:Virtualization) do
76
76
  # Detect KVM/QEMU paravirt guests from cpu, report as KVM
77
77
  # hw.model: QEMU Virtual CPU version 0.9.1
78
78
  so = shell_out("sysctl -n hw.model")
79
- if so.stdout =~ /QEMU Virtual CPU|KVM processor/
79
+ if /QEMU Virtual CPU|KVM processor/.match?(so.stdout)
80
80
  virtualization[:system] = "kvm"
81
81
  virtualization[:role] = "guest"
82
82
  virtualization[:systems][:kvm] = "guest"
@@ -96,7 +96,7 @@ Ohai.plugin(:Virtualization) do
96
96
  "xen"
97
97
  when /kvm/
98
98
  so = shell_out("sysctl -n kern.hostuuid")
99
- so.stdout =~ /^ec2/ ? "amazonec2" : "kvm"
99
+ /^ec2/.match?(so.stdout) ? "amazonec2" : "kvm"
100
100
  when /bhyve/
101
101
  "bhyve"
102
102
  end
@@ -137,7 +137,7 @@ Ohai.plugin(:C) do
137
137
  logger.trace("Plugin C: 'xlc' binary could not be found. Skipping data.")
138
138
  end
139
139
 
140
- def collect_sunpro
140
+ def collect_sun_pro
141
141
  # sun pro
142
142
  collect("cc -V -flags") do |so|
143
143
  output = so.stderr.split
@@ -173,7 +173,7 @@ Ohai.plugin(:C) do
173
173
  @c = Mash.new
174
174
  collect_gcc
175
175
  collect_glibc
176
- collect_sunpro
176
+ collect_sun_pro
177
177
  languages[:c] = @c unless @c.empty?
178
178
  end
179
179
  end
@@ -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
 
@@ -305,7 +305,7 @@ Ohai.plugin(:CPU) do
305
305
  cpu[index] = Mash.new
306
306
  cpu[index][:status] = status
307
307
  cpu[index][:location] = location
308
- if status =~ /Available/
308
+ if /Available/.match?(status)
309
309
  cpu[:available] += 1
310
310
  lsattr = shell_out("lsattr -El #{name}").stdout.lines
311
311
  lsattr.each do |attribute|
@@ -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
@@ -66,8 +66,8 @@ Ohai.plugin(:Network) do
66
66
 
67
67
  def scope_lookup(scope)
68
68
  return "Node" if scope.eql?("::1")
69
- return "Link" if scope =~ /^fe80\:/
70
- return "Site" if scope =~ /^fec0\:/
69
+ return "Link" if /^fe80\:/.match?(scope)
70
+ return "Site" if /^fec0\:/.match?(scope)
71
71
 
72
72
  "Global"
73
73
  end
@@ -79,7 +79,7 @@ Ohai.plugin(:Network) do
79
79
  def locate_interface(ifaces, ifname, mac)
80
80
  return ifname unless ifaces[ifname].nil?
81
81
  # oh well, time to go hunting!
82
- return ifname.chop if ifname =~ /\*$/
82
+ return ifname.chop if /\*$/.match?(ifname)
83
83
 
84
84
  ifaces.each_key do |ifc|
85
85
  ifaces[ifc][:addresses].each_key do |addr|
@@ -82,7 +82,7 @@ Ohai.plugin(:Virtualization) do
82
82
  virtualization[:systems][:parallels] = "host"
83
83
  elsif ioreg_exists?
84
84
  so = shell_out("ioreg -l")
85
- if so.stdout =~ /pci1ab8,4000/
85
+ if /pci1ab8,4000/.match?(so.stdout)
86
86
  virtualization[:system] = "parallels"
87
87
  virtualization[:role] = "guest"
88
88
  virtualization[:systems][:parallels] = "guest"
@@ -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
@@ -41,7 +40,7 @@ Ohai.plugin(:EC2) do
41
40
  # @return [Boolean] do we have Amazon DMI data?
42
41
  def has_ec2_amazon_dmi?
43
42
  # detect a version of '4.2.amazon'
44
- if file_val_if_exists("/sys/class/dmi/id/bios_vendor") =~ /Amazon/
43
+ if /Amazon/.match?(file_val_if_exists("/sys/class/dmi/id/bios_vendor"))
45
44
  logger.trace("Plugin EC2: has_ec2_amazon_dmi? == true")
46
45
  true
47
46
  else
@@ -56,7 +55,7 @@ Ohai.plugin(:EC2) do
56
55
  # @return [Boolean] do we have Amazon DMI data?
57
56
  def has_ec2_xen_dmi?
58
57
  # detect a version of '4.2.amazon'
59
- if file_val_if_exists("/sys/class/dmi/id/bios_version") =~ /amazon/
58
+ if /amazon/.match?(file_val_if_exists("/sys/class/dmi/id/bios_version"))
60
59
  logger.trace("Plugin EC2: has_ec2_xen_dmi? == true")
61
60
  true
62
61
  else
@@ -68,7 +67,7 @@ Ohai.plugin(:EC2) do
68
67
  # looks for a xen UUID that starts with ec2 from within the Linux sys tree
69
68
  # @return [Boolean] do we have a Xen UUID or not?
70
69
  def has_ec2_xen_uuid?
71
- if file_val_if_exists("/sys/hypervisor/uuid") =~ /^ec2/
70
+ if /^ec2/.match?(file_val_if_exists("/sys/hypervisor/uuid"))
72
71
  logger.trace("Plugin EC2: has_ec2_xen_uuid? == true")
73
72
  return true
74
73
  end
@@ -81,10 +80,10 @@ Ohai.plugin(:EC2) do
81
80
  # linux hosts
82
81
  # @return [Boolean] do we have a Xen Identifying Number or not?
83
82
  def has_ec2_identifying_number?
84
- if RUBY_PLATFORM =~ /mswin|mingw32|windows/
85
- require "wmi-lite/wmi"
83
+ if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
84
+ require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
86
85
  wmi = WmiLite::Wmi.new
87
- if wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"] =~ /^ec2/
86
+ if /^ec2/.match?(wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"])
88
87
  logger.trace("Plugin EC2: has_ec2_identifying_number? == true")
89
88
  true
90
89
  end
@@ -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
@@ -42,7 +42,7 @@ Ohai.plugin(:Eucalyptus) do
42
42
  def has_euca_mac?
43
43
  network[:interfaces].each_value do |iface|
44
44
  mac = get_mac_address(iface[:addresses])
45
- if mac =~ /^[dD]0:0[dD]:/
45
+ if /^[dD]0:0[dD]:/.match?(mac)
46
46
  logger.trace("Plugin Eucalyptus: has_euca_mac? == true (#{mac})")
47
47
  return true
48
48
  end
@@ -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}"
@@ -590,16 +583,16 @@ Ohai.plugin(:Filesystem) do
590
583
  end
591
584
  end
592
585
 
593
- zfs.each do |fsname, attributes|
586
+ zfs.each do |fs_name, attributes|
594
587
  mountpoint = attributes[:mountpoint][:value] if attributes[:mountpoint]
595
- key = "#{fsname},#{mountpoint}"
588
+ key = "#{fs_name},#{mountpoint}"
596
589
  fs[key] ||= Mash.new
597
590
  fs[key][:fs_type] = "zfs"
598
591
  fs[key][:mount] = mountpoint if mountpoint
599
- fs[key][:device] = fsname
592
+ fs[key][:device] = fs_name
600
593
  fs[key][:zfs_properties] = attributes
601
594
  # find all zfs parents
602
- parents = fsname.split("/")
595
+ parents = fs_name.split("/")
603
596
  zfs_parents = []
604
597
  (0..parents.length - 1).to_a.each do |parent_index|
605
598
  next_parent = parents[0..parent_index].join("/")
@@ -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)