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
@@ -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
@@ -27,7 +27,7 @@ Ohai.plugin(:GCE) do
27
27
  # this works even if the system lacks dmidecode use by the Dmi plugin
28
28
  # @return [Boolean] do we have Google Compute Engine DMI data?
29
29
  def has_gce_dmi?
30
- if file_val_if_exists("/sys/class/dmi/id/product_name") =~ /Google Compute Engine/
30
+ if /Google Compute Engine/.match?(file_val_if_exists("/sys/class/dmi/id/product_name"))
31
31
  logger.trace("Plugin GCE: has_gce_dmi? == true")
32
32
  true
33
33
  else
@@ -48,8 +48,8 @@ Ohai.plugin(:GCE) do
48
48
  # looks at the Manufacturer and Model WMI values to see if they starts with Google.
49
49
  # @return [Boolean] Are the manufacturer and model Google?
50
50
  def has_gce_system_info?
51
- if RUBY_PLATFORM =~ /mswin|mingw32|windows/
52
- require "wmi-lite/wmi"
51
+ if RUBY_PLATFORM.match?(/mswin|mingw32|windows/)
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])
@@ -99,19 +99,19 @@ Ohai.plugin(:Hostname) do
99
99
  hostname from_cmd("hostname -s")
100
100
  machinename from_cmd("hostname")
101
101
  begin
102
- ourfqdn = resolve_fqdn
102
+ our_fqdn = resolve_fqdn
103
103
  # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
104
104
  # returns a blank string. WTF.
105
- if ourfqdn.nil? || ourfqdn.empty?
105
+ if our_fqdn.nil? || our_fqdn.empty?
106
106
  logger.trace("Plugin Hostname: hostname returned an empty string, retrying once.")
107
- ourfqdn = resolve_fqdn
107
+ our_fqdn = resolve_fqdn
108
108
  end
109
109
 
110
- if ourfqdn.nil? || ourfqdn.empty?
110
+ if our_fqdn.nil? || our_fqdn.empty?
111
111
  logger.trace("Plugin Hostname: hostname returned an empty string twice and will" +
112
112
  "not be set.")
113
113
  else
114
- fqdn ourfqdn
114
+ fqdn our_fqdn
115
115
  end
116
116
  rescue
117
117
  logger.trace(
@@ -132,20 +132,20 @@ Ohai.plugin(:Hostname) do
132
132
  hostname from_cmd("hostname -s")
133
133
  machinename from_cmd("hostname")
134
134
  begin
135
- ourfqdn = from_cmd("hostname --fqdn")
135
+ our_fqdn = from_cmd("hostname --fqdn")
136
136
  # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
137
137
  # returns a blank string. WTF.
138
- if ourfqdn.nil? || ourfqdn.empty?
138
+ if our_fqdn.nil? || our_fqdn.empty?
139
139
  logger.trace("Plugin Hostname: hostname --fqdn returned an empty string, retrying " +
140
140
  "once.")
141
- ourfqdn = from_cmd("hostname --fqdn")
141
+ our_fqdn = from_cmd("hostname --fqdn")
142
142
  end
143
143
 
144
- if ourfqdn.nil? || ourfqdn.empty?
144
+ if our_fqdn.nil? || our_fqdn.empty?
145
145
  logger.trace("Plugin Hostname: hostname --fqdn returned an empty string twice and " +
146
146
  "will not be set.")
147
147
  else
148
- fqdn ourfqdn
148
+ fqdn our_fqdn
149
149
  end
150
150
  rescue
151
151
  logger.trace("Plugin Hostname: hostname --fqdn returned an error, probably no domain set")
@@ -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
@@ -171,14 +171,14 @@ Ohai.plugin(:Hostname) do
171
171
  machinename host["name"].to_s
172
172
 
173
173
  info = Socket.gethostbyname(Socket.gethostname)
174
- if info.first =~ /.+?\.(.*)/
174
+ if /.+?\.(.*)/.match?(info.first)
175
175
  fqdn info.first
176
176
  else
177
177
  # host is not in dns. optionally use:
178
178
  # C:\WINDOWS\system32\drivers\etc\hosts
179
179
  info[3..info.length].reverse_each do |addr|
180
180
  hostent = Socket.gethostbyaddr(addr)
181
- if hostent.first =~ /.+?\.(.*)/
181
+ if /.+?\.(.*)/.match?(hostent.first)
182
182
  fqdn hostent.first
183
183
  break
184
184
  end
@@ -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
@@ -65,7 +65,7 @@ Ohai.plugin(:Interrupts) do
65
65
  interrupts[:irq][irqn][:events_by_cpu][cpu] = fields[cpu].to_i
66
66
  end
67
67
  # Only regular IRQs have extra fields and affinity settings
68
- if /^\d+$/.match(irqn)
68
+ if /^\d+$/.match?(irqn)
69
69
  interrupts[:irq][irqn][:type],
70
70
  interrupts[:irq][irqn][:vector],
71
71
  interrupts[:irq][irqn][:device] =
@@ -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
@@ -105,7 +105,7 @@ Ohai.plugin(:Mdadm) do
105
105
  # gather detailed information on the array
106
106
  so = shell_out("mdadm --detail /dev/#{device}")
107
107
 
108
- # if the mdadm command was sucessful pass so.stdout to create_raid_device_mash to grab the tidbits we want
108
+ # if the mdadm command was successful pass so.stdout to create_raid_device_mash to grab the tidbits we want
109
109
  mdadm[device] = create_raid_device_mash(so.stdout) if so.stdout
110
110
  mdadm[device]["members"] = devices[device]["active"]
111
111
  mdadm[device]["spares"] = devices[device]["spare"]
@@ -78,7 +78,7 @@ Ohai.plugin(:Network) do
78
78
  so.stdout.lines do |line|
79
79
  line.strip!
80
80
  logger.trace("Plugin Network: Parsing #{line}")
81
- if line =~ /\\/
81
+ if /\\/.match?(line)
82
82
  parts = line.split('\\')
83
83
  route_dest = parts.shift.strip
84
84
  route_endings = parts
@@ -108,6 +108,8 @@ Ohai.plugin(:Network) do
108
108
  # http://rubular.com/r/pwTNp65VFf
109
109
  route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)/
110
110
  end
111
+ # https://rubular.com/r/k1sMrRn5yLjgVi
112
+ route_entry["via"] = $1 if route_ending =~ /\bvia\s+inet6\s+([^\s]+)/
111
113
 
112
114
  # a sanity check, especially for Linux-VServer, OpenVZ and LXC:
113
115
  # don't report the route entry if the src address isn't set on the node
@@ -189,11 +191,11 @@ Ohai.plugin(:Network) do
189
191
  next if line.start_with?("Ring parameters for")
190
192
  next if line.strip.nil?
191
193
 
192
- if line =~ /Pre-set maximums/
194
+ if /Pre-set maximums/.match?(line)
193
195
  type = "max"
194
196
  next
195
197
  end
196
- if line =~ /Current hardware settings/
198
+ if /Current hardware settings/.match?(line)
197
199
  type = "current"
198
200
  next
199
201
  end
@@ -222,11 +224,11 @@ Ohai.plugin(:Network) do
222
224
  next if line.start_with?("Channel parameters for")
223
225
  next if line.strip.nil?
224
226
 
225
- if line =~ /Pre-set maximums/
227
+ if /Pre-set maximums/.match?(line)
226
228
  type = "max"
227
229
  next
228
230
  end
229
- if line =~ /Current hardware settings/
231
+ if /Current hardware settings/.match?(line)
230
232
  type = "current"
231
233
  next
232
234
  end
@@ -306,7 +308,7 @@ Ohai.plugin(:Network) do
306
308
  net_counters[tmp_int] ||= Mash.new
307
309
  end
308
310
 
309
- if line =~ /^\s+(ip6tnl|ipip)/
311
+ if /^\s+(ip6tnl|ipip)/.match?(line)
310
312
  iface[tmp_int][:tunnel_info] = {}
311
313
  words = line.split
312
314
  words.each_with_index do |word, index|
@@ -476,7 +478,7 @@ Ohai.plugin(:Network) do
476
478
 
477
479
  # returns the macaddress for interface from a hash of interfaces (iface elsewhere in this file)
478
480
  def get_mac_for_interface(interfaces, interface)
479
- 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")
480
482
  end
481
483
 
482
484
  # returns the default route with the lowest metric (unspecified metric is 0)
@@ -514,8 +516,16 @@ Ohai.plugin(:Network) do
514
516
  # if the route destination is a default route, it's good
515
517
  return true if route[:destination] == "default"
516
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
+
517
527
  # the default route has a gateway and the route matches the gateway
518
- !default_route[:via].nil? && IPAddress(route[:destination]).include?(IPAddress(default_route[:via]))
528
+ dest_ipaddr.include?(default_route_via)
519
529
  end
520
530
 
521
531
  # ipv4/ipv6 routes are different enough that having a single algorithm to select the favored route for both creates unnecessary complexity
@@ -567,7 +577,7 @@ Ohai.plugin(:Network) do
567
577
  # If the 'ip' binary is available, this plugin may set {ip,mac,ip6}address. The network plugin should not overwrite these.
568
578
  # The older code section below that relies on the deprecated net-tools, e.g. netstat and ifconfig, provides less functionality.
569
579
  collect_data(:linux) do
570
- require "ipaddr"
580
+ require "ipaddr" unless defined?(IPAddr)
571
581
 
572
582
  iface = Mash.new
573
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
  #
@@ -195,7 +192,7 @@ Ohai.plugin(:Platform) do
195
192
  elsif File.exist?("/etc/debian_version")
196
193
  # Ubuntu and Debian both have /etc/debian_version
197
194
  # Ubuntu should always have a working lsb, debian does not by default
198
- if lsb[:id] =~ /Ubuntu/i
195
+ if /Ubuntu/i.match?(lsb[:id])
199
196
  platform "ubuntu"
200
197
  platform_version lsb[:release]
201
198
  else
@@ -222,7 +219,7 @@ Ohai.plugin(:Platform) do
222
219
  suse_version = suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
223
220
  suse_version = suse_release[/VERSION = ([\d\.]{2,})/, 1] if suse_version == ""
224
221
  platform_version suse_version
225
- if suse_release =~ /^openSUSE/
222
+ if /^openSUSE/.match?(suse_release)
226
223
  # opensuse releases >= 42 are openSUSE Leap
227
224
  if platform_version.to_i < 42
228
225
  platform "opensuse"
@@ -256,23 +253,23 @@ Ohai.plugin(:Platform) do
256
253
  platform_version shell_out("/bin/uname -r").stdout.strip
257
254
  elsif File.exist?("/usr/lib/os-release")
258
255
  contents = File.read("/usr/lib/os-release")
259
- if /clear-linux-os/ =~ contents # Clear Linux https://clearlinux.org/
256
+ if /clear-linux-os/.match?(contents) # Clear Linux https://clearlinux.org/
260
257
  platform "clearlinux"
261
258
  platform_version contents[/VERSION_ID=(\d+)/, 1]
262
259
  end
263
- elsif lsb[:id] =~ /RedHat/i
260
+ elsif /RedHat/i.match?(lsb[:id])
264
261
  platform "redhat"
265
262
  platform_version lsb[:release]
266
- elsif lsb[:id] =~ /Amazon/i
263
+ elsif /Amazon/i.match?(lsb[:id])
267
264
  platform "amazon"
268
265
  platform_version lsb[:release]
269
- elsif lsb[:id] =~ /ScientificSL/i
266
+ elsif /ScientificSL/i.match?(lsb[:id])
270
267
  platform "scientific"
271
268
  platform_version lsb[:release]
272
- elsif lsb[:id] =~ /XenServer/i
269
+ elsif /XenServer/i.match?(lsb[:id])
273
270
  platform "xenserver"
274
271
  platform_version lsb[:release]
275
- elsif lsb[:id] =~ /XCP/i
272
+ elsif /XCP/i.match?(lsb[:id])
276
273
  platform "xcp"
277
274
  platform_version lsb[:release]
278
275
  elsif lsb[:id] # LSB can provide odd data that changes between releases, so we currently fall back on it rather than dealing with its subtleties
@@ -59,7 +59,7 @@ Ohai.plugin(:Virtualization) do
59
59
 
60
60
  # This file should exist on most Xen systems, normally empty for guests
61
61
  if File.exist?("/proc/xen/capabilities")
62
- if File.read("/proc/xen/capabilities") =~ /control_d/i
62
+ if /control_d/i.match?(File.read("/proc/xen/capabilities"))
63
63
  logger.trace("Plugin Virtualization: /proc/xen/capabilities contains control_d. Detecting as Xen host")
64
64
  virtualization[:role] = "host"
65
65
  virtualization[:systems][:xen] = "host"
@@ -70,12 +70,12 @@ Ohai.plugin(:Virtualization) do
70
70
  # Detect Virtualbox from kernel module
71
71
  if File.exist?("/proc/modules")
72
72
  modules = File.read("/proc/modules")
73
- if modules =~ /^vboxdrv/
73
+ if /^vboxdrv/.match?(modules)
74
74
  logger.trace("Plugin Virtualization: /proc/modules contains vboxdrv. Detecting as vbox host")
75
75
  virtualization[:system] = "vbox"
76
76
  virtualization[:role] = "host"
77
77
  virtualization[:systems][:vbox] = "host"
78
- elsif modules =~ /^vboxguest/
78
+ elsif /^vboxguest/.match?(modules)
79
79
  logger.trace("Plugin Virtualization: /proc/modules contains vboxguest. Detecting as vbox guest")
80
80
  virtualization[:system] = "vbox"
81
81
  virtualization[:role] = "guest"
@@ -93,7 +93,7 @@ Ohai.plugin(:Virtualization) do
93
93
 
94
94
  # Detect paravirt KVM/QEMU from cpuinfo, report as KVM
95
95
  if File.exist?("/proc/cpuinfo")
96
- if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/
96
+ if /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/.match?(File.read("/proc/cpuinfo"))
97
97
  logger.trace("Plugin Virtualization: /proc/cpuinfo lists a KVM paravirt CPU string. Detecting as kvm guest")
98
98
  virtualization[:system] = "kvm"
99
99
  virtualization[:role] = "guest"
@@ -105,7 +105,7 @@ Ohai.plugin(:Virtualization) do
105
105
  # guests will have the hypervisor cpu feature that hosts don't have
106
106
  if File.exist?("/sys/devices/virtual/misc/kvm")
107
107
  virtualization[:system] = "kvm"
108
- if File.read("/proc/cpuinfo") =~ /hypervisor/
108
+ if /hypervisor/.match?(File.read("/proc/cpuinfo"))
109
109
  logger.trace("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo lists the hypervisor feature. Detecting as kvm guest")
110
110
  virtualization[:role] = "guest"
111
111
  virtualization[:systems][:kvm] = "guest"
@@ -190,18 +190,21 @@ Ohai.plugin(:Virtualization) do
190
190
  # Kernel docs, https://www.kernel.org/doc/Documentation/cgroups
191
191
  if File.exist?("/proc/self/cgroup")
192
192
  cgroup_content = File.read("/proc/self/cgroup")
193
- if cgroup_content =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$} ||
194
- cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-?.+$}
193
+ # These two REs catch many different examples. Here's a specific one
194
+ # from when it is docker and there is no subsystem name.
195
+ # https://rubular.com/r/dV13hiU9KxmiWB
196
+ if cgroup_content =~ %r{^\d+:[^:]*:/(lxc|docker)/.+$} ||
197
+ cgroup_content =~ %r{^\d+:[^:]*:/[^/]+/(lxc|docker)-?.+$}
195
198
  logger.trace("Plugin Virtualization: /proc/self/cgroup indicates #{$1} container. Detecting as #{$1} guest")
196
199
  virtualization[:system] = $1
197
200
  virtualization[:role] = "guest"
198
201
  virtualization[:systems][$1.to_sym] = "guest"
199
- elsif File.read("/proc/1/environ") =~ /container=lxc/
202
+ elsif /container=lxc/.match?(File.read("/proc/1/environ"))
200
203
  logger.trace("Plugin Virtualization: /proc/1/environ indicates lxc container. Detecting as lxc guest")
201
204
  virtualization[:system] = "lxc"
202
205
  virtualization[:role] = "guest"
203
206
  virtualization[:systems][:lxc] = "guest"
204
- elsif File.read("/proc/1/environ") =~ /container=systemd-nspawn/
207
+ elsif /container=systemd-nspawn/.match?(File.read("/proc/1/environ"))
205
208
  logger.trace("Plugin Virtualization: /proc/1/environ indicates nspawn container. Detecting as nspawn guest")
206
209
  virtualization[:system] = "nspawn"
207
210
  virtualization[:role] = "guest"