ohai 17.5.2 → 17.7.12

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: afaf1b3332e2a31c5d045ea50e9315bd9fcf64fcd21e120982974c5b9d167d76
4
- data.tar.gz: ed90edfe09e2bf83fea9018b7f16d3fd16caf28aa998e75e44c9980789df6d30
3
+ metadata.gz: 152ee2a1456b0508eeb740837c37169e101f860d4398ed71dc2be86207aa9e75
4
+ data.tar.gz: ff72078f7fb2e6eab1207659eb0a66b4bfed98cbf66ca82778830ecfe545e5f4
5
5
  SHA512:
6
- metadata.gz: e4693d375412563df16856fe88ccdfd83ba5279a9b33fb3856ea9a7299bc599c943d7360d7135d28a59543420456a250300ad416a5e93bb7b09f7041750c336c
7
- data.tar.gz: ee963b18a46ea9b8a2d3292be0f82a2aaa7ef90cb629a71eb1fe51a661b5ded47d8da4c9b44f35614d169b6e0922dba3aa5e966ceab7055dcef8e57b50fc7afa
6
+ metadata.gz: e0bd1cc8142814db7d670a19cb6c49d7ccbfa7e029ae33ec79d194f27c03abdf07c215e155e50cc052893f9b3aef15a1c4de414e40e370753595fb877fa2c574
7
+ data.tar.gz: 23424895d514fe8ca3384e1155a75cbaba60a684aac6f4e53c924bb34733194691642a3b877f09c8e377b8a0fe59075bb2380d0bba9c8ed0c8abb59eea758aa2
data/Gemfile CHANGED
@@ -9,14 +9,14 @@ gem "chef-utils", git: "https://github.com/chef/chef", branch: "main", glob: "ch
9
9
 
10
10
  # NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local
11
11
  group :development do
12
- gem "chefstyle", "2.0.9"
12
+ gem "chefstyle", "2.1.3"
13
13
  gem "ipaddr_extensions"
14
14
  gem "rake", ">= 10.1.0"
15
15
  gem "rspec-collection_matchers", "~> 1.0"
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.11.5"
19
+ gem "rubocop-performance", "1.12.0"
20
20
  gem "rubocop-rspec"
21
21
  end
22
22
 
@@ -23,7 +23,7 @@ module Ohai
23
23
  module ConstantHelper
24
24
 
25
25
  def remove_constants
26
- new_object_constants = Object.constants - @object_pristine.constants
26
+ new_object_constants = Object.constants - @object_pristine.constants - [ :SortedSet ]
27
27
  new_object_constants.each do |constant|
28
28
  Object.send(:remove_const, constant) unless Object.const_get(constant).is_a?(Module)
29
29
  end
@@ -18,6 +18,8 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
+ require "socket" unless defined?(Socket)
22
+
21
23
  module Ohai
22
24
  module Mixin
23
25
  module NetworkHelper
@@ -32,6 +34,30 @@ module Ohai
32
34
  [2, 4, 6].each { |n| dec = dec + "." + netmask[n..n + 1].to_i(16).to_s(10) }
33
35
  dec
34
36
  end
37
+
38
+ # This does a forward and reverse lookup on the hostname to return what should be
39
+ # the FQDN for the host determined by name lookup (generally DNS). If the forward
40
+ # lookup fails this will throw. If the reverse lookup fails this will return the
41
+ # hostname back. The behavior on failure of the reverse lookup is both vitally important
42
+ # to this API, and completely untested, so changes to this method (not recommended) need
43
+ # to be manually validated by hand by setting up a DNS server with a broken A record to
44
+ # an IP without a PTR record (e.g. any RFC1918 space not served by the configured DNS
45
+ # server), and the method should return the hostname and not the IP address.
46
+ #
47
+ def canonicalize_hostname(hostname)
48
+ Addrinfo.getaddrinfo(hostname, nil, nil, nil, nil, Socket::AI_CANONNAME).first.canonname
49
+ end
50
+
51
+ def canonicalize_hostname_with_retries(hostname)
52
+ retries = 3
53
+ begin
54
+ canonicalize_hostname(hostname)
55
+ rescue
56
+ retries -= 1
57
+ retry if retries > 0
58
+ nil
59
+ end
60
+ end
35
61
  end
36
62
  end
37
63
  end
data/lib/ohai/mixin/os.rb CHANGED
@@ -82,13 +82,13 @@ module Ohai
82
82
  else
83
83
  # now we have something like an IPMI console that isn't Unix-like or Windows, presumably cannot run ruby, and
84
84
  # so we just trust the train O/S information.
85
- transport_connection.os
85
+ transport_connection.os.name
86
86
  end
87
87
  end
88
88
 
89
89
  # @api private
90
90
  def nonruby_target?
91
- transport_connection && !transport_connection.os.unix? && !transport_connection.os.windows
91
+ transport_connection && !transport_connection.os.unix? && !transport_connection.os.windows?
92
92
  end
93
93
 
94
94
  # @api private
@@ -48,7 +48,7 @@ Ohai.plugin(:Azure) do
48
48
  # check for either the waagent or the unknown-245 DHCP option that Azure uses
49
49
  # http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/
50
50
  def has_waagent?
51
- if file_exist?("/usr/sbin/waagent") || dir_exist?('C:\WindowsAzure')
51
+ if file_exist?("/usr/sbin/waagent") || dir_exist?("C:\\WindowsAzure")
52
52
  logger.trace("Plugin Azure: Found waagent used by Azure.")
53
53
  true
54
54
  end
@@ -499,7 +499,7 @@ Ohai.plugin(:CPU) do
499
499
 
500
500
  cpu[:total] = shell_out("pmcycles -m").stdout.lines.length
501
501
 
502
- # The below is only relevent on an LPAR
502
+ # The below is only relevant on an LPAR
503
503
  if shell_out("uname -W").stdout.strip == "0"
504
504
 
505
505
  # At least one CPU will be available, but we'll wait to increment this later.
@@ -26,7 +26,11 @@
26
26
  # limitations under the License.
27
27
  #
28
28
 
29
+ require_relative "../mixin/network_helper"
30
+
29
31
  Ohai.plugin(:Hostname) do
32
+ include Ohai::Mixin::NetworkHelper
33
+
30
34
  provides "domain", "hostname", "fqdn", "machinename"
31
35
 
32
36
  # hostname : short hostname
@@ -42,38 +46,8 @@ Ohai.plugin(:Hostname) do
42
46
  end
43
47
 
44
48
  # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
45
- # this is ipv6-safe, works on ruby 1.8.7+
46
49
  def resolve_fqdn
47
- require "socket" unless defined?(Socket)
48
- require "ipaddr" unless defined?(IPAddr)
49
-
50
- hostname = from_cmd("hostname")
51
- begin
52
- addrinfo = Socket.getaddrinfo(hostname, nil).first
53
- rescue SocketError
54
- # In the event that we got an exception from Socket, it's possible
55
- # that it will work if we restrict it to IPv4 only either because of
56
- # IPv6 misconfiguration or other bugs.
57
- #
58
- # Specifically it's worth noting that on macOS, getaddrinfo() will choke
59
- # if it gets back a link-local address (say if you have 'fe80::1 myhost'
60
- # in /etc/hosts). This will raise:
61
- # SocketError (getnameinfo: Non-recoverable failure in name resolution)
62
- #
63
- # But general misconfiguration could cause similar issues, so attempt to
64
- # fall back to v4-only
65
- begin
66
- addrinfo = Socket.getaddrinfo(hostname, nil, :INET).first
67
- rescue
68
- # and if *that* fails, then try v6-only, in case we're in a v6-only
69
- # environment with v4 config issues
70
- addrinfo = Socket.getaddrinfo(hostname, nil, :INET6).first
71
- end
72
- end
73
- iaddr = IPAddr.new(addrinfo[3])
74
- Socket.gethostbyaddr(iaddr.hton)[0]
75
- rescue
76
- nil
50
+ canonicalize_hostname_with_retries(from_cmd("hostname"))
77
51
  end
78
52
 
79
53
  def collect_domain
@@ -119,58 +93,21 @@ Ohai.plugin(:Hostname) do
119
93
  collect_data(:darwin) do
120
94
  hostname from_cmd("hostname -s")
121
95
  machinename from_cmd("hostname")
122
- begin
123
- our_fqdn = resolve_fqdn
124
- # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
125
- # returns a blank string. WTF.
126
- if our_fqdn.nil? || our_fqdn.empty?
127
- logger.trace("Plugin Hostname: hostname returned an empty string, retrying once.")
128
- our_fqdn = resolve_fqdn
129
- end
130
-
131
- if our_fqdn.nil? || our_fqdn.empty?
132
- logger.trace("Plugin Hostname: hostname returned an empty string twice and will" +
133
- "not be set.")
134
- else
135
- fqdn our_fqdn
136
- end
137
- rescue
138
- logger.trace(
139
- "Plugin Hostname: hostname returned an error, probably no domain set"
140
- )
141
- end
96
+ fqdn resolve_fqdn
142
97
  domain collect_domain
143
98
  end
144
99
 
145
100
  collect_data(:freebsd) do
146
101
  hostname from_cmd("hostname -s")
147
102
  machinename from_cmd("hostname")
148
- fqdn from_cmd("hostname -f")
103
+ fqdn resolve_fqdn
149
104
  collect_domain
150
105
  end
151
106
 
152
107
  collect_data(:linux) do
153
108
  hostname from_cmd("hostname -s")
154
109
  machinename from_cmd("hostname")
155
- begin
156
- our_fqdn = from_cmd("hostname --fqdn")
157
- # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely
158
- # returns a blank string. WTF.
159
- if our_fqdn.nil? || our_fqdn.empty?
160
- logger.trace("Plugin Hostname: hostname --fqdn returned an empty string, retrying " +
161
- "once.")
162
- our_fqdn = from_cmd("hostname --fqdn")
163
- end
164
-
165
- if our_fqdn.nil? || our_fqdn.empty?
166
- logger.trace("Plugin Hostname: hostname --fqdn returned an empty string twice and " +
167
- "will not be set.")
168
- else
169
- fqdn our_fqdn
170
- end
171
- rescue
172
- logger.trace("Plugin Hostname: hostname --fqdn returned an error, probably no domain set")
173
- end
110
+ fqdn resolve_fqdn
174
111
  domain collect_domain
175
112
  end
176
113
 
@@ -190,22 +127,7 @@ Ohai.plugin(:Hostname) do
190
127
 
191
128
  hostname host["dnshostname"].to_s
192
129
  machinename host["name"].to_s
193
-
194
- info = Socket.gethostbyname(Socket.gethostname)
195
- if /.+?\.(.*)/.match?(info.first)
196
- fqdn info.first
197
- else
198
- # host is not in dns. optionally use:
199
- # C:\WINDOWS\system32\drivers\etc\hosts
200
- info[3..info.length].reverse_each do |addr|
201
- hostent = Socket.gethostbyaddr(addr)
202
- if /.+?\.(.*)/.match?(hostent.first)
203
- fqdn hostent.first
204
- break
205
- end
206
- end
207
- fqdn info.first unless fqdn
208
- end
130
+ fqdn canonicalize_hostname_with_retries(Socket.gethostname)
209
131
  domain collect_domain
210
132
  end
211
133
  end
@@ -0,0 +1,61 @@
1
+ #
2
+ # Author:: Matthew Massey <matthewmassey@fb.com>
3
+ # Copyright:: Copyright (c) 2021 Facebook
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ Ohai.plugin(:Tc) do
20
+ provides "tc"
21
+ optional true
22
+
23
+ collect_data(:linux) do
24
+ tc_path = which("tc")
25
+ if tc_path
26
+ cmd = "#{tc_path} qdisc show"
27
+ tc_output = shell_out(cmd)
28
+
29
+ tc_data = Mash.new
30
+ tc_data[:qdisc] = Mash.new
31
+
32
+ tc_output.stdout.split("\n").each do |line|
33
+ line = line.strip
34
+ if /dev (\w+)/ =~ line
35
+ dev = $1
36
+ tc_data[:qdisc][dev] ||= Mash.new
37
+ else
38
+ next
39
+ end
40
+ if /qdisc (\w+)/ =~ line
41
+ qdisc = $1
42
+ tc_data[:qdisc][dev][:qdiscs] ||= []
43
+ tc_data[:qdisc][dev][:qdiscs] << Mash.new
44
+ qdisc_idx = tc_data[:qdisc][dev][:qdiscs].length - 1
45
+ tc_data[:qdisc][dev][:qdiscs][qdisc_idx] ||= Mash.new
46
+ tc_data[:qdisc][dev][:qdiscs][qdisc_idx][:type] = qdisc
47
+ tc_data[:qdisc][dev][:qdiscs][qdisc_idx][:parms] ||= Mash.new
48
+ else
49
+ next
50
+ end
51
+ if qdisc == "fq" && /buckets (\d+)/ =~ line
52
+ buckets = $1.to_i
53
+ tc_data[:qdisc][dev][:qdiscs][qdisc_idx][:parms][:buckets] = buckets
54
+ end
55
+ end
56
+ tc tc_data
57
+ else
58
+ logger.trace("Plugin Tc: Could not find tc. Skipping plugin.")
59
+ end
60
+ end
61
+ end
@@ -40,6 +40,12 @@ Ohai.plugin(:OS) do
40
40
 
41
41
  collect_data(:target) do
42
42
  os collect_os
43
+ os_version "unknown"
44
+ end
45
+
46
+ collect_data(:api) do
47
+ os collect_os
48
+ os_version "unknown"
43
49
  end
44
50
 
45
51
  collect_data do
@@ -134,9 +134,9 @@ Ohai.plugin(:Packages) do
134
134
  require "win32/registry" unless defined?(Win32::Registry)
135
135
  packages Mash.new
136
136
  collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
137
- collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall')
137
+ # on 64 bit systems, 32 bit programs are stored here moved before HKEY_CURRENT_USER otherwise it is not collected (impacts both ohai 16 & 17)
138
138
  collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
139
- # on 64 bit systems, 32 bit programs are stored here
139
+ collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall') rescue nil
140
140
  end
141
141
 
142
142
  collect_data(:aix) do
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Author:: Davide Cavalca <dcavalca@fb.com>
5
+ # Copyright:: Copyright (c) 2021 Meta Platforms, Inc. and affiliates.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ Ohai.plugin(:Rpm) do
22
+ provides "rpm"
23
+ optional "true"
24
+
25
+ MACROS_MARKER = /========================/.freeze
26
+
27
+ DO_NOT_SPLIT = %w{
28
+ build_arch
29
+ build_os
30
+ install_arch
31
+ install_os
32
+ archcolor
33
+ optflags
34
+ }.freeze
35
+
36
+ collect_data(:aix, :darwin, :dragonflybsd, :freebsd, :linux, :netbsd, :openbsd, :solaris2) do
37
+ rpm_path = which("rpm")
38
+ if rpm_path
39
+ rpm_version_out = shell_out("#{rpm_path} --version")
40
+ rpm_showrc_out = shell_out("#{rpm_path} --showrc")
41
+
42
+ rpm Mash.new unless rpm
43
+ rpm[:macros] ||= Mash.new
44
+
45
+ m = rpm_version_out.stdout.match(/\w+ (\d.*)/)
46
+ if m
47
+ rpm[:version] = m[1]
48
+ end
49
+
50
+ lines = rpm_showrc_out.stdout.split("\n")
51
+ # there's a marker to separate the beginning and end of the macros list
52
+ macros_start_idx = lines.index { |x| x.match(MACROS_MARKER) }
53
+ macros_end_idx = lines.rindex { |x| x.match(MACROS_MARKER) }
54
+ section = nil
55
+ lines[0..macros_start_idx - 1].each do |line|
56
+ if line.start_with?("ARCHITECTURE AND OS")
57
+ section = :arch_os
58
+ rpm[section] ||= Mash.new
59
+ elsif line.start_with?("RPMRC VALUES")
60
+ section = :rpmrc
61
+ rpm[section] ||= Mash.new
62
+ elsif line.start_with?("Features supported by rpmlib")
63
+ section = :features
64
+ rpm[section] ||= Mash.new
65
+ elsif line.start_with?("Macro path")
66
+ fields = line.split(":", 2)
67
+ if fields
68
+ rpm[:macro_path] = fields[1].strip.split(":")
69
+ end
70
+ section = nil
71
+ elsif %i{arch_os rpmrc}.include?(section)
72
+ fields = line.split(":")
73
+ if fields && fields[0] && fields[1]
74
+ key = fields[0].strip.sub("'s", "es").tr(" ", "_")
75
+ if DO_NOT_SPLIT.include?(key)
76
+ values = fields[1].strip
77
+ else
78
+ values = fields[1].strip.split(" ")
79
+ end
80
+ rpm[section][key] = values
81
+ end
82
+ elsif section == :features
83
+ fields = line.split("=")
84
+ if fields && fields[0] && fields[1]
85
+ rpm[section][fields[0].strip] = fields[1].strip
86
+ end
87
+ end
88
+ end
89
+
90
+ name = nil
91
+ value = ""
92
+ lines[macros_start_idx + 1..macros_end_idx - 1].each do |line|
93
+ if line.start_with?("-")
94
+ if name
95
+ rpm[:macros][name] = value
96
+ name = nil
97
+ value = ""
98
+ else
99
+ _prefix, name, value = line.split(" ", 3)
100
+ end
101
+ else
102
+ value += "\n#{line}"
103
+ end
104
+ end
105
+ else
106
+ logger.trace("Plugin RPM: Could not find rpm. Skipping plugin.")
107
+ end
108
+ end
109
+ end
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 = "17.5.2"
22
+ VERSION = "17.7.12"
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: 17.5.2
4
+ version: 17.7.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Jacob
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-27 00:00:00.000000000 Z
11
+ date: 2021-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-config
@@ -315,6 +315,7 @@ files:
315
315
  - lib/ohai/plugins/linux/sessions.rb
316
316
  - lib/ohai/plugins/linux/sysctl.rb
317
317
  - lib/ohai/plugins/linux/systemd_paths.rb
318
+ - lib/ohai/plugins/linux/tc.rb
318
319
  - lib/ohai/plugins/linux/virtualization.rb
319
320
  - lib/ohai/plugins/lua.rb
320
321
  - lib/ohai/plugins/mono.rb
@@ -340,6 +341,7 @@ files:
340
341
  - lib/ohai/plugins/python.rb
341
342
  - lib/ohai/plugins/rackspace.rb
342
343
  - lib/ohai/plugins/root_group.rb
344
+ - lib/ohai/plugins/rpm.rb
343
345
  - lib/ohai/plugins/ruby.rb
344
346
  - lib/ohai/plugins/rust.rb
345
347
  - lib/ohai/plugins/scala.rb