ohai 18.1.3 → 18.1.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 62cb983e4564cb9d15a8eb0b74bbdfdbf2c515fc2906a46718ad71f8e54fa663
4
- data.tar.gz: 1b5157e0f291485d13ef5ee96d5b0aa90e274f19d259d1ac15897ea9a9a3bb33
3
+ metadata.gz: ba5e0cd23be58860dbaeaa8215628de72afb4ca181235acacd356064c8cdcdb6
4
+ data.tar.gz: 8059d2d3e7bf4c4a68b75f926165929446a3dbe280402438eba20be552c05fec
5
5
  SHA512:
6
- metadata.gz: 815bce3ce6a1a8b83d0bdcd702581331632fc2239f7eea243261db411c951145bdbdc0c45802acae14ad514bcb390ce7f65fc8c2ef61d9e16b672cdb550e53fe
7
- data.tar.gz: 98a13a200478051a2898b7d210f944bbdad9fecab0b39ecf7fa54ea0a3104027bcfcced0b22d9b17bf25383830a0386bd5a3cad5cf2ca202adf36a4fd19ffafb
6
+ metadata.gz: 5161f55dba454fff218dd4545a940cb0b324e3802930bf01b3b0d62730026d470961d4138259c4b6c8f76e3ed4059eb98e1a37b188823e02808d1e35817254e3
7
+ data.tar.gz: 27e98bd57c54192067a797a1303466becf7fa0eff0448665b35782613abbe238ae8c623192afd0ac6acd270a313212384e25c98373b0f101cd766dbece762358
data/Gemfile CHANGED
@@ -16,7 +16,7 @@ group :development do
16
16
  gem "rspec-core", "~> 3.0"
17
17
  gem "rspec-expectations", "~> 3.0"
18
18
  gem "rspec-mocks", "~> 3.0"
19
- gem "rubocop-performance", "1.16.0"
19
+ gem "rubocop-performance", "1.18.0"
20
20
  gem "rubocop-rspec"
21
21
  end
22
22
 
@@ -41,23 +41,26 @@ module Ohai
41
41
  conn.get("/2016-01-01/#{uri}", { "User-Agent" => "chef-ohai/#{Ohai::VERSION}" })
42
42
  end
43
43
 
44
- def fetch_metadata(id = "")
44
+ def fetch_metadata(id = "", is_directory = true)
45
45
  response = http_get(id)
46
46
  if response.code == "200"
47
- json_data = parse_json(response.body)
48
- if json_data.nil?
49
- logger.warn("Mixin AlibabaMetadata: Metadata response is NOT valid JSON for id='#{id}'")
50
- if response.body.include?("\n")
51
- temp = {}
52
- response.body.split("\n").each do |sub_attr|
53
- temp[sanitize_key(sub_attr)] = fetch_metadata("#{id}/#{sub_attr}")
54
- end
55
- temp
56
- else
47
+
48
+ if !is_directory
49
+ json_data = parse_json(response.body)
50
+ if json_data.nil?
57
51
  response.body
52
+ else
53
+ json_data
58
54
  end
59
- else
60
- json_data
55
+ elsif is_directory
56
+ temp = {}
57
+ response.body.split("\n").each do |sub_attr|
58
+ if "#{id}/#{sub_attr}" != "/user-data"
59
+ uri = id == "" ? "#{id}#{sub_attr}/" : "#{id}#{sub_attr}"
60
+ temp[sanitize_key(sub_attr).gsub(/_$/, "")] = fetch_metadata(uri, has_trailing_slash?(uri))
61
+ end
62
+ end
63
+ temp
61
64
  end
62
65
  else
63
66
  logger.warn("Mixin AlibabaMetadata: Received response code #{response.code} requesting metadata for id='#{id}'")
@@ -65,6 +68,13 @@ module Ohai
65
68
  end
66
69
  end
67
70
 
71
+ # @param data [String]
72
+ #
73
+ # @return [Boolean] is there a trailing /?
74
+ def has_trailing_slash?(data)
75
+ !!(data =~ %r{/$})
76
+ end
77
+
68
78
  def sanitize_key(key)
69
79
  key.gsub(%r{\-|/}, "_")
70
80
  end
@@ -41,7 +41,8 @@ module Ohai
41
41
  AZURE_SUPPORTED_VERSIONS ||= %w{ 2018-10-01 2019-02-01 2019-03-11 2019-04-30 2019-06-01
42
42
  2019-06-04 2019-08-01 2019-08-15 2019-11-01 2020-06-01
43
43
  2020-07-15 2020-09-01 2020-10-01 2020-12-01 2021-01-01
44
- 2021-02-01 2021-03-01 2021-05-01 2021-10-01 }.freeze
44
+ 2021-02-01 2021-03-01 2021-05-01 2021-10-01 2021-11-01
45
+ 2021-11-15 2021-12-13 2023-07-01 }.freeze
45
46
 
46
47
  def best_api_version
47
48
  @api_version ||= begin
@@ -26,7 +26,7 @@ module Ohai
26
26
 
27
27
  # Trailing dot to host is added to avoid DNS search path
28
28
  GCE_METADATA_ADDR ||= "metadata.google.internal."
29
- GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true"
29
+ GCE_METADATA_URL ||= "/computeMetadata/v1"
30
30
 
31
31
  # fetch the meta content with a timeout and the required header
32
32
  def http_get(uri)
@@ -39,7 +39,9 @@ module Ohai
39
39
  end
40
40
 
41
41
  def fetch_metadata(id = "")
42
- response = http_get("#{GCE_METADATA_URL}/#{id}")
42
+ url = "#{GCE_METADATA_URL}/#{id}"
43
+ url = "#{url}?recursive=true" if url.end_with?("/")
44
+ response = http_get(url)
43
45
  if response.code == "200"
44
46
  json_data = parse_json(response.body)
45
47
  if json_data.nil?
@@ -19,6 +19,7 @@
19
19
  #
20
20
 
21
21
  require "socket" unless defined?(Socket)
22
+ require "resolv" unless defined?(Resolv)
22
23
 
23
24
  module Ohai
24
25
  module Mixin
@@ -37,6 +38,12 @@ module Ohai
37
38
  dec
38
39
  end
39
40
 
41
+ # Addrinfo#ip*? methods return true on AI_CANONNAME Addrinfo records that match
42
+ # the ipv* scheme and #ip? always returns true unless a non tcp Addrinfo
43
+ def ip?(hostname)
44
+ Resolv::IPv4::Regex.match?(hostname) || Resolv::IPv6::Regex.match?(hostname)
45
+ end
46
+
40
47
  # This does a forward and reverse lookup on the hostname to return what should be
41
48
  # the FQDN for the host determined by name lookup (generally DNS). If the forward
42
49
  # lookup fails this will throw. If the reverse lookup fails this will return the
@@ -47,7 +54,27 @@ module Ohai
47
54
  # server), and the method should return the hostname and not the IP address.
48
55
  #
49
56
  def canonicalize_hostname(hostname)
50
- Addrinfo.getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first.canonname
57
+ ai = Addrinfo
58
+ .getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME)
59
+ .first
60
+
61
+ canonname = ai&.canonname
62
+ # use canonname if it's an FQDN
63
+ # This API is preferred as it never gives us an IP address for broken DNS
64
+ # (see https://github.com/chef/ohai/pull/1705)
65
+ # However, we have found that Windows hosts that are not joined to a domain
66
+ # can return a non-qualified hostname).
67
+ # Use a '.' in the canonname as indicator of FQDN
68
+ return canonname if canonname.include?(".")
69
+
70
+ # If we got a non-qualified name, then we do a standard reverse resolve
71
+ # which, assuming DNS is working, will work around that windows bug
72
+ # (and maybe others)
73
+ canonname = ai&.getnameinfo&.first
74
+ return canonname unless ip?(canonname)
75
+
76
+ # if all else fails, return the name we were given as a safety
77
+ hostname
51
78
  end
52
79
 
53
80
  def canonicalize_hostname_with_retries(hostname)
@@ -18,7 +18,7 @@
18
18
  #
19
19
 
20
20
  Ohai.plugin(:Platform) do
21
- provides "platform", "platform_version", "platform_build", "platform_family"
21
+ provides "platform", "platform_version", "platform_version_extra", "platform_build", "platform_family"
22
22
 
23
23
  collect_data(:darwin) do
24
24
  so = shell_out(Ohai.abs_path( "/usr/bin/sw_vers" ).to_s)
@@ -26,6 +26,8 @@ Ohai.plugin(:Platform) do
26
26
  case line
27
27
  when /^ProductVersion:\s+(.+)$/
28
28
  platform_version $1
29
+ when /^ProductVersionExtra:\s+(.+)$/
30
+ platform_version_extra $1
29
31
  when /^BuildVersion:\s+(.+)$/
30
32
  platform_build $1
31
33
  end
@@ -43,6 +43,10 @@ Ohai.plugin(:Virtualization) do
43
43
  which("docker")
44
44
  end
45
45
 
46
+ def sysctl_exists?
47
+ which("sysctl")
48
+ end
49
+
46
50
  collect_data(:darwin) do
47
51
  virtualization Mash.new unless virtualization
48
52
  virtualization[:systems] ||= Mash.new
@@ -77,6 +81,11 @@ Ohai.plugin(:Virtualization) do
77
81
  virtualization[:systems][:vmware] = "guest"
78
82
  end
79
83
 
84
+ if sysctl_exists? && shell_out("sysctl -in kern.hv_vmm_present").stdout.strip.to_i == 1
85
+ virtualization[:system] = "qemu"
86
+ virtualization[:role] = "guest"
87
+ end
88
+
80
89
  if ioreg_exists? && shell_out("ioreg -l").stdout.include?("pci1ab8,4000")
81
90
  virtualization[:system] = "parallels"
82
91
  virtualization[:role] = "guest"
@@ -86,5 +95,10 @@ Ohai.plugin(:Virtualization) do
86
95
  virtualization[:role] = "host"
87
96
  virtualization[:systems][:parallels] = "host"
88
97
  end
98
+
99
+ if hardware["machine_model"].include? "VirtualMac"
100
+ virtualization[:system] = "apple"
101
+ virtualization[:role] = "guest"
102
+ end
89
103
  end
90
- end
104
+ end
@@ -51,10 +51,14 @@ Ohai.plugin(:Lspci) do
51
51
 
52
52
  case dev[0]
53
53
  when "Device" # There are two different Device tags
54
- if ( tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/) )
54
+ if ( tmp = dev[1].match(/(#{hhhh}:)?(#{hh}:#{hh}\.#{h})/) )
55
55
  # We have a device id
56
56
  d_id = tmp[0] # From now on we will need this id
57
57
  devices[d_id] = Mash.new
58
+ if tmp[1]
59
+ # We have a root complex
60
+ devices[d_id]["root_port"] = tmp[1][0..-2]
61
+ end
58
62
  else
59
63
  standard_form(devices, d_id, hhhh, "device", dev[1])
60
64
  end
@@ -700,7 +700,7 @@ Ohai.plugin(:Network) do
700
700
  # Match the lead line for an interface from iproute2
701
701
  # 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
702
702
  # The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex
703
- IPROUTE_INT_REGEX ||= /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/.freeze
703
+ IPROUTE_INT_REGEX ||= /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z\-_]+|):\s/.freeze
704
704
 
705
705
  if which("ip")
706
706
  # families to get default routes from
@@ -33,13 +33,13 @@ Ohai.plugin(:Packages) do
33
33
  packages Mash.new
34
34
  case platform_family
35
35
  when "debian"
36
- format = '${Package}\t${Version}\t${Architecture}\n'
36
+ format = '${Package}\t${Version}\t${Architecture}\t${db:Status-Status}\n'
37
37
  so = shell_out("dpkg-query -W -f='#{format}'")
38
38
  pkgs = so.stdout.lines
39
39
 
40
40
  pkgs.each do |pkg|
41
- name, version, arch = pkg.split
42
- packages[name] = { "version" => version, "arch" => arch }
41
+ name, version, arch, status = pkg.split
42
+ packages[name] = { "version" => version, "arch" => arch, "status" => status }
43
43
  end
44
44
 
45
45
  when "rhel", "fedora", "suse", "pld", "amazon"
data/lib/ohai/version.rb CHANGED
@@ -19,5 +19,5 @@
19
19
 
20
20
  module Ohai
21
21
  OHAI_ROOT = File.expand_path(__dir__)
22
- VERSION = "18.1.3"
22
+ VERSION = "18.1.18"
23
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohai
3
3
  version: !ruby/object:Gem::Version
4
- version: 18.1.3
4
+ version: 18.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-08 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -401,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
401
401
  - !ruby/object:Gem::Version
402
402
  version: '0'
403
403
  requirements: []
404
- rubygems_version: 3.1.4
404
+ rubygems_version: 3.2.3
405
405
  signing_key:
406
406
  specification_version: 4
407
407
  summary: Ohai profiles your system and emits JSON