ohai 16.10.6 → 17.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +5 -5
- data/lib/ohai/config.rb +1 -1
- data/lib/ohai/mixin/alibaba_metadata.rb +86 -0
- data/lib/ohai/mixin/constant_helper.rb +1 -1
- data/lib/ohai/mixin/ec2_metadata.rb +26 -4
- data/lib/ohai/mixin/network_helper.rb +26 -0
- data/lib/ohai/mixin/os.rb +2 -2
- data/lib/ohai/plugins/aix/virtualization.rb +4 -3
- data/lib/ohai/plugins/alibaba.rb +72 -0
- data/lib/ohai/plugins/azure.rb +1 -1
- data/lib/ohai/plugins/c.rb +6 -8
- data/lib/ohai/plugins/chef.rb +12 -1
- data/lib/ohai/plugins/cloud.rb +20 -3
- data/lib/ohai/plugins/cpu.rb +246 -35
- data/lib/ohai/plugins/eucalyptus.rb +1 -1
- data/lib/ohai/plugins/filesystem.rb +4 -17
- data/lib/ohai/plugins/habitat.rb +73 -0
- data/lib/ohai/plugins/hostname.rb +9 -66
- data/lib/ohai/plugins/linux/livepatch.rb +38 -0
- data/lib/ohai/plugins/linux/network.rb +30 -5
- data/lib/ohai/plugins/linux/os_release.rb +38 -0
- data/lib/ohai/plugins/linux/platform.rb +19 -19
- data/lib/ohai/plugins/linux/tc.rb +61 -0
- data/lib/ohai/plugins/linux/virtualization.rb +40 -2
- data/lib/ohai/plugins/network.rb +1 -1
- data/lib/ohai/plugins/os.rb +6 -0
- data/lib/ohai/plugins/packages.rb +6 -5
- data/lib/ohai/plugins/rpm.rb +119 -0
- data/lib/ohai/plugins/vmware.rb +22 -2
- data/lib/ohai/runner.rb +1 -1
- data/lib/ohai/version.rb +1 -1
- data/ohai.gemspec +4 -8
- metadata +24 -17
@@ -80,7 +80,7 @@ Ohai.plugin(:Network) do
|
|
80
80
|
line.strip!
|
81
81
|
logger.trace("Plugin Network: Parsing #{line}")
|
82
82
|
if /\\/.match?(line)
|
83
|
-
parts = line.split(
|
83
|
+
parts = line.split("\\")
|
84
84
|
route_dest = parts.shift.strip
|
85
85
|
route_endings = parts
|
86
86
|
elsif line =~ /^([^\s]+)\s(.*)$/
|
@@ -141,13 +141,13 @@ Ohai.plugin(:Network) do
|
|
141
141
|
|
142
142
|
# using a temporary var to hold routes and their interface name
|
143
143
|
def parse_routes(family, iface)
|
144
|
-
iface.
|
144
|
+
iface.filter_map do |i, iv|
|
145
145
|
next unless iv[:routes]
|
146
146
|
|
147
|
-
iv[:routes].
|
147
|
+
iv[:routes].filter_map do |r|
|
148
148
|
r.merge(dev: i) if r[:family] == family[:name]
|
149
|
-
end
|
150
|
-
end.
|
149
|
+
end
|
150
|
+
end.flatten
|
151
151
|
end
|
152
152
|
|
153
153
|
# determine layer 1 details for the interface using ethtool
|
@@ -273,6 +273,30 @@ Ohai.plugin(:Network) do
|
|
273
273
|
iface
|
274
274
|
end
|
275
275
|
|
276
|
+
# determine offload features for the interface using ethtool
|
277
|
+
def ethernet_offload_parameters(iface)
|
278
|
+
return iface unless ethtool_binary_path
|
279
|
+
|
280
|
+
iface.each_key do |tmp_int|
|
281
|
+
next unless iface[tmp_int][:encapsulation] == "Ethernet"
|
282
|
+
|
283
|
+
so = shell_out("#{ethtool_binary_path} -k #{tmp_int}")
|
284
|
+
Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{so.stdout}")
|
285
|
+
iface[tmp_int]["offload_params"] = {}
|
286
|
+
so.stdout.lines.each do |line|
|
287
|
+
next if line.start_with?("Features for")
|
288
|
+
next if line.strip.nil?
|
289
|
+
|
290
|
+
key, val = line.split(/:\s+/)
|
291
|
+
if val
|
292
|
+
offload_key = key.downcase.strip.tr(" ", "_").to_s
|
293
|
+
iface[tmp_int]["offload_params"][offload_key] = val.downcase.gsub(/\[.*\]/, "").strip.to_s
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
iface
|
298
|
+
end
|
299
|
+
|
276
300
|
# determine pause parameters for the interface using ethtool
|
277
301
|
def ethernet_pause_parameters(iface)
|
278
302
|
return iface unless ethtool_binary_path
|
@@ -793,6 +817,7 @@ Ohai.plugin(:Network) do
|
|
793
817
|
iface = ethernet_ring_parameters(iface)
|
794
818
|
iface = ethernet_channel_parameters(iface)
|
795
819
|
iface = ethernet_coalesce_parameters(iface)
|
820
|
+
iface = ethernet_offload_parameters(iface)
|
796
821
|
iface = ethernet_driver_info(iface)
|
797
822
|
iface = ethernet_pause_parameters(iface)
|
798
823
|
counters[:network][:interfaces] = net_counters
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Author:: Lance Albertson (lance@osuosl.org>)
|
4
|
+
# Copyright:: Copyright (c) 2021 Oregon State University
|
5
|
+
# License:: Apache License, Version 2.0
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
|
20
|
+
Ohai.plugin(:OsRelease) do
|
21
|
+
provides "os_release"
|
22
|
+
|
23
|
+
collect_data(:linux) do
|
24
|
+
os_release Mash.new unless os_release
|
25
|
+
|
26
|
+
# https://www.freedesktop.org/software/systemd/man/os-release.html
|
27
|
+
if file_exist?("/etc/os-release")
|
28
|
+
file_read("/etc/os-release").each_line do |line|
|
29
|
+
key, value = line.split("=")
|
30
|
+
if key == "ID_LIKE"
|
31
|
+
os_release[key.downcase] = value.chomp.gsub(/\A"|"\Z/, "").split(" ") if value
|
32
|
+
else
|
33
|
+
os_release[key.downcase] = value.chomp.gsub(/\A"|"\Z/, "") if value
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -54,7 +54,7 @@ Ohai.plugin(:Platform) do
|
|
54
54
|
end
|
55
55
|
|
56
56
|
#
|
57
|
-
# Cached /etc/os-release info Hash.
|
57
|
+
# Cached /etc/os-release info Hash. Also has logic for Cisco Nexus
|
58
58
|
# switches that pulls the chained CISCO_RELEASE_INFO file into the Hash (other
|
59
59
|
# distros can also reuse this method safely).
|
60
60
|
#
|
@@ -112,16 +112,17 @@ Ohai.plugin(:Platform) do
|
|
112
112
|
# ohai uses. If you're adding a new platform here and you want to change the name
|
113
113
|
# you'll want to add it here and then add a spec for the platform_id_remap method
|
114
114
|
{
|
115
|
-
"
|
115
|
+
"alinux" => "alibabalinux",
|
116
116
|
"amzn" => "amazon",
|
117
|
+
"archarm" => "arch",
|
118
|
+
"cumulus-linux" => "cumulus",
|
117
119
|
"ol" => "oracle",
|
118
|
-
"sles" => "suse",
|
119
|
-
"sles_sap" => "suse",
|
120
120
|
"opensuse-leap" => "opensuseleap",
|
121
|
+
"rhel" => "redhat",
|
122
|
+
"sles_sap" => "suse",
|
123
|
+
"sles" => "suse",
|
121
124
|
"xenenterprise" => "xenserver",
|
122
|
-
|
123
|
-
"archarm" => "arch",
|
124
|
-
}[id] || id
|
125
|
+
}[id.downcase] || id.downcase
|
125
126
|
end
|
126
127
|
|
127
128
|
#
|
@@ -133,22 +134,24 @@ Ohai.plugin(:Platform) do
|
|
133
134
|
#
|
134
135
|
def platform_family_from_platform(plat)
|
135
136
|
case plat
|
136
|
-
when /
|
137
|
+
when /ubuntu/, /debian/, /linuxmint/, /raspbian/, /cumulus/, /kali/, /pop/
|
137
138
|
# apt-get+dpkg almost certainly goes here
|
138
139
|
"debian"
|
139
|
-
when /
|
140
|
+
when /centos/, /redhat/, /oracle/, /almalinux/, /rocky/, /scientific/, /enterpriseenterprise/, /xenserver/, /xcp-ng/, /cloudlinux/, /alibabalinux/, /sangoma/, /clearos/, /parallels/, /ibm_powerkvm/, /nexus_centos/, /bigip/, /virtuozzo/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
|
140
141
|
# NOTE: "rhel" should be reserved exclusively for recompiled rhel versions that are nearly perfectly compatible down to the platform_version.
|
141
142
|
# The operating systems that are "rhel" should all be as compatible as rhel7 = centos7 = oracle7 = scientific7 (98%-ish core RPM version compatibility
|
142
143
|
# and the version numbers MUST track the upstream). The appropriate EPEL version repo should work nearly perfectly. Some variation like the
|
143
|
-
# oracle kernel version differences and tuning and extra packages are clearly acceptable.
|
144
|
-
# should not be in this list.
|
144
|
+
# oracle kernel version differences and tuning and extra packages are clearly acceptable. Almost certainly some distros above (xenserver?)
|
145
|
+
# should not be in this list. Please use fedora, below, instead. Also note that this is the only platform_family with this strict of a rule,
|
145
146
|
# see the example of the debian platform family for how the rest of the platform_family designations should be used.
|
147
|
+
#
|
148
|
+
# TODO: when XCP-NG 7.4 support ends we can remove the xcp-ng match. 7.5+ reports as xenenterprise which we remap to xenserver
|
146
149
|
"rhel"
|
147
150
|
when /amazon/
|
148
151
|
"amazon"
|
149
|
-
when /suse/, /sles/, /
|
152
|
+
when /suse/, /sles/, /opensuseleap/, /opensuse/, /sled/
|
150
153
|
"suse"
|
151
|
-
when /fedora/, /
|
154
|
+
when /fedora/, /arista_eos/
|
152
155
|
# In the broadest sense: RPM-based, fedora-derived distributions which are not strictly re-compiled RHEL (if it uses RPMs, and smells more like redhat and less like
|
153
156
|
# SuSE it probably goes here).
|
154
157
|
"fedora"
|
@@ -156,9 +159,7 @@ Ohai.plugin(:Platform) do
|
|
156
159
|
"wrlinux"
|
157
160
|
when /gentoo/
|
158
161
|
"gentoo"
|
159
|
-
when /
|
160
|
-
"slackware"
|
161
|
-
when /arch/, /manjaro/, /antergos/
|
162
|
+
when /arch/, /manjaro/
|
162
163
|
"arch"
|
163
164
|
when /exherbo/
|
164
165
|
"exherbo"
|
@@ -168,6 +169,8 @@ Ohai.plugin(:Platform) do
|
|
168
169
|
"clearlinux"
|
169
170
|
when /mangeia/
|
170
171
|
"mandriva"
|
172
|
+
when /slackware/
|
173
|
+
"slackware"
|
171
174
|
end
|
172
175
|
end
|
173
176
|
|
@@ -270,9 +273,6 @@ Ohai.plugin(:Platform) do
|
|
270
273
|
elsif /XenServer/i.match?(lsb[:id])
|
271
274
|
platform "xenserver"
|
272
275
|
platform_version lsb[:release]
|
273
|
-
elsif /XCP/i.match?(lsb[:id])
|
274
|
-
platform "xcp"
|
275
|
-
platform_version lsb[:release]
|
276
276
|
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
|
277
277
|
platform lsb[:id].downcase
|
278
278
|
platform_version lsb[:release]
|
@@ -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
|
@@ -20,6 +20,7 @@
|
|
20
20
|
Ohai.plugin(:Virtualization) do
|
21
21
|
provides "virtualization"
|
22
22
|
depends "dmi"
|
23
|
+
depends "cpu"
|
23
24
|
require_relative "../../mixin/dmi_decode"
|
24
25
|
include Ohai::Mixin::DmiDecode
|
25
26
|
|
@@ -35,6 +36,10 @@ Ohai.plugin(:Virtualization) do
|
|
35
36
|
which("docker")
|
36
37
|
end
|
37
38
|
|
39
|
+
def podman_exists?
|
40
|
+
which("podman")
|
41
|
+
end
|
42
|
+
|
38
43
|
collect_data(:linux) do
|
39
44
|
virtualization Mash.new unless virtualization
|
40
45
|
virtualization[:systems] ||= Mash.new
|
@@ -46,6 +51,13 @@ Ohai.plugin(:Virtualization) do
|
|
46
51
|
virtualization[:systems][:docker] = "host"
|
47
52
|
end
|
48
53
|
|
54
|
+
# Podman hosts
|
55
|
+
if podman_exists?
|
56
|
+
virtualization[:system] = "podman"
|
57
|
+
virtualization[:role] = "host"
|
58
|
+
virtualization[:systems][:podman] = "host"
|
59
|
+
end
|
60
|
+
|
49
61
|
# Xen Notes:
|
50
62
|
# - /proc/xen is an empty dir for EL6 + Linode Guests + Paravirt EC2 instances
|
51
63
|
# - cpuid of guests, if we could get it, would also be a clue
|
@@ -115,6 +127,14 @@ Ohai.plugin(:Virtualization) do
|
|
115
127
|
virtualization[:role] = "host"
|
116
128
|
virtualization[:systems][:kvm] = "host"
|
117
129
|
end
|
130
|
+
elsif get_attribute(:cpu, :hypervisor_vendor)
|
131
|
+
if get_attribute(:cpu, :hypervisor_vendor) == "KVM"
|
132
|
+
virtualization[:system] = "kvm"
|
133
|
+
if /(para|full)/.match?(get_attribute(:cpu, :virtualization_type))
|
134
|
+
virtualization[:role] = "guest"
|
135
|
+
virtualization[:systems][:kvm] = "guest"
|
136
|
+
end
|
137
|
+
end
|
118
138
|
end
|
119
139
|
|
120
140
|
# parse dmi to discover various virtualization guests
|
@@ -188,7 +208,7 @@ Ohai.plugin(:Virtualization) do
|
|
188
208
|
# <index #>:<subsystem>:/
|
189
209
|
#
|
190
210
|
# Full notes, https://tickets.opscode.com/browse/OHAI-551
|
191
|
-
# Kernel docs, https://www.kernel.org/doc/Documentation/cgroups
|
211
|
+
# Kernel docs, https://web.archive.org/web/20100514070914/http://www.kernel.org/doc/Documentation/cgroups/
|
192
212
|
if file_exist?("/proc/self/cgroup")
|
193
213
|
cgroup_content = file_read("/proc/self/cgroup")
|
194
214
|
# These two REs catch many different examples. Here's a specific one
|
@@ -210,6 +230,20 @@ Ohai.plugin(:Virtualization) do
|
|
210
230
|
virtualization[:system] = "nspawn"
|
211
231
|
virtualization[:role] = "guest"
|
212
232
|
virtualization[:systems][:nspawn] = "guest"
|
233
|
+
elsif /container=podman/.match?(file_read("/proc/1/environ"))
|
234
|
+
logger.trace("Plugin Virtualization: /proc/1/environ indicates podman container. Detecting as podman guest")
|
235
|
+
virtualization[:system] = "podman"
|
236
|
+
virtualization[:role] = "guest"
|
237
|
+
virtualization[:systems][:podman] = "guest"
|
238
|
+
# Detect any containers that appear to be using docker such as those running on Github Actions virtual machines
|
239
|
+
# but aren't triggered by the cgroup regex above. It's pretty safe to assume if the cgroup contains containerd,
|
240
|
+
# it's likely using docker.
|
241
|
+
# https://rubular.com/r/qhSmV113cPmEBT
|
242
|
+
elsif %r{^\d+:[^:]*:/[^/]+/(containerd)-?.+$}.match?(cgroup_content)
|
243
|
+
logger.trace("Plugin Virtualization: /proc/self/cgroup indicates docker container. Detecting as docker guest")
|
244
|
+
virtualization[:system] = "docker"
|
245
|
+
virtualization[:role] = "guest"
|
246
|
+
virtualization[:systems][:docker] = "guest"
|
213
247
|
elsif lxc_version_exists? && file_read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$}
|
214
248
|
# lxc-version shouldn't be installed by default
|
215
249
|
# Even so, it is likely we are on an LXC capable host that is not being used as such
|
@@ -225,7 +259,11 @@ Ohai.plugin(:Virtualization) do
|
|
225
259
|
# If so, we may need to look further for a differentiator (OHAI-573)
|
226
260
|
virtualization[:systems][:lxc] = "host"
|
227
261
|
end
|
228
|
-
|
262
|
+
end
|
263
|
+
|
264
|
+
# regardless of what we found above, if we're a docker container inside
|
265
|
+
# of the above, lets report as a docker container
|
266
|
+
if file_exist?("/.dockerenv") || file_exist?("/.dockerinit")
|
229
267
|
logger.trace("Plugin Virtualization: .dockerenv or .dockerinit exist. Detecting as docker guest")
|
230
268
|
virtualization[:system] = "docker"
|
231
269
|
virtualization[:role] = "guest"
|
data/lib/ohai/plugins/network.rb
CHANGED
@@ -82,7 +82,7 @@ Ohai.plugin(:NetworkAddresses) do
|
|
82
82
|
elsif network[gw_attr] &&
|
83
83
|
network["interfaces"][network[int_attr]] &&
|
84
84
|
network["interfaces"][network[int_attr]]["addresses"]
|
85
|
-
if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] }
|
85
|
+
if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] } # rubocop: disable Performance/RedundantEqualityComparisonBlock
|
86
86
|
# link level default route
|
87
87
|
logger.trace("Plugin Network: link level default #{family} route, picking ip from #{network[gw_attr]}")
|
88
88
|
r = gw_if_ips.first
|
data/lib/ohai/plugins/os.rb
CHANGED
@@ -106,7 +106,7 @@ Ohai.plugin(:Packages) do
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
def collect_programs_from_registry_key(key_path)
|
109
|
+
def collect_programs_from_registry_key(repo, key_path)
|
110
110
|
# from http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx
|
111
111
|
if ::RbConfig::CONFIG["target_cpu"] == "i386"
|
112
112
|
reg_type = Win32::Registry::KEY_READ | 0x100
|
@@ -115,7 +115,7 @@ Ohai.plugin(:Packages) do
|
|
115
115
|
else
|
116
116
|
reg_type = Win32::Registry::KEY_READ
|
117
117
|
end
|
118
|
-
|
118
|
+
repo.open(key_path, reg_type) do |reg|
|
119
119
|
reg.each_key do |key, _wtime|
|
120
120
|
pkg = reg.open(key)
|
121
121
|
name = pkg["DisplayName"] rescue nil
|
@@ -133,9 +133,10 @@ Ohai.plugin(:Packages) do
|
|
133
133
|
collect_data(:windows) do
|
134
134
|
require "win32/registry" unless defined?(Win32::Registry)
|
135
135
|
packages Mash.new
|
136
|
-
collect_programs_from_registry_key('Software\Microsoft\Windows\CurrentVersion\Uninstall')
|
137
|
-
# on 64 bit systems, 32 bit programs are stored here
|
138
|
-
collect_programs_from_registry_key('Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
|
136
|
+
collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, '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
|
+
collect_programs_from_registry_key(Win32::Registry::HKEY_LOCAL_MACHINE, 'Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall')
|
139
|
+
collect_programs_from_registry_key(Win32::Registry::HKEY_CURRENT_USER, 'Software\Microsoft\Windows\CurrentVersion\Uninstall') rescue nil
|
139
140
|
end
|
140
141
|
|
141
142
|
collect_data(:aix) do
|
@@ -0,0 +1,119 @@
|
|
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
|
+
# new macros are always prefixed by a dash
|
95
|
+
if name
|
96
|
+
# if we had parsed a macro before, store it
|
97
|
+
rpm[:macros][name] = value
|
98
|
+
name = nil
|
99
|
+
value = ""
|
100
|
+
end
|
101
|
+
|
102
|
+
# parse the new macro definition
|
103
|
+
_prefix, name, value = line.split(" ", 3)
|
104
|
+
else
|
105
|
+
# continuations have no prefix and just append to the previous one
|
106
|
+
value += "\n#{line}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Once we're done parsing all lines, we might have a parsed definition
|
111
|
+
# we haven't stored - if so, store it.
|
112
|
+
if name
|
113
|
+
rpm[:macros][name] = value
|
114
|
+
end
|
115
|
+
else
|
116
|
+
logger.trace("Plugin RPM: Could not find rpm. Skipping plugin.")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/lib/ohai/plugins/vmware.rb
CHANGED
@@ -45,12 +45,14 @@ Ohai.plugin(:VMware) do
|
|
45
45
|
logger.trace("Plugin VMware: #{vmtools_path} not found")
|
46
46
|
else
|
47
47
|
vmware Mash.new
|
48
|
+
vmware[:host] = Mash.new
|
49
|
+
vmware[:guest] = Mash.new
|
48
50
|
begin
|
49
51
|
# vmware-toolbox-cmd stat <param> commands
|
50
52
|
# Iterate through each parameter supported by the "vwware-toolbox-cmd stat" command, assign value
|
51
53
|
# to attribute "vmware[:<parameter>]"
|
52
54
|
%w{hosttime speed sessionid balloon swap memlimit memres cpures cpulimit}.each do |param|
|
53
|
-
vmware[param] = from_cmd(
|
55
|
+
vmware[param] = from_cmd([vmtools_path, "stat", param])
|
54
56
|
if /UpdateInfo failed/.match?(vmware[param])
|
55
57
|
vmware[param] = nil
|
56
58
|
end
|
@@ -59,8 +61,23 @@ Ohai.plugin(:VMware) do
|
|
59
61
|
# Iterate through each parameter supported by the "vmware-toolbox-cmd status" command, assign value
|
60
62
|
# to attribute "vmware[:<parameter>]"
|
61
63
|
%w{upgrade timesync}.each do |param|
|
62
|
-
vmware[param] = from_cmd(
|
64
|
+
vmware[param] = from_cmd([vmtools_path, param, "status"])
|
63
65
|
end
|
66
|
+
# Distinguish hypervisors by presence of raw session data (vSphere only)
|
67
|
+
raw_session = from_cmd([vmtools_path, "stat", "raw", "json", "session"])
|
68
|
+
if raw_session.empty?
|
69
|
+
vmware[:host] = {
|
70
|
+
type: "vmware_desktop",
|
71
|
+
}
|
72
|
+
else
|
73
|
+
require "json" unless defined?(JSON)
|
74
|
+
session = JSON.parse(raw_session)
|
75
|
+
vmware[:host] = {
|
76
|
+
type: "vmware_vsphere",
|
77
|
+
version: session["version"],
|
78
|
+
}
|
79
|
+
end
|
80
|
+
vmware[:guest][:vmware_tools_version] = from_cmd([vmtools_path, "-v"]).split(" ").first
|
64
81
|
rescue
|
65
82
|
logger.trace("Plugin VMware: Error while collecting VMware guest attributes")
|
66
83
|
end
|
@@ -71,4 +88,7 @@ Ohai.plugin(:VMware) do
|
|
71
88
|
get_vm_attributes("/usr/bin/vmware-toolbox-cmd") if virtualization[:systems][:vmware]
|
72
89
|
end
|
73
90
|
|
91
|
+
collect_data(:windows) do
|
92
|
+
get_vm_attributes("C:/Program Files/VMWare/VMware Tools/VMwareToolboxCmd.exe") if virtualization[:systems][:vmware]
|
93
|
+
end
|
74
94
|
end
|
data/lib/ohai/runner.rb
CHANGED
@@ -61,7 +61,7 @@ module Ohai
|
|
61
61
|
rescue Ohai::Exceptions::Error, SystemExit # SystemExit: abort or exit from plug-in should exit Ohai with failure code
|
62
62
|
raise
|
63
63
|
rescue Exception => e
|
64
|
-
logger.
|
64
|
+
logger.warn("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
|
65
65
|
end
|
66
66
|
end
|
67
67
|
logger.trace("Plugin #{plugin.name} took #{"%f" % elapsed.truncate(6)} seconds to run.")
|
data/lib/ohai/version.rb
CHANGED
data/ohai.gemspec
CHANGED
@@ -12,24 +12,20 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.email = "adam@chef.io"
|
13
13
|
s.homepage = "https://github.com/chef/ohai/"
|
14
14
|
|
15
|
-
s.required_ruby_version = ">= 2.
|
15
|
+
s.required_ruby_version = ">= 2.7"
|
16
16
|
|
17
|
-
s.add_dependency "chef-config", ">= 12
|
18
|
-
s.add_dependency "chef-utils", ">= 16.0", "<
|
17
|
+
s.add_dependency "chef-config", ">= 14.12", "< 18"
|
18
|
+
s.add_dependency "chef-utils", ">= 16.0", "< 18"
|
19
19
|
s.add_dependency "ffi", "~> 1.9"
|
20
20
|
s.add_dependency "ffi-yajl", "~> 2.2"
|
21
21
|
s.add_dependency "ipaddress"
|
22
22
|
s.add_dependency "mixlib-cli", ">= 1.7.0" # 1.7+ needed to support passing multiple options
|
23
23
|
s.add_dependency "mixlib-config", ">= 2.0", "< 4.0"
|
24
24
|
s.add_dependency "mixlib-log", ">= 2.0.1", "< 4.0"
|
25
|
-
s.add_dependency "mixlib-shellout", "
|
25
|
+
s.add_dependency "mixlib-shellout", "~> 3.2", ">= 3.2.5"
|
26
26
|
s.add_dependency "plist", "~> 3.1"
|
27
27
|
s.add_dependency "train-core"
|
28
28
|
s.add_dependency "wmi-lite", "~> 1.0"
|
29
|
-
# Note for ohai developers: If chef-config causes you grief, try:
|
30
|
-
# bundle install --with development
|
31
|
-
# this should work as long as chef is a development dependency in Gemfile.
|
32
|
-
#
|
33
29
|
|
34
30
|
s.bindir = "bin"
|
35
31
|
s.executables = %w{ohai}
|