ohai 8.26.1 → 13.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +3 -4
- data/Rakefile +14 -0
- data/lib/ohai/application.rb +1 -0
- data/lib/ohai/config.rb +2 -88
- data/lib/ohai/dsl/plugin.rb +0 -4
- data/lib/ohai/exception.rb +0 -1
- data/lib/ohai/loader.rb +11 -2
- data/lib/ohai/log.rb +3 -1
- data/lib/ohai/mixin/command.rb +1 -318
- data/lib/ohai/mixin/do_metadata.rb +47 -0
- data/lib/ohai/mixin/ec2_metadata.rb +2 -29
- data/lib/ohai/mixin/gce_metadata.rb +0 -37
- data/lib/ohai/mixin/http_helper.rb +56 -0
- data/lib/ohai/mixin/network_constants.rb +0 -5
- data/lib/ohai/plugins/cloud.rb +144 -157
- data/lib/ohai/plugins/darwin/filesystem.rb +68 -22
- data/lib/ohai/plugins/digital_ocean.rb +24 -42
- data/lib/ohai/plugins/dmi.rb +81 -77
- data/lib/ohai/plugins/ec2.rb +33 -60
- data/lib/ohai/plugins/gce.rb +3 -1
- data/lib/ohai/plugins/hostname.rb +1 -16
- data/lib/ohai/plugins/linux/filesystem.rb +130 -81
- data/lib/ohai/plugins/linux/mdadm.rb +3 -45
- data/lib/ohai/plugins/linux/network.rb +1 -26
- data/lib/ohai/plugins/linux/platform.rb +4 -2
- data/lib/ohai/plugins/linux/virtualization.rb +1 -5
- data/lib/ohai/plugins/scala.rb +1 -13
- data/lib/ohai/plugins/solaris2/network.rb +1 -2
- data/lib/ohai/plugins/uptime.rb +0 -9
- data/lib/ohai/plugins/windows/cpu.rb +2 -1
- data/lib/ohai/plugins/windows/network.rb +1 -1
- data/lib/ohai/runner.rb +0 -5
- data/lib/ohai/system.rb +38 -8
- data/lib/ohai/version.rb +2 -2
- data/ohai.gemspec +1 -1
- data/spec/functional/application_spec.rb +0 -40
- data/spec/functional/plugins/powershell_spec.rb +1 -1
- data/spec/functional/plugins/root_group_spec.rb +1 -1
- data/spec/functional/plugins/windows/uptime_spec.rb +1 -1
- data/spec/ohai_spec.rb +1 -1
- data/spec/support/integration_helper.rb +17 -0
- data/spec/support/platform_helpers.rb +17 -0
- data/spec/unit/application_spec.rb +0 -1
- data/spec/unit/config_spec.rb +0 -111
- data/spec/unit/dsl/plugin_spec.rb +1 -1
- data/spec/unit/hints_spec.rb +1 -1
- data/spec/unit/loader_spec.rb +26 -1
- data/spec/unit/mixin/command_spec.rb +1 -69
- data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
- data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
- data/spec/unit/plugin_config_spec.rb +0 -1
- data/spec/unit/plugins/abort_spec.rb +1 -1
- data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
- data/spec/unit/plugins/aix/filesystem_spec.rb +2 -1
- data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
- data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
- data/spec/unit/plugins/aix/memory_spec.rb +1 -1
- data/spec/unit/plugins/aix/network_spec.rb +1 -1
- data/spec/unit/plugins/aix/os_spec.rb +1 -1
- data/spec/unit/plugins/aix/platform_spec.rb +1 -1
- data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
- data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/azure_spec.rb +1 -1
- data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
- data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/c_spec.rb +1 -1
- data/spec/unit/plugins/chef_spec.rb +1 -2
- data/spec/unit/plugins/cloud_spec.rb +210 -50
- data/spec/unit/plugins/darwin/cpu_spec.rb +1 -1
- data/spec/unit/plugins/darwin/filesystem_spec.rb +62 -13
- data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
- data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
- data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
- data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
- data/spec/unit/plugins/darwin/network_spec.rb +1 -1
- data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +2 -9
- data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/digital_ocean_spec.rb +39 -110
- data/spec/unit/plugins/dmi_spec.rb +1 -1
- data/spec/unit/plugins/ec2_spec.rb +10 -62
- data/spec/unit/plugins/elixir_spec.rb +1 -1
- data/spec/unit/plugins/erlang_spec.rb +1 -1
- data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
- data/spec/unit/plugins/fail_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/os_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/gce_spec.rb +1 -1
- data/spec/unit/plugins/go_spec.rb +1 -1
- data/spec/unit/plugins/groovy_spec.rb +1 -1
- data/spec/unit/plugins/haskell_spec.rb +1 -1
- data/spec/unit/plugins/hostname_spec.rb +16 -41
- data/spec/unit/plugins/init_package_spec.rb +1 -1
- data/spec/unit/plugins/ip_scopes_spec.rb +18 -6
- data/spec/unit/plugins/java_spec.rb +1 -1
- data/spec/unit/plugins/joyent_spec.rb +17 -1
- data/spec/unit/plugins/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linode_spec.rb +1 -1
- data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
- data/spec/unit/plugins/linux/cpu_spec.rb +1 -2
- data/spec/unit/plugins/linux/filesystem_spec.rb +207 -201
- data/spec/unit/plugins/linux/fips_spec.rb +1 -1
- data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
- data/spec/unit/plugins/linux/hostnamectl_spec.rb +1 -1
- data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linux/lsb_spec.rb +1 -1
- data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
- data/spec/unit/plugins/linux/mdadm_spec.rb +2 -68
- data/spec/unit/plugins/linux/memory_spec.rb +1 -1
- data/spec/unit/plugins/linux/network_spec.rb +3 -44
- data/spec/unit/plugins/linux/platform_spec.rb +4 -4
- data/spec/unit/plugins/linux/sessions_spec.rb +1 -1
- data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
- data/spec/unit/plugins/linux/virtualization_spec.rb +1 -28
- data/spec/unit/plugins/lua_spec.rb +1 -1
- data/spec/unit/plugins/mono_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/network_spec.rb +1 -1
- data/spec/unit/plugins/nodejs_spec.rb +1 -1
- data/spec/unit/plugins/ohai_spec.rb +1 -1
- data/spec/unit/plugins/ohai_time_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
- data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
- data/spec/unit/plugins/openstack_spec.rb +2 -3
- data/spec/unit/plugins/os_spec.rb +1 -1
- data/spec/unit/plugins/packages_spec.rb +1 -1
- data/spec/unit/plugins/passwd_spec.rb +17 -1
- data/spec/unit/plugins/perl_spec.rb +1 -1
- data/spec/unit/plugins/php_spec.rb +1 -1
- data/spec/unit/plugins/platform_spec.rb +1 -1
- data/spec/unit/plugins/powershell_spec.rb +1 -1
- data/spec/unit/plugins/python_spec.rb +1 -1
- data/spec/unit/plugins/rackspace_spec.rb +1 -2
- data/spec/unit/plugins/root_group_spec.rb +2 -2
- data/spec/unit/plugins/ruby_spec.rb +1 -1
- data/spec/unit/plugins/rust_spec.rb +1 -1
- data/spec/unit/plugins/scala_spec.rb +3 -37
- data/spec/unit/plugins/shard_spec.rb +1 -1
- data/spec/unit/plugins/shells_spec.rb +1 -1
- data/spec/unit/plugins/softlayer_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/network_spec.rb +7 -4
- data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/solaris2/zpools_spec.rb +1 -1
- data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
- data/spec/unit/plugins/sysconf_spec.rb +1 -1
- data/spec/unit/plugins/timezone_spec.rb +1 -1
- data/spec/unit/plugins/virtualbox_spec.rb +1 -1
- data/spec/unit/plugins/vmware_spec.rb +2 -1
- data/spec/unit/plugins/windows/cpu_spec.rb +9 -2
- data/spec/unit/plugins/windows/fips_spec.rb +1 -1
- data/spec/unit/plugins/windows/memory_spec.rb +1 -1
- data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
- data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
- data/spec/unit/provides_map_spec.rb +1 -1
- data/spec/unit/runner_spec.rb +1 -1
- data/spec/unit/system_spec.rb +68 -76
- data/spec/unit/util/file_helper_spec.rb +1 -1
- data/spec/unit/util/ip_helper_spec.rb +1 -1
- metadata +6 -20
- data/lib/ohai/plugins/cloud_v2.rb +0 -315
- data/lib/ohai/plugins/darwin/filesystem2.rb +0 -107
- data/lib/ohai/plugins/linux/filesystem2.rb +0 -223
- data/lib/ohai/plugins/linux/lspci.rb +0 -76
- data/lib/ohai/plugins/network_listeners.rb +0 -60
- data/lib/ohai/plugins/sigar/cpu.rb +0 -44
- data/lib/ohai/plugins/sigar/filesystem.rb +0 -50
- data/lib/ohai/plugins/sigar/memory.rb +0 -39
- data/lib/ohai/plugins/sigar/network.rb +0 -168
- data/lib/ohai/plugins/sigar/network_route.rb +0 -64
- data/lib/ohai/plugins/sigar/platform.rb +0 -30
- data/spec/unit/plugins/cloud_v2_spec.rb +0 -389
- data/spec/unit/plugins/darwin/filesystem2_spec.rb +0 -139
- data/spec/unit/plugins/linux/filesystem2_spec.rb +0 -437
- data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
- data/spec/unit/plugins/sigar/network_route_spec.rb +0 -148
@@ -1,6 +1,8 @@
|
|
1
1
|
#
|
2
|
+
# Author:: Phil Dibowitz (<phil@ipom.com>)
|
2
3
|
# Author:: Benjamin Black (<bb@chef.io>)
|
3
4
|
# Copyright:: Copyright (c) 2009-2016 Chef Software, Inc.
|
5
|
+
# Copyright:: Copyright (c) 2015 Facebook, Inc.
|
4
6
|
# License:: Apache License, Version 2.0
|
5
7
|
#
|
6
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -18,46 +20,90 @@
|
|
18
20
|
|
19
21
|
Ohai.plugin(:Filesystem) do
|
20
22
|
provides "filesystem"
|
23
|
+
provides "filesystem2"
|
24
|
+
|
25
|
+
def generate_device_view(fs)
|
26
|
+
view = {}
|
27
|
+
fs.each_value do |entry|
|
28
|
+
view[entry[:device]] = Mash.new unless view[entry[:device]]
|
29
|
+
entry.each do |key, val|
|
30
|
+
next if %w{device mount}.include?(key)
|
31
|
+
view[entry[:device]][key] = val
|
32
|
+
end
|
33
|
+
if entry[:mount]
|
34
|
+
view[entry[:device]][:mounts] = [] unless view[entry[:device]][:mounts]
|
35
|
+
view[entry[:device]][:mounts] << entry[:mount]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
view
|
39
|
+
end
|
40
|
+
|
41
|
+
def generate_mountpoint_view(fs)
|
42
|
+
view = {}
|
43
|
+
fs.each_value do |entry|
|
44
|
+
next unless entry[:mount]
|
45
|
+
view[entry[:mount]] = Mash.new unless view[entry[:mount]]
|
46
|
+
entry.each do |key, val|
|
47
|
+
next if %w{mount device}.include?(key)
|
48
|
+
view[entry[:mount]][key] = val
|
49
|
+
end
|
50
|
+
if entry[:device]
|
51
|
+
view[entry[:mount]][:devices] = [] unless view[entry[:mount]][:devices]
|
52
|
+
view[entry[:mount]][:devices] << entry[:device]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
view
|
56
|
+
end
|
21
57
|
|
22
58
|
collect_data(:darwin) do
|
23
59
|
fs = Mash.new
|
24
|
-
|
25
60
|
block_size = 0
|
61
|
+
# on new versions of OSX, -i is default, on old versions it's not, so
|
62
|
+
# specifying it gets consistent output
|
26
63
|
so = shell_out("df -i")
|
27
|
-
so.stdout.
|
64
|
+
so.stdout.each_line do |line|
|
28
65
|
case line
|
29
66
|
when /^Filesystem\s+(\d+)-/
|
30
67
|
block_size = $1.to_i
|
31
68
|
next
|
32
69
|
when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(.+)$/
|
33
|
-
|
34
|
-
fs[
|
35
|
-
fs[
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
fs[
|
40
|
-
fs[
|
41
|
-
fs[
|
42
|
-
fs[
|
43
|
-
fs[
|
44
|
-
fs[
|
45
|
-
fs[
|
46
|
-
fs[filesystem][:mount] = $9
|
70
|
+
key = "#{$1},#{$9}"
|
71
|
+
fs[key] = Mash.new
|
72
|
+
fs[key][:block_size] = block_size
|
73
|
+
fs[key][:device] = $1
|
74
|
+
fs[key][:kb_size] = ($2.to_i / (1024 / block_size)).to_s
|
75
|
+
fs[key][:kb_used] = ($3.to_i / (1024 / block_size)).to_s
|
76
|
+
fs[key][:kb_available] = ($4.to_i / (1024 / block_size)).to_s
|
77
|
+
fs[key][:percent_used] = $5
|
78
|
+
fs[key][:inodes_used] = $6
|
79
|
+
fs[key][:inodes_available] = $7
|
80
|
+
fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s
|
81
|
+
fs[key][:inodes_percent_used] = $8
|
82
|
+
fs[key][:mount] = $9
|
47
83
|
end
|
48
84
|
end
|
49
85
|
|
50
86
|
so = shell_out("mount")
|
51
87
|
so.stdout.lines do |line|
|
52
88
|
if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
|
53
|
-
|
54
|
-
fs[
|
55
|
-
fs[
|
56
|
-
fs[
|
57
|
-
fs[
|
89
|
+
key = "#{$1},#{$2}"
|
90
|
+
fs[key] = Mash.new unless fs.has_key?(key)
|
91
|
+
fs[key][:mount] = $2
|
92
|
+
fs[key][:fs_type] = $3
|
93
|
+
fs[key][:mount_options] = $4.split(/,\s*/)
|
58
94
|
end
|
59
95
|
end
|
60
96
|
|
61
|
-
|
97
|
+
by_pair = fs
|
98
|
+
by_device = generate_device_view(fs)
|
99
|
+
by_mountpoint = generate_mountpoint_view(fs)
|
100
|
+
|
101
|
+
fs_data = Mash.new
|
102
|
+
fs_data["by_device"] = by_device
|
103
|
+
fs_data["by_mountpoint"] = by_mountpoint
|
104
|
+
fs_data["by_pair"] = by_pair
|
105
|
+
|
106
|
+
filesystem fs_data
|
107
|
+
filesystem2 fs_data
|
62
108
|
end
|
63
109
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
#
|
2
|
+
# Author:: Dylan Page (<dpage@digitalocean.com>)
|
2
3
|
# Author:: Stafford Brunk (<stafford.brunk@gmail.com>)
|
3
4
|
# License:: Apache License, Version 2.0
|
4
5
|
#
|
@@ -14,65 +15,46 @@
|
|
14
15
|
# See the License for the specific language governing permissions and
|
15
16
|
# limitations under the License.
|
16
17
|
|
17
|
-
require "ohai/
|
18
|
+
require "ohai/mixin/do_metadata"
|
19
|
+
require "ohai/mixin/http_helper"
|
18
20
|
|
19
21
|
Ohai.plugin(:DigitalOcean) do
|
20
|
-
include Ohai::
|
21
|
-
|
22
|
-
DIGITALOCEAN_FILE = "/etc/digitalocean" unless defined?(DIGITALOCEAN_FILE)
|
22
|
+
include Ohai::Mixin::DOMetadata
|
23
|
+
include Ohai::Mixin::HttpHelper
|
23
24
|
|
24
25
|
provides "digital_ocean"
|
25
|
-
depends "network/interfaces"
|
26
26
|
|
27
|
-
|
28
|
-
addresses = Mash.new({ "v4" => [], "v6" => [] })
|
29
|
-
network[:interfaces].each_value do |iface|
|
30
|
-
iface[:addresses].each do |address, details|
|
31
|
-
next if details[:family] == "lladdr" || loopback?(address)
|
27
|
+
depends "dmi"
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
# look for digitalocean string in dmi bios data
|
30
|
+
def has_do_dmi?
|
31
|
+
begin
|
32
|
+
# detect a vendor of "DigitalOcean"
|
33
|
+
if dmi[:bios][:all_records][0][:Vendor] == "DigitalOcean"
|
34
|
+
Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == true")
|
35
|
+
return true
|
37
36
|
end
|
37
|
+
rescue NoMethodError
|
38
|
+
# dmi[:bios][:all_records][0][:Vendor] may not exist
|
38
39
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
def build_address_hash(ip, details)
|
43
|
-
address_hash = Mash.new({
|
44
|
-
"ip_address" => ip.address,
|
45
|
-
"type" => private_address?(ip.address) ? "private" : "public",
|
46
|
-
})
|
47
|
-
|
48
|
-
if ip.ipv4?
|
49
|
-
address_hash["netmask"] = details[:netmask]
|
50
|
-
elsif ip.ipv6?
|
51
|
-
address_hash["cidr"] = ip.prefix
|
52
|
-
end
|
53
|
-
address_hash
|
54
|
-
end
|
55
|
-
|
56
|
-
def digital_ocean_address_type(ip)
|
57
|
-
ip.ipv4? ? "v4" : "v6"
|
40
|
+
Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == false")
|
41
|
+
return false
|
58
42
|
end
|
59
43
|
|
60
44
|
def looks_like_digital_ocean?
|
61
|
-
hint?("digital_ocean")
|
45
|
+
return true if hint?("digital_ocean")
|
46
|
+
return true if has_do_dmi? && can_socket_connect?(Ohai::Mixin::DOMetadata::DO_METADATA_ADDR, 80)
|
47
|
+
return false
|
62
48
|
end
|
63
49
|
|
64
50
|
collect_data do
|
65
51
|
if looks_like_digital_ocean?
|
66
52
|
Ohai::Log.debug("Plugin Digitalocean: looks_like_digital_ocean? == true")
|
67
53
|
digital_ocean Mash.new
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# The networks sub-hash is structured similarly to how
|
73
|
-
# Digital Ocean's v2 API structures things:
|
74
|
-
# https://developers.digitalocean.com/#droplets
|
75
|
-
digital_ocean[:networks] = extract_droplet_ip_addresses
|
54
|
+
fetch_metadata.each do |k, v|
|
55
|
+
next if k == "vendor_data" # this may have sensitive data we shouldn't store
|
56
|
+
digital_ocean[k] = v
|
57
|
+
end
|
76
58
|
else
|
77
59
|
Ohai::Log.debug("Plugin Digitalocean: No hints present for and doesn't look like digitalocean")
|
78
60
|
false
|
data/lib/ohai/plugins/dmi.rb
CHANGED
@@ -44,86 +44,90 @@ Ohai.plugin(:DMI) do
|
|
44
44
|
dmi_record = nil
|
45
45
|
field = nil
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
47
|
+
begin
|
48
|
+
so = shell_out("dmidecode")
|
49
|
+
# ==== EXAMPLE RECORD: ====
|
50
|
+
#Handle 0x0000, DMI type 0, 24 bytes
|
51
|
+
#BIOS Information
|
52
|
+
# Vendor: American Megatrends Inc.
|
53
|
+
# Version: 080012
|
54
|
+
# ... similar lines trimmed
|
55
|
+
# Characteristics:
|
56
|
+
# ISA is supported
|
57
|
+
# PCI is supported
|
58
|
+
# ... similar lines trimmed
|
59
|
+
so.stdout.lines do |line|
|
60
|
+
next if blank_line.match(line)
|
61
|
+
line = line.encode(line.encoding, :universal_newline => true)
|
62
|
+
|
63
|
+
if dmidecode_version = dmidecode_version_line.match(line)
|
64
|
+
dmi[:dmidecode_version] = dmidecode_version[1]
|
65
|
+
|
66
|
+
elsif smbios_version = smbios_version_line.match(line)
|
67
|
+
dmi[:smbios_version] = smbios_version[1]
|
68
|
+
|
69
|
+
elsif structures = structures_line.match(line)
|
70
|
+
dmi[:structures] = Mash.new
|
71
|
+
dmi[:structures][:count] = structures[1]
|
72
|
+
dmi[:structures][:size] = structures[2]
|
73
|
+
|
74
|
+
elsif table_location = table_location_line.match(line)
|
75
|
+
dmi[:table_location] = table_location[1]
|
76
|
+
|
77
|
+
elsif handle = handle_line.match(line)
|
78
|
+
# Don't overcapture for now (OHAI-260)
|
79
|
+
unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i)
|
80
|
+
dmi_record = nil
|
81
|
+
next
|
82
|
+
end
|
83
|
+
|
84
|
+
dmi_record = { :type => Ohai::Common::DMI.id_lookup(handle[2]) }
|
85
|
+
|
86
|
+
dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
|
87
|
+
dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records)
|
88
|
+
dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length
|
89
|
+
dmi[dmi_record[:type]][:all_records].push(Mash.new)
|
90
|
+
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = handle[1]
|
91
|
+
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2]
|
92
|
+
field = nil
|
93
|
+
|
94
|
+
elsif type = type_line.match(line)
|
95
|
+
if dmi_record .nil?
|
96
|
+
Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
|
97
|
+
next
|
98
|
+
end
|
99
|
+
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1]
|
100
|
+
|
101
|
+
elsif data = data_line.match(line)
|
102
|
+
if dmi_record .nil?
|
103
|
+
Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}")
|
104
|
+
next
|
105
|
+
end
|
106
|
+
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
|
107
|
+
field = data[1]
|
108
|
+
|
109
|
+
elsif extended_data = extended_data_line.match(line)
|
110
|
+
if dmi_record .nil?
|
111
|
+
Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
|
112
|
+
next
|
113
|
+
end
|
114
|
+
if field .nil?
|
115
|
+
Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
|
116
|
+
next
|
117
|
+
end
|
118
|
+
# overwrite "raw" value with a new Mash
|
119
|
+
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == "Mash"
|
120
|
+
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil
|
121
|
+
|
122
|
+
else
|
123
|
+
Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
|
107
124
|
|
108
|
-
elsif extended_data = extended_data_line.match(line)
|
109
|
-
if dmi_record.nil?
|
110
|
-
Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}")
|
111
|
-
next
|
112
|
-
end
|
113
|
-
if field.nil?
|
114
|
-
Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}")
|
115
|
-
next
|
116
125
|
end
|
117
|
-
# overwrite "raw" value with a new Mash
|
118
|
-
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == "Mash"
|
119
|
-
dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil
|
120
|
-
|
121
|
-
else
|
122
|
-
Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}")
|
123
|
-
|
124
126
|
end
|
125
|
-
end
|
126
127
|
|
127
|
-
|
128
|
+
Ohai::Common::DMI.convenience_keys(dmi)
|
129
|
+
rescue Ohai::Exceptions::Exec
|
130
|
+
Ohai::Log.debug('Plugin DMI: Could not shell_out "dmidecode". Skipping data')
|
131
|
+
end
|
128
132
|
end
|
129
133
|
end
|
data/lib/ohai/plugins/ec2.rb
CHANGED
@@ -21,93 +21,66 @@
|
|
21
21
|
# How we detect EC2 from easiest to hardest & least reliable
|
22
22
|
# 1. Ohai ec2 hint exists. This always works
|
23
23
|
# 2. Xen hypervisor UUID starts with 'ec2'. This catches Linux HVM & paravirt instances
|
24
|
-
# 3. DMI
|
25
|
-
# 3. DMI bios vendor data mentions amazon. This catches HVM instances in a VPC on the non-Xen based hypervisor
|
24
|
+
# 3. DMI data mentions amazon. This catches HVM instances in a VPC
|
26
25
|
# 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
require "ohai/mixin/ec2_metadata"
|
28
|
+
require "ohai/mixin/http_helper"
|
29
|
+
require "base64"
|
31
30
|
|
31
|
+
Ohai.plugin(:EC2) do
|
32
32
|
include Ohai::Mixin::Ec2Metadata
|
33
|
+
include Ohai::Mixin::HttpHelper
|
33
34
|
|
34
35
|
provides "ec2"
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
# this gets us detection of new Xen-less HVM instances that are within a VPC
|
39
|
-
# @return [Boolean] do we have Amazon DMI data?
|
40
|
-
def has_ec2_amazon_dmi?
|
41
|
-
# detect a version of '4.2.amazon'
|
42
|
-
if file_val_if_exists("/sys/class/dmi/id/bios_vendor") =~ /Amazon/
|
43
|
-
Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == true")
|
44
|
-
true
|
45
|
-
else
|
46
|
-
Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == false")
|
47
|
-
false
|
48
|
-
end
|
49
|
-
end
|
37
|
+
depends "dmi"
|
38
|
+
depends "kernel"
|
50
39
|
|
51
|
-
# look for amazon string in dmi bios
|
52
|
-
# this works even if the system lacks dmidecode use by the Dmi plugin
|
40
|
+
# look for amazon string in dmi bios data
|
53
41
|
# this gets us detection of HVM instances that are within a VPC
|
54
|
-
|
55
|
-
def has_ec2_xen_dmi?
|
42
|
+
def has_ec2_dmi?
|
56
43
|
# detect a version of '4.2.amazon'
|
57
|
-
if
|
58
|
-
Ohai::Log.debug("Plugin EC2:
|
59
|
-
true
|
44
|
+
if get_attribute(:dmi, :bios, :all_records, 0, :Version) =~ /amazon/
|
45
|
+
Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == true")
|
46
|
+
return true
|
60
47
|
else
|
61
|
-
Ohai::Log.debug("Plugin EC2:
|
62
|
-
false
|
48
|
+
Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == false")
|
49
|
+
return false
|
63
50
|
end
|
64
51
|
end
|
65
52
|
|
66
|
-
# looks for a xen UUID that starts with ec2
|
67
|
-
#
|
53
|
+
# looks for a xen UUID that starts with ec2
|
54
|
+
# this gets us detection of Linux HVM and Paravirt hosts
|
68
55
|
def has_ec2_xen_uuid?
|
69
|
-
if
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == false")
|
74
|
-
false
|
75
|
-
end
|
76
|
-
|
77
|
-
# looks at the identifying number WMI value to see if it starts with ec2.
|
78
|
-
# this is actually the same value we're looking at in has_ec2_xen_uuid? on
|
79
|
-
# linux hosts
|
80
|
-
# @return [Boolean] do we have a Xen Identifying Number or not?
|
81
|
-
def has_ec2_identifying_number?
|
82
|
-
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
83
|
-
require "wmi-lite/wmi"
|
84
|
-
wmi = WmiLite::Wmi.new
|
85
|
-
if wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"] =~ /^ec2/
|
86
|
-
Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == true")
|
56
|
+
if ::File.exist?("/sys/hypervisor/uuid")
|
57
|
+
if ::File.read("/sys/hypervisor/uuid") =~ /^ec2/
|
58
|
+
Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true")
|
87
59
|
return true
|
88
60
|
end
|
89
|
-
else
|
90
|
-
Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == false")
|
91
|
-
false
|
92
61
|
end
|
62
|
+
Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == false")
|
63
|
+
return false
|
93
64
|
end
|
94
65
|
|
95
|
-
#
|
96
|
-
#
|
97
|
-
|
98
|
-
|
99
|
-
if
|
100
|
-
::
|
66
|
+
# looks for the Amazon.com Organization in Windows Kernel data
|
67
|
+
# this gets us detection of Windows systems
|
68
|
+
def has_amazon_org?
|
69
|
+
# detect an Organization of 'Amazon.com'
|
70
|
+
if get_attribute(:kernel, :os_info, :organization) =~ /Amazon/
|
71
|
+
Ohai::Log.debug("Plugin EC2: has_amazon_org? == true")
|
72
|
+
return true
|
73
|
+
else
|
74
|
+
Ohai::Log.debug("Plugin EC2: has_amazon_org? == false")
|
75
|
+
return false
|
101
76
|
end
|
102
77
|
end
|
103
78
|
|
104
|
-
# a single check that combines all the various detection methods for EC2
|
105
|
-
# @return [Boolean] Does the system appear to be on EC2
|
106
79
|
def looks_like_ec2?
|
107
80
|
return true if hint?("ec2")
|
108
81
|
|
109
82
|
# Even if it looks like EC2 try to connect first
|
110
|
-
if has_ec2_xen_uuid? ||
|
83
|
+
if has_ec2_xen_uuid? || has_ec2_dmi? || has_amazon_org?
|
111
84
|
return true if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
112
85
|
end
|
113
86
|
end
|