ohai 17.3.1 → 17.7.8

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: 41b4188e51b39e36fad8b57469446d7f7728842543175edf1ea4f4f919e42ed5
4
- data.tar.gz: 863e1b6aca39b9d3bf1f982c6a512877ff75c09e19638ed58fe1dbd60fc29d28
3
+ metadata.gz: 9624a58f805a1092cf71a19d5cc1501104c297df8b5f5cb9dafc8f288a77a62b
4
+ data.tar.gz: fa2839c8ca0d39f53629fc186b77addb1ef02e8783dba59a10f94d94406388ce
5
5
  SHA512:
6
- metadata.gz: f852e14b190cd4f5e9fe2d24cb17085f5146b5b069df85942ea0ddc3fba984ac9b8be266c665e40ddc119efdc99e232122ff03f058a3a7771ea0d3de436efa52
7
- data.tar.gz: 7745e8ebbc26abc7ca4bbdb937983e00d46b38ad049ed035fc17434594f212b062f6d1690ce919417978d28a1d4e63c734bfd6f5f9da71282ab505c9b23b05fd
6
+ metadata.gz: 4252161549ecd67b7bfd91c7b01673071b54d76179472ac2824965281147a5b40b14b2cc120fc8d2d1a41bc1956041c1c39bf820f3d538f2ee85b61771d11c66
7
+ data.tar.gz: 3f1be719448a8c6cb39be6b5cb2f1c9017e05abd223d3b2bc23aedb4891a8663e259f6a3f2828a8a7e5809f52dde821fcefaeeb534af80cc4729ba19bcc63514
data/Gemfile CHANGED
@@ -3,20 +3,20 @@ source "https://rubygems.org"
3
3
 
4
4
  gemspec
5
5
 
6
- # pull these gems from master of chef/chef so that we're testing against what we will release
7
- gem "chef-config", git: "https://github.com/chef/chef", branch: "master", glob: "chef-config/chef-config.gemspec"
8
- gem "chef-utils", git: "https://github.com/chef/chef", branch: "master", glob: "chef-utils/chef-utils.gemspec"
6
+ # pull these gems from main of chef/chef so that we're testing against what we will release
7
+ gem "chef-config", git: "https://github.com/chef/chef", branch: "main", glob: "chef-config/chef-config.gemspec"
8
+ gem "chef-utils", git: "https://github.com/chef/chef", branch: "main", glob: "chef-utils/chef-utils.gemspec"
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.6"
12
+ gem "chefstyle", "2.1.2"
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.4"
19
+ gem "rubocop-performance", "1.11.5"
20
20
  gem "rubocop-rspec"
21
21
  end
22
22
 
data/lib/ohai/config.rb CHANGED
@@ -26,7 +26,7 @@ module Ohai
26
26
  Config = ChefConfig::Config
27
27
 
28
28
  # Reopens ChefConfig::Config to add Ohai configuration settings.
29
- # see: https://github.com/chef/chef/blob/master/lib/chef/config.rb
29
+ # see: https://github.com/chef/chef/blob/main/lib/chef/config.rb
30
30
  class Config
31
31
  config_context :ohai do
32
32
  default :disabled_plugins, []
@@ -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
@@ -41,10 +41,32 @@ module Ohai
41
41
  module Ec2Metadata
42
42
 
43
43
  EC2_METADATA_ADDR ||= "169.254.169.254"
44
- EC2_SUPPORTED_VERSIONS ||= %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15
45
- 2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
46
- 2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02
47
- 2016-11-30 2018-08-17 2018-11-29 2019-10-01 2020-08-24 2020-11-01 }.freeze
44
+ EC2_SUPPORTED_VERSIONS ||= %w{ 1.0
45
+ 2007-01-19
46
+ 2007-03-01
47
+ 2007-08-29
48
+ 2007-10-10
49
+ 2007-12-15
50
+ 2008-02-01
51
+ 2008-09-01
52
+ 2009-04-04
53
+ 2011-01-01
54
+ 2011-05-01
55
+ 2012-01-12
56
+ 2014-02-25
57
+ 2014-11-05
58
+ 2015-10-20
59
+ 2016-04-19
60
+ 2016-06-30
61
+ 2016-09-02
62
+ 2018-03-28
63
+ 2018-08-17
64
+ 2018-09-24
65
+ 2019-10-01
66
+ 2020-10-27
67
+ 2021-01-03
68
+ 2021-03-23
69
+ 2021-07-15 }.freeze
48
70
  EC2_ARRAY_VALUES ||= %w{security-groups local_ipv4s}.freeze
49
71
  EC2_ARRAY_DIR ||= %w{network/interfaces/macs}.freeze
50
72
  EC2_JSON_DIR ||= %w{iam}.freeze
@@ -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
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.3.1"
22
+ VERSION = "17.7.8"
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.3.1
4
+ version: 17.7.8
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-07-20 00:00:00.000000000 Z
11
+ date: 2021-10-28 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