ohai 18.0.26 → 18.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +28 -28
- data/LICENSE +201 -201
- data/bin/ohai +25 -25
- data/lib/ohai/application.rb +189 -189
- data/lib/ohai/common/dmi.rb +167 -167
- data/lib/ohai/config.rb +51 -51
- data/lib/ohai/dsl/plugin/versionvii.rb +203 -203
- data/lib/ohai/dsl/plugin.rb +232 -232
- data/lib/ohai/dsl.rb +22 -22
- data/lib/ohai/exception.rb +36 -36
- data/lib/ohai/hints.rb +68 -68
- data/lib/ohai/loader.rb +178 -178
- data/lib/ohai/log.rb +34 -34
- data/lib/ohai/mash.rb +22 -22
- data/lib/ohai/mixin/alibaba_metadata.rb +86 -86
- data/lib/ohai/mixin/azure_metadata.rb +111 -111
- data/lib/ohai/mixin/chef_utils_wiring.rb +52 -52
- data/lib/ohai/mixin/command.rb +4 -4
- data/lib/ohai/mixin/constant_helper.rb +55 -55
- data/lib/ohai/mixin/dmi_decode.rb +54 -54
- data/lib/ohai/mixin/do_metadata.rb +48 -48
- data/lib/ohai/mixin/ec2_metadata.rb +256 -256
- data/lib/ohai/mixin/gce_metadata.rb +83 -83
- data/lib/ohai/mixin/http_helper.rb +64 -64
- data/lib/ohai/mixin/network_helper.rb +65 -65
- data/lib/ohai/mixin/oci_metadata.rb +69 -0
- data/lib/ohai/mixin/os.rb +128 -128
- data/lib/ohai/mixin/scaleway_metadata.rb +51 -51
- data/lib/ohai/mixin/seconds_to_human.rb +52 -52
- data/lib/ohai/mixin/shell_out.rb +51 -51
- data/lib/ohai/mixin/softlayer_metadata.rb +74 -74
- data/lib/ohai/mixin/string.rb +31 -31
- data/lib/ohai/mixin/train_helpers.rb +36 -36
- data/lib/ohai/mixin/which.rb +39 -39
- data/lib/ohai/plugin_config.rb +47 -47
- data/lib/ohai/plugins/aix/kernel.rb +50 -50
- data/lib/ohai/plugins/aix/memory.rb +37 -37
- data/lib/ohai/plugins/aix/network.rb +142 -142
- data/lib/ohai/plugins/aix/platform.rb +30 -30
- data/lib/ohai/plugins/aix/uptime.rb +54 -54
- data/lib/ohai/plugins/aix/virtualization.rb +154 -154
- data/lib/ohai/plugins/alibaba.rb +72 -72
- data/lib/ohai/plugins/azure.rb +154 -154
- data/lib/ohai/plugins/bsd/virtualization.rb +121 -121
- data/lib/ohai/plugins/c.rb +178 -178
- data/lib/ohai/plugins/chef.rb +50 -50
- data/lib/ohai/plugins/cloud.rb +379 -357
- data/lib/ohai/plugins/command.rb +26 -26
- data/lib/ohai/plugins/cpu.rb +635 -635
- data/lib/ohai/plugins/darwin/hardware.rb +99 -99
- data/lib/ohai/plugins/darwin/memory.rb +62 -62
- data/lib/ohai/plugins/darwin/network.rb +207 -207
- data/lib/ohai/plugins/darwin/platform.rb +38 -38
- data/lib/ohai/plugins/darwin/virtualization.rb +90 -93
- data/lib/ohai/plugins/digital_ocean.rb +67 -67
- data/lib/ohai/plugins/dmi.rb +134 -134
- data/lib/ohai/plugins/docker.rb +58 -58
- data/lib/ohai/plugins/dragonflybsd/memory.rb +60 -60
- data/lib/ohai/plugins/dragonflybsd/network.rb +128 -128
- data/lib/ohai/plugins/dragonflybsd/platform.rb +28 -28
- data/lib/ohai/plugins/ec2.rb +148 -148
- data/lib/ohai/plugins/elixir.rb +36 -36
- data/lib/ohai/plugins/erlang.rb +60 -60
- data/lib/ohai/plugins/eucalyptus.rb +86 -86
- data/lib/ohai/plugins/filesystem.rb +751 -751
- data/lib/ohai/plugins/fips.rb +36 -36
- data/lib/ohai/plugins/freebsd/memory.rb +60 -60
- data/lib/ohai/plugins/freebsd/network.rb +128 -128
- data/lib/ohai/plugins/freebsd/platform.rb +28 -28
- data/lib/ohai/plugins/gce.rb +89 -89
- data/lib/ohai/plugins/go.rb +34 -34
- data/lib/ohai/plugins/groovy.rb +38 -38
- data/lib/ohai/plugins/grub2.rb +40 -40
- data/lib/ohai/plugins/habitat.rb +73 -73
- data/lib/ohai/plugins/haskell.rb +96 -96
- data/lib/ohai/plugins/hostname.rb +133 -133
- data/lib/ohai/plugins/init_package.rb +26 -26
- data/lib/ohai/plugins/java.rb +78 -78
- data/lib/ohai/plugins/kernel.rb +292 -292
- data/lib/ohai/plugins/keys.rb +27 -27
- data/lib/ohai/plugins/languages.rb +26 -26
- data/lib/ohai/plugins/libvirt.rb +114 -114
- data/lib/ohai/plugins/linode.rb +73 -73
- data/lib/ohai/plugins/linux/block_device.rb +48 -48
- data/lib/ohai/plugins/linux/hostnamectl.rb +34 -34
- data/lib/ohai/plugins/linux/interrupts.rb +84 -84
- data/lib/ohai/plugins/linux/ipc.rb +52 -52
- data/lib/ohai/plugins/linux/livepatch.rb +38 -38
- data/lib/ohai/plugins/linux/lsb.rb +46 -46
- data/lib/ohai/plugins/linux/lspci.rb +76 -76
- data/lib/ohai/plugins/linux/machineid.rb +36 -36
- data/lib/ohai/plugins/linux/mdadm.rb +120 -120
- data/lib/ohai/plugins/linux/memory.rb +106 -106
- data/lib/ohai/plugins/linux/network.rb +879 -879
- data/lib/ohai/plugins/linux/os_release.rb +38 -38
- data/lib/ohai/plugins/linux/platform.rb +314 -314
- data/lib/ohai/plugins/linux/selinux.rb +69 -69
- data/lib/ohai/plugins/linux/sessions.rb +54 -54
- data/lib/ohai/plugins/linux/sysctl.rb +39 -39
- data/lib/ohai/plugins/linux/systemd_paths.rb +36 -36
- data/lib/ohai/plugins/linux/tc.rb +61 -61
- data/lib/ohai/plugins/linux/virtualization.rb +300 -300
- data/lib/ohai/plugins/lua.rb +39 -39
- data/lib/ohai/plugins/mono.rb +50 -50
- data/lib/ohai/plugins/netbsd/memory.rb +99 -99
- data/lib/ohai/plugins/netbsd/network.rb +122 -122
- data/lib/ohai/plugins/netbsd/platform.rb +28 -28
- data/lib/ohai/plugins/network.rb +186 -186
- data/lib/ohai/plugins/nodejs.rb +40 -40
- data/lib/ohai/plugins/oci.rb +94 -0
- data/lib/ohai/plugins/ohai.rb +29 -29
- data/lib/ohai/plugins/ohai_time.rb +26 -26
- data/lib/ohai/plugins/openbsd/memory.rb +99 -99
- data/lib/ohai/plugins/openbsd/network.rb +122 -122
- data/lib/ohai/plugins/openbsd/platform.rb +28 -28
- data/lib/ohai/plugins/openstack.rb +84 -84
- data/lib/ohai/plugins/os.rb +55 -55
- data/lib/ohai/plugins/packages.rb +234 -234
- data/lib/ohai/plugins/passwd.rb +104 -104
- data/lib/ohai/plugins/perl.rb +45 -45
- data/lib/ohai/plugins/php.rb +52 -52
- data/lib/ohai/plugins/platform.rb +29 -29
- data/lib/ohai/plugins/powershell.rb +82 -82
- data/lib/ohai/plugins/ps.rb +35 -35
- data/lib/ohai/plugins/python.rb +43 -43
- data/lib/ohai/plugins/rackspace.rb +177 -177
- data/lib/ohai/plugins/root_group.rb +41 -41
- data/lib/ohai/plugins/rpm.rb +121 -121
- data/lib/ohai/plugins/ruby.rb +66 -66
- data/lib/ohai/plugins/rust.rb +34 -34
- data/lib/ohai/plugins/scala.rb +38 -38
- data/lib/ohai/plugins/scaleway.rb +58 -58
- data/lib/ohai/plugins/scsi.rb +52 -52
- data/lib/ohai/plugins/shard.rb +142 -142
- data/lib/ohai/plugins/shells.rb +32 -32
- data/lib/ohai/plugins/softlayer.rb +48 -48
- data/lib/ohai/plugins/solaris2/dmi.rb +191 -191
- data/lib/ohai/plugins/solaris2/memory.rb +32 -32
- data/lib/ohai/plugins/solaris2/network.rb +192 -192
- data/lib/ohai/plugins/solaris2/platform.rb +58 -58
- data/lib/ohai/plugins/solaris2/virtualization.rb +90 -90
- data/lib/ohai/plugins/ssh_host_key.rb +84 -84
- data/lib/ohai/plugins/sysconf.rb +46 -46
- data/lib/ohai/plugins/timezone.rb +45 -25
- data/lib/ohai/plugins/train.rb +35 -35
- data/lib/ohai/plugins/uptime.rb +95 -95
- data/lib/ohai/plugins/virtualbox.rb +197 -197
- data/lib/ohai/plugins/vmware.rb +109 -94
- data/lib/ohai/plugins/windows/dmi.rb +95 -95
- data/lib/ohai/plugins/windows/drivers.rb +52 -52
- data/lib/ohai/plugins/windows/memory.rb +39 -39
- data/lib/ohai/plugins/windows/network.rb +222 -222
- data/lib/ohai/plugins/windows/platform.rb +34 -34
- data/lib/ohai/plugins/windows/system_enclosure.rb +29 -29
- data/lib/ohai/plugins/windows/virtualization.rb +45 -45
- data/lib/ohai/plugins/zpools.rb +94 -94
- data/lib/ohai/provides_map.rb +208 -208
- data/lib/ohai/runner.rb +128 -128
- data/lib/ohai/system.rb +258 -258
- data/lib/ohai/train_transport.rb +29 -29
- data/lib/ohai/util/file_helper.rb +6 -6
- data/lib/ohai/util/ip_helper.rb +56 -56
- data/lib/ohai/util/win32.rb +47 -47
- data/lib/ohai/version.rb +23 -23
- data/lib/ohai.rb +23 -23
- data/ohai.gemspec +35 -35
- metadata +5 -3
data/lib/ohai/plugins/kernel.rb
CHANGED
@@ -1,292 +1,292 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Author:: Adam Jacob (<adam@chef.io>)
|
4
|
-
# Author:: Benjamin Black (<nostromo@gmail.com>)
|
5
|
-
# Author:: Bryan McLellan (<btm@loftninjas.org>)
|
6
|
-
# Author:: Claire McQuin (<claire@chef.io>)
|
7
|
-
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
8
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
9
|
-
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
10
|
-
# License:: Apache License, Version 2.0
|
11
|
-
#
|
12
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
13
|
-
# you may not use this file except in compliance with the License.
|
14
|
-
# You may obtain a copy of the License at
|
15
|
-
#
|
16
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
17
|
-
#
|
18
|
-
# Unless required by applicable law or agreed to in writing, software
|
19
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
21
|
-
# implied.
|
22
|
-
# See the License for the specific language governing permissions and
|
23
|
-
# limitations under the License.
|
24
|
-
#
|
25
|
-
|
26
|
-
Ohai.plugin(:Kernel) do
|
27
|
-
provides "kernel", "kernel/modules"
|
28
|
-
|
29
|
-
# common initial kernel attribute values
|
30
|
-
# @return [Mash] basic kernel properties from uname
|
31
|
-
def init_kernel
|
32
|
-
kernel Mash.new
|
33
|
-
[["uname -s", :name], ["uname -r", :release],
|
34
|
-
["uname -v", :version], ["uname -m", :machine],
|
35
|
-
["uname -p", :processor]].each do |cmd, property|
|
36
|
-
so = shell_out(cmd)
|
37
|
-
kernel[property] = so.stdout.strip
|
38
|
-
end
|
39
|
-
kernel
|
40
|
-
end
|
41
|
-
|
42
|
-
# common *bsd code for collecting modules data
|
43
|
-
# @return [Mash]
|
44
|
-
def bsd_modules(path)
|
45
|
-
modules = Mash.new
|
46
|
-
so = shell_out(Ohai.abs_path(path).to_s)
|
47
|
-
so.stdout.lines do |line|
|
48
|
-
# 1 7 0xc0400000 97f830 kernel
|
49
|
-
if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
|
50
|
-
modules[$5] = { size: $4, refcount: $2 }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
modules
|
54
|
-
end
|
55
|
-
|
56
|
-
# given the OperatingSystemSKU value from WMI's Win32_OperatingSystem class
|
57
|
-
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
58
|
-
# return if we're on a Server Core installation
|
59
|
-
# @param [String] sku OperatingSystemSKU value from Win32_OperatingSystem
|
60
|
-
# @return [boolean]
|
61
|
-
def server_core?(sku)
|
62
|
-
return true if [
|
63
|
-
12, # Server Datacenter Core
|
64
|
-
39, # Server Datacenter without Hyper-V Core
|
65
|
-
14, # Server Enterprise Core
|
66
|
-
41, # Server Enterprise without Hyper-V Core
|
67
|
-
13, # Server Standard Core
|
68
|
-
40, # Server Standard without Hyper-V Core
|
69
|
-
63, # Small Business Server Premium Core
|
70
|
-
53, # Server Solutions Premium Core
|
71
|
-
46, # Storage Server Enterprise Core
|
72
|
-
43, # Storage Server Express Core
|
73
|
-
44, # Storage Server Standard Core
|
74
|
-
45, # Storage Server Workgroup Core
|
75
|
-
29, # Web Server Core
|
76
|
-
].include?(sku)
|
77
|
-
|
78
|
-
false
|
79
|
-
end
|
80
|
-
|
81
|
-
# given the SystemType value from WMI's Win32_ComputerSystem class
|
82
|
-
# https://msdn.microsoft.com/en-us/library/aa394102(v=vs.85).aspx
|
83
|
-
# return the architecture type
|
84
|
-
# @param [String] sys_type SystemType value from Win32_ComputerSystem
|
85
|
-
# @return [String] x86_64 or i386
|
86
|
-
def arch_lookup(sys_type)
|
87
|
-
return "x86_64" if sys_type == "x64-based PC"
|
88
|
-
return "i386" if sys_type == "X86-based PC"
|
89
|
-
|
90
|
-
sys_type
|
91
|
-
end
|
92
|
-
|
93
|
-
# given the ProductType value from WMI's Win32_OperatingSystem class
|
94
|
-
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
95
|
-
# return either workstation or server
|
96
|
-
# @param [Integer] type ProductType value from Win32_OperatingSystem
|
97
|
-
# @return [String] Workstation or Server
|
98
|
-
def product_type_decode(type)
|
99
|
-
return "Workstation" if type == 1
|
100
|
-
|
101
|
-
"Server"
|
102
|
-
end
|
103
|
-
|
104
|
-
# decode the OSType field from WMI Win32_OperatingSystem class
|
105
|
-
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
106
|
-
# @param [Integer] sys_type OSType value from Win32_OperatingSystem
|
107
|
-
# @return [String] the human consumable OS type value
|
108
|
-
def os_type_decode(sys_type)
|
109
|
-
case sys_type
|
110
|
-
when 18 then "WINNT" # most likely so first
|
111
|
-
when 0 then "Unknown"
|
112
|
-
when 1 then "Other"
|
113
|
-
when 14 then "MSDOS"
|
114
|
-
when 15 then "WIN3x"
|
115
|
-
when 16 then "WIN95"
|
116
|
-
when 17 then "WIN98"
|
117
|
-
when 19 then "WINCE"
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
# decode the PCSystemType field from WMI Win32_OperatingSystem class
|
122
|
-
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
123
|
-
# @param [Integer] type the integer value from PCSystemType
|
124
|
-
# @return [String] the human consumable OS type value
|
125
|
-
def pc_system_type_decode(type)
|
126
|
-
case type
|
127
|
-
when 4 then "Enterprise Server" # most likely so first
|
128
|
-
when 0 then "Unspecified"
|
129
|
-
when 1 then "Desktop"
|
130
|
-
when 2 then "Mobile"
|
131
|
-
when 3 then "Workstation"
|
132
|
-
when 5 then "SOHO Server"
|
133
|
-
when 6 then "Appliance PC"
|
134
|
-
when 7 then "Performance Server"
|
135
|
-
when 8 then "Maximum"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
# see if a WMI name is in the blocked list so we can avoid writing
|
140
|
-
# out useless data to ohai
|
141
|
-
#
|
142
|
-
# @param [String] name the wmi name to check
|
143
|
-
# @return [Boolean] is the wmi name in the blocked list
|
144
|
-
def blocked_wmi_name?(name)
|
145
|
-
[
|
146
|
-
"creation_class_name", # this is just the wmi name
|
147
|
-
"cs_creation_class_name", # this is just the wmi name
|
148
|
-
"oem_logo_bitmap", # this is the entire OEM bitmap file
|
149
|
-
"total_swap_space_size", # already in memory plugin
|
150
|
-
"total_virtual_memory_size", # already in memory plugin
|
151
|
-
"total_virtual_memory_size", # already in memory plugin
|
152
|
-
"free_physical_memory", # already in memory plugin
|
153
|
-
"free_space_in_paging_files", # already in memory plugin
|
154
|
-
"free_virtual_memory", # already in memory plugin
|
155
|
-
].include?(name)
|
156
|
-
end
|
157
|
-
|
158
|
-
collect_data(:target) do
|
159
|
-
# intentionally left blank
|
160
|
-
end
|
161
|
-
|
162
|
-
collect_data(:default) do
|
163
|
-
kernel init_kernel
|
164
|
-
end
|
165
|
-
|
166
|
-
collect_data(:darwin) do
|
167
|
-
kernel init_kernel
|
168
|
-
kernel[:os] = kernel[:name]
|
169
|
-
|
170
|
-
so = shell_out("sysctl -n hw.optional.x86_64")
|
171
|
-
if so.stdout.strip.to_i == 1
|
172
|
-
kernel[:machine] = "x86_64"
|
173
|
-
end
|
174
|
-
|
175
|
-
modules = Mash.new
|
176
|
-
so = shell_out("kextstat -k -l")
|
177
|
-
so.stdout.lines do |line|
|
178
|
-
if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/
|
179
|
-
modules[$4] = { version: $5, size: $3.hex, index: $1, refcount: $2 }
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
kernel[:modules] = modules
|
184
|
-
end
|
185
|
-
|
186
|
-
collect_data(:freebsd, :dragonflybsd) do
|
187
|
-
kernel init_kernel
|
188
|
-
kernel[:os] = kernel[:name]
|
189
|
-
|
190
|
-
so = shell_out("uname -i")
|
191
|
-
kernel[:ident] = so.stdout.strip
|
192
|
-
so = shell_out("sysctl kern.securelevel")
|
193
|
-
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
|
194
|
-
|
195
|
-
kernel[:modules] = bsd_modules("/sbin/kldstat")
|
196
|
-
end
|
197
|
-
|
198
|
-
collect_data(:linux) do
|
199
|
-
kernel init_kernel
|
200
|
-
|
201
|
-
so = shell_out("uname -o")
|
202
|
-
kernel[:os] = so.stdout.strip
|
203
|
-
|
204
|
-
modules = Mash.new
|
205
|
-
so = shell_out("env lsmod")
|
206
|
-
so.stdout.lines do |line|
|
207
|
-
if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
|
208
|
-
modules[$1] = { size: $2, refcount: $3 }
|
209
|
-
# Making sure to get the module version that has been loaded
|
210
|
-
if file_exist?("/sys/module/#{$1}/version")
|
211
|
-
version = file_read("/sys/module/#{$1}/version").chomp.strip
|
212
|
-
modules[$1]["version"] = version unless version.empty?
|
213
|
-
end
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
kernel[:modules] = modules
|
218
|
-
end
|
219
|
-
|
220
|
-
collect_data(:netbsd, :openbsd) do
|
221
|
-
kernel init_kernel
|
222
|
-
kernel[:os] = kernel[:name]
|
223
|
-
|
224
|
-
so = shell_out("sysctl kern.securelevel")
|
225
|
-
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
|
226
|
-
|
227
|
-
kernel[:modules] = bsd_modules("/usr/bin/modstat")
|
228
|
-
end
|
229
|
-
|
230
|
-
collect_data(:solaris2) do
|
231
|
-
kernel init_kernel
|
232
|
-
|
233
|
-
so = shell_out("uname -s")
|
234
|
-
kernel[:os] = so.stdout.strip
|
235
|
-
|
236
|
-
so = file_open("/etc/release", &:gets)
|
237
|
-
md = /(?<update>\d.*\d)/.match(so)
|
238
|
-
kernel[:update] = md[:update] if md
|
239
|
-
|
240
|
-
modules = Mash.new
|
241
|
-
|
242
|
-
so = shell_out("modinfo")
|
243
|
-
# EXAMPLE:
|
244
|
-
# Id Loadaddr Size Info Rev Module Name
|
245
|
-
# 6 1180000 4623 1 1 specfs (filesystem for specfs)
|
246
|
-
module_description = /\s*(\d+)\s+([a-f\d]+)\s+([a-f\d]+)\s+(?:[\-\d]+)\s+(?:\d+)\s+(\S+)\s+\((.+)\)$/
|
247
|
-
so.stdout.lines do |line|
|
248
|
-
if ( mod = module_description.match(line) )
|
249
|
-
modules[mod[4]] = { id: mod[1].to_i, loadaddr: mod[2], size: mod[3].to_i(16), description: mod[5] }
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
kernel[:modules] = modules
|
254
|
-
end
|
255
|
-
|
256
|
-
collect_data(:windows) do
|
257
|
-
require "win32ole" unless defined?(WIN32OLE)
|
258
|
-
require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
|
259
|
-
|
260
|
-
WIN32OLE.codepage = WIN32OLE::CP_UTF8
|
261
|
-
|
262
|
-
wmi = WmiLite::Wmi.new
|
263
|
-
|
264
|
-
kernel Mash.new
|
265
|
-
|
266
|
-
host = wmi.first_of("Win32_OperatingSystem")
|
267
|
-
kernel[:os_info] = Mash.new
|
268
|
-
host.wmi_ole_object.properties_.each do |p|
|
269
|
-
next if blocked_wmi_name?(p.name.wmi_underscore)
|
270
|
-
|
271
|
-
kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
|
272
|
-
end
|
273
|
-
|
274
|
-
kernel[:name] = (kernel[:os_info][:caption]).to_s
|
275
|
-
kernel[:release] = (kernel[:os_info][:version]).to_s
|
276
|
-
kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
|
277
|
-
kernel[:os] = os_type_decode(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
|
278
|
-
kernel[:product_type] = product_type_decode(kernel[:os_info][:product_type])
|
279
|
-
kernel[:server_core] = server_core?(kernel[:os_info][:operating_system_sku])
|
280
|
-
|
281
|
-
kernel[:cs_info] = Mash.new
|
282
|
-
host = wmi.first_of("Win32_ComputerSystem")
|
283
|
-
host.wmi_ole_object.properties_.each do |p|
|
284
|
-
next if blocked_wmi_name?(p.name.wmi_underscore)
|
285
|
-
|
286
|
-
kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
|
287
|
-
end
|
288
|
-
|
289
|
-
kernel[:machine] = arch_lookup((kernel[:cs_info][:system_type]).to_s)
|
290
|
-
kernel[:system_type] = pc_system_type_decode(kernel[:cs_info][:pc_system_type])
|
291
|
-
end
|
292
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Author:: Adam Jacob (<adam@chef.io>)
|
4
|
+
# Author:: Benjamin Black (<nostromo@gmail.com>)
|
5
|
+
# Author:: Bryan McLellan (<btm@loftninjas.org>)
|
6
|
+
# Author:: Claire McQuin (<claire@chef.io>)
|
7
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
8
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
9
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
10
|
+
# License:: Apache License, Version 2.0
|
11
|
+
#
|
12
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
13
|
+
# you may not use this file except in compliance with the License.
|
14
|
+
# You may obtain a copy of the License at
|
15
|
+
#
|
16
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
17
|
+
#
|
18
|
+
# Unless required by applicable law or agreed to in writing, software
|
19
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
20
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
21
|
+
# implied.
|
22
|
+
# See the License for the specific language governing permissions and
|
23
|
+
# limitations under the License.
|
24
|
+
#
|
25
|
+
|
26
|
+
Ohai.plugin(:Kernel) do
|
27
|
+
provides "kernel", "kernel/modules"
|
28
|
+
|
29
|
+
# common initial kernel attribute values
|
30
|
+
# @return [Mash] basic kernel properties from uname
|
31
|
+
def init_kernel
|
32
|
+
kernel Mash.new
|
33
|
+
[["uname -s", :name], ["uname -r", :release],
|
34
|
+
["uname -v", :version], ["uname -m", :machine],
|
35
|
+
["uname -p", :processor]].each do |cmd, property|
|
36
|
+
so = shell_out(cmd)
|
37
|
+
kernel[property] = so.stdout.strip
|
38
|
+
end
|
39
|
+
kernel
|
40
|
+
end
|
41
|
+
|
42
|
+
# common *bsd code for collecting modules data
|
43
|
+
# @return [Mash]
|
44
|
+
def bsd_modules(path)
|
45
|
+
modules = Mash.new
|
46
|
+
so = shell_out(Ohai.abs_path(path).to_s)
|
47
|
+
so.stdout.lines do |line|
|
48
|
+
# 1 7 0xc0400000 97f830 kernel
|
49
|
+
if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
|
50
|
+
modules[$5] = { size: $4, refcount: $2 }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
modules
|
54
|
+
end
|
55
|
+
|
56
|
+
# given the OperatingSystemSKU value from WMI's Win32_OperatingSystem class
|
57
|
+
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
58
|
+
# return if we're on a Server Core installation
|
59
|
+
# @param [String] sku OperatingSystemSKU value from Win32_OperatingSystem
|
60
|
+
# @return [boolean]
|
61
|
+
def server_core?(sku)
|
62
|
+
return true if [
|
63
|
+
12, # Server Datacenter Core
|
64
|
+
39, # Server Datacenter without Hyper-V Core
|
65
|
+
14, # Server Enterprise Core
|
66
|
+
41, # Server Enterprise without Hyper-V Core
|
67
|
+
13, # Server Standard Core
|
68
|
+
40, # Server Standard without Hyper-V Core
|
69
|
+
63, # Small Business Server Premium Core
|
70
|
+
53, # Server Solutions Premium Core
|
71
|
+
46, # Storage Server Enterprise Core
|
72
|
+
43, # Storage Server Express Core
|
73
|
+
44, # Storage Server Standard Core
|
74
|
+
45, # Storage Server Workgroup Core
|
75
|
+
29, # Web Server Core
|
76
|
+
].include?(sku)
|
77
|
+
|
78
|
+
false
|
79
|
+
end
|
80
|
+
|
81
|
+
# given the SystemType value from WMI's Win32_ComputerSystem class
|
82
|
+
# https://msdn.microsoft.com/en-us/library/aa394102(v=vs.85).aspx
|
83
|
+
# return the architecture type
|
84
|
+
# @param [String] sys_type SystemType value from Win32_ComputerSystem
|
85
|
+
# @return [String] x86_64 or i386
|
86
|
+
def arch_lookup(sys_type)
|
87
|
+
return "x86_64" if sys_type == "x64-based PC"
|
88
|
+
return "i386" if sys_type == "X86-based PC"
|
89
|
+
|
90
|
+
sys_type
|
91
|
+
end
|
92
|
+
|
93
|
+
# given the ProductType value from WMI's Win32_OperatingSystem class
|
94
|
+
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
95
|
+
# return either workstation or server
|
96
|
+
# @param [Integer] type ProductType value from Win32_OperatingSystem
|
97
|
+
# @return [String] Workstation or Server
|
98
|
+
def product_type_decode(type)
|
99
|
+
return "Workstation" if type == 1
|
100
|
+
|
101
|
+
"Server"
|
102
|
+
end
|
103
|
+
|
104
|
+
# decode the OSType field from WMI Win32_OperatingSystem class
|
105
|
+
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
106
|
+
# @param [Integer] sys_type OSType value from Win32_OperatingSystem
|
107
|
+
# @return [String] the human consumable OS type value
|
108
|
+
def os_type_decode(sys_type)
|
109
|
+
case sys_type
|
110
|
+
when 18 then "WINNT" # most likely so first
|
111
|
+
when 0 then "Unknown"
|
112
|
+
when 1 then "Other"
|
113
|
+
when 14 then "MSDOS"
|
114
|
+
when 15 then "WIN3x"
|
115
|
+
when 16 then "WIN95"
|
116
|
+
when 17 then "WIN98"
|
117
|
+
when 19 then "WINCE"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# decode the PCSystemType field from WMI Win32_OperatingSystem class
|
122
|
+
# https://msdn.microsoft.com/en-us/library/aa394239(v=vs.85).aspx
|
123
|
+
# @param [Integer] type the integer value from PCSystemType
|
124
|
+
# @return [String] the human consumable OS type value
|
125
|
+
def pc_system_type_decode(type)
|
126
|
+
case type
|
127
|
+
when 4 then "Enterprise Server" # most likely so first
|
128
|
+
when 0 then "Unspecified"
|
129
|
+
when 1 then "Desktop"
|
130
|
+
when 2 then "Mobile"
|
131
|
+
when 3 then "Workstation"
|
132
|
+
when 5 then "SOHO Server"
|
133
|
+
when 6 then "Appliance PC"
|
134
|
+
when 7 then "Performance Server"
|
135
|
+
when 8 then "Maximum"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# see if a WMI name is in the blocked list so we can avoid writing
|
140
|
+
# out useless data to ohai
|
141
|
+
#
|
142
|
+
# @param [String] name the wmi name to check
|
143
|
+
# @return [Boolean] is the wmi name in the blocked list
|
144
|
+
def blocked_wmi_name?(name)
|
145
|
+
[
|
146
|
+
"creation_class_name", # this is just the wmi name
|
147
|
+
"cs_creation_class_name", # this is just the wmi name
|
148
|
+
"oem_logo_bitmap", # this is the entire OEM bitmap file
|
149
|
+
"total_swap_space_size", # already in memory plugin
|
150
|
+
"total_virtual_memory_size", # already in memory plugin
|
151
|
+
"total_virtual_memory_size", # already in memory plugin
|
152
|
+
"free_physical_memory", # already in memory plugin
|
153
|
+
"free_space_in_paging_files", # already in memory plugin
|
154
|
+
"free_virtual_memory", # already in memory plugin
|
155
|
+
].include?(name)
|
156
|
+
end
|
157
|
+
|
158
|
+
collect_data(:target) do
|
159
|
+
# intentionally left blank
|
160
|
+
end
|
161
|
+
|
162
|
+
collect_data(:default) do
|
163
|
+
kernel init_kernel
|
164
|
+
end
|
165
|
+
|
166
|
+
collect_data(:darwin) do
|
167
|
+
kernel init_kernel
|
168
|
+
kernel[:os] = kernel[:name]
|
169
|
+
|
170
|
+
so = shell_out("sysctl -n hw.optional.x86_64")
|
171
|
+
if so.stdout.strip.to_i == 1
|
172
|
+
kernel[:machine] = "x86_64"
|
173
|
+
end
|
174
|
+
|
175
|
+
modules = Mash.new
|
176
|
+
so = shell_out("kextstat -k -l")
|
177
|
+
so.stdout.lines do |line|
|
178
|
+
if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/
|
179
|
+
modules[$4] = { version: $5, size: $3.hex, index: $1, refcount: $2 }
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
kernel[:modules] = modules
|
184
|
+
end
|
185
|
+
|
186
|
+
collect_data(:freebsd, :dragonflybsd) do
|
187
|
+
kernel init_kernel
|
188
|
+
kernel[:os] = kernel[:name]
|
189
|
+
|
190
|
+
so = shell_out("uname -i")
|
191
|
+
kernel[:ident] = so.stdout.strip
|
192
|
+
so = shell_out("sysctl kern.securelevel")
|
193
|
+
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
|
194
|
+
|
195
|
+
kernel[:modules] = bsd_modules("/sbin/kldstat")
|
196
|
+
end
|
197
|
+
|
198
|
+
collect_data(:linux) do
|
199
|
+
kernel init_kernel
|
200
|
+
|
201
|
+
so = shell_out("uname -o")
|
202
|
+
kernel[:os] = so.stdout.strip
|
203
|
+
|
204
|
+
modules = Mash.new
|
205
|
+
so = shell_out("env lsmod")
|
206
|
+
so.stdout.lines do |line|
|
207
|
+
if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
|
208
|
+
modules[$1] = { size: $2, refcount: $3 }
|
209
|
+
# Making sure to get the module version that has been loaded
|
210
|
+
if file_exist?("/sys/module/#{$1}/version")
|
211
|
+
version = file_read("/sys/module/#{$1}/version").chomp.strip
|
212
|
+
modules[$1]["version"] = version unless version.empty?
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
kernel[:modules] = modules
|
218
|
+
end
|
219
|
+
|
220
|
+
collect_data(:netbsd, :openbsd) do
|
221
|
+
kernel init_kernel
|
222
|
+
kernel[:os] = kernel[:name]
|
223
|
+
|
224
|
+
so = shell_out("sysctl kern.securelevel")
|
225
|
+
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
|
226
|
+
|
227
|
+
kernel[:modules] = bsd_modules("/usr/bin/modstat")
|
228
|
+
end
|
229
|
+
|
230
|
+
collect_data(:solaris2) do
|
231
|
+
kernel init_kernel
|
232
|
+
|
233
|
+
so = shell_out("uname -s")
|
234
|
+
kernel[:os] = so.stdout.strip
|
235
|
+
|
236
|
+
so = file_open("/etc/release", &:gets)
|
237
|
+
md = /(?<update>\d.*\d)/.match(so)
|
238
|
+
kernel[:update] = md[:update] if md
|
239
|
+
|
240
|
+
modules = Mash.new
|
241
|
+
|
242
|
+
so = shell_out("modinfo")
|
243
|
+
# EXAMPLE:
|
244
|
+
# Id Loadaddr Size Info Rev Module Name
|
245
|
+
# 6 1180000 4623 1 1 specfs (filesystem for specfs)
|
246
|
+
module_description = /\s*(\d+)\s+([a-f\d]+)\s+([a-f\d]+)\s+(?:[\-\d]+)\s+(?:\d+)\s+(\S+)\s+\((.+)\)$/
|
247
|
+
so.stdout.lines do |line|
|
248
|
+
if ( mod = module_description.match(line) )
|
249
|
+
modules[mod[4]] = { id: mod[1].to_i, loadaddr: mod[2], size: mod[3].to_i(16), description: mod[5] }
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
kernel[:modules] = modules
|
254
|
+
end
|
255
|
+
|
256
|
+
collect_data(:windows) do
|
257
|
+
require "win32ole" unless defined?(WIN32OLE)
|
258
|
+
require "wmi-lite/wmi" unless defined?(WmiLite::Wmi)
|
259
|
+
|
260
|
+
WIN32OLE.codepage = WIN32OLE::CP_UTF8
|
261
|
+
|
262
|
+
wmi = WmiLite::Wmi.new
|
263
|
+
|
264
|
+
kernel Mash.new
|
265
|
+
|
266
|
+
host = wmi.first_of("Win32_OperatingSystem")
|
267
|
+
kernel[:os_info] = Mash.new
|
268
|
+
host.wmi_ole_object.properties_.each do |p|
|
269
|
+
next if blocked_wmi_name?(p.name.wmi_underscore)
|
270
|
+
|
271
|
+
kernel[:os_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
|
272
|
+
end
|
273
|
+
|
274
|
+
kernel[:name] = (kernel[:os_info][:caption]).to_s
|
275
|
+
kernel[:release] = (kernel[:os_info][:version]).to_s
|
276
|
+
kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
|
277
|
+
kernel[:os] = os_type_decode(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
|
278
|
+
kernel[:product_type] = product_type_decode(kernel[:os_info][:product_type])
|
279
|
+
kernel[:server_core] = server_core?(kernel[:os_info][:operating_system_sku])
|
280
|
+
|
281
|
+
kernel[:cs_info] = Mash.new
|
282
|
+
host = wmi.first_of("Win32_ComputerSystem")
|
283
|
+
host.wmi_ole_object.properties_.each do |p|
|
284
|
+
next if blocked_wmi_name?(p.name.wmi_underscore)
|
285
|
+
|
286
|
+
kernel[:cs_info][p.name.wmi_underscore.to_sym] = host[p.name.downcase]
|
287
|
+
end
|
288
|
+
|
289
|
+
kernel[:machine] = arch_lookup((kernel[:cs_info][:system_type]).to_s)
|
290
|
+
kernel[:system_type] = pc_system_type_decode(kernel[:cs_info][:pc_system_type])
|
291
|
+
end
|
292
|
+
end
|
data/lib/ohai/plugins/keys.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
#
|
3
|
-
# Cookbook Name:: apache2
|
4
|
-
# Recipe:: default
|
5
|
-
#
|
6
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
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(:Keys) do
|
22
|
-
provides "keys"
|
23
|
-
|
24
|
-
collect_data do
|
25
|
-
keys Mash.new
|
26
|
-
end
|
27
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Cookbook Name:: apache2
|
4
|
+
# Recipe:: default
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
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(:Keys) do
|
22
|
+
provides "keys"
|
23
|
+
|
24
|
+
collect_data do
|
25
|
+
keys Mash.new
|
26
|
+
end
|
27
|
+
end
|