ohai 6.24.2 → 7.0.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +5 -12
- data/lib/ohai/common/dmi.rb +126 -0
- data/lib/ohai/config.rb +9 -9
- data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
- data/lib/ohai/dsl/plugin.rb +186 -0
- data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
- data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
- data/lib/ohai/exception.rb +11 -2
- data/lib/ohai/hints.rb +48 -0
- data/lib/ohai/loader.rb +205 -0
- data/lib/ohai/mixin/command.rb +14 -18
- data/lib/ohai/mixin/constant_helper.rb +53 -0
- data/lib/ohai/mixin/gce_metadata.rb +0 -2
- data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
- data/lib/ohai/mixin/os.rb +59 -0
- data/lib/ohai/mixin/seconds_to_human.rb +48 -0
- data/lib/ohai/plugins/aix/cpu.rb +26 -22
- data/lib/ohai/plugins/aix/filesystem.rb +47 -48
- data/lib/ohai/plugins/aix/kernel.rb +11 -7
- data/lib/ohai/plugins/aix/memory.rb +8 -4
- data/lib/ohai/plugins/aix/network.rb +73 -82
- data/lib/ohai/plugins/aix/platform.rb +9 -6
- data/lib/ohai/plugins/aix/uptime.rb +14 -12
- data/lib/ohai/plugins/azure.rb +33 -11
- data/lib/ohai/plugins/c.rb +103 -78
- data/lib/ohai/plugins/chef.rb +20 -8
- data/lib/ohai/plugins/cloud.rb +234 -230
- data/lib/ohai/plugins/command.rb +6 -2
- data/lib/ohai/plugins/darwin/cpu.rb +10 -4
- data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
- data/lib/ohai/plugins/darwin/network.rb +157 -154
- data/lib/ohai/plugins/darwin/platform.rb +18 -16
- data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
- data/lib/ohai/plugins/dmi.rb +102 -102
- data/lib/ohai/plugins/ec2.rb +30 -28
- data/lib/ohai/plugins/erlang.rb +19 -16
- data/lib/ohai/plugins/eucalyptus.rb +37 -36
- data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
- data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/freebsd/memory.rb +35 -25
- data/lib/ohai/plugins/freebsd/network.rb +94 -89
- data/lib/ohai/plugins/freebsd/platform.rb +10 -4
- data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
- data/lib/ohai/plugins/gce.rb +30 -36
- data/lib/ohai/plugins/groovy.rb +14 -11
- data/lib/ohai/plugins/hostname.rb +132 -10
- data/lib/ohai/plugins/ip_scopes.rb +31 -16
- data/lib/ohai/plugins/java.rb +45 -21
- data/lib/ohai/plugins/kernel.rb +186 -19
- data/lib/ohai/plugins/keys.rb +6 -2
- data/lib/ohai/plugins/languages.rb +6 -2
- data/lib/ohai/plugins/linode.rb +38 -30
- data/lib/ohai/plugins/linux/block_device.rb +19 -15
- data/lib/ohai/plugins/linux/cpu.rb +42 -38
- data/lib/ohai/plugins/linux/filesystem.rb +70 -130
- data/lib/ohai/plugins/linux/lsb.rb +35 -35
- data/lib/ohai/plugins/linux/memory.rb +65 -61
- data/lib/ohai/plugins/linux/network.rb +343 -362
- data/lib/ohai/plugins/linux/platform.rb +90 -88
- data/lib/ohai/plugins/linux/virtualization.rb +95 -90
- data/lib/ohai/plugins/lua.rb +14 -10
- data/lib/ohai/plugins/mono.rb +17 -13
- data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
- data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/netbsd/memory.rb +59 -59
- data/lib/ohai/plugins/netbsd/network.rb +92 -88
- data/lib/ohai/plugins/netbsd/platform.rb +10 -3
- data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
- data/lib/ohai/plugins/network.rb +131 -130
- data/lib/ohai/plugins/network_listeners.rb +26 -22
- data/lib/ohai/plugins/nodejs.rb +14 -10
- data/lib/ohai/plugins/ohai.rb +11 -6
- data/lib/ohai/plugins/ohai_time.rb +6 -2
- data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
- data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/openbsd/memory.rb +59 -59
- data/lib/ohai/plugins/openbsd/network.rb +92 -88
- data/lib/ohai/plugins/openbsd/platform.rb +10 -4
- data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
- data/lib/ohai/plugins/openstack.rb +23 -21
- data/lib/ohai/plugins/os.rb +8 -32
- data/lib/ohai/plugins/passwd.rb +27 -22
- data/lib/ohai/plugins/perl.rb +21 -16
- data/lib/ohai/plugins/php.rb +15 -12
- data/lib/ohai/plugins/platform.rb +9 -9
- data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
- data/lib/ohai/plugins/python.rb +16 -12
- data/lib/ohai/plugins/rackspace.rb +82 -77
- data/lib/ohai/plugins/root_group.rb +13 -9
- data/lib/ohai/plugins/ruby.rb +50 -48
- data/lib/ohai/plugins/sigar/cpu.rb +21 -17
- data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
- data/lib/ohai/plugins/sigar/memory.rb +17 -14
- data/lib/ohai/plugins/sigar/network.rb +133 -67
- data/lib/ohai/plugins/sigar/network_route.rb +33 -28
- data/lib/ohai/plugins/sigar/platform.rb +10 -6
- data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
- data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
- data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
- data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
- data/lib/ohai/plugins/solaris2/network.rb +91 -86
- data/lib/ohai/plugins/solaris2/platform.rb +40 -36
- data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
- data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
- data/lib/ohai/plugins/ssh_host_key.rb +49 -45
- data/lib/ohai/plugins/uptime.rb +87 -25
- data/lib/ohai/plugins/virtualization.rb +59 -55
- data/lib/ohai/plugins/windows/cpu.rb +44 -40
- data/lib/ohai/plugins/windows/filesystem.rb +28 -22
- data/lib/ohai/plugins/windows/network.rb +88 -79
- data/lib/ohai/plugins/windows/platform.rb +10 -3
- data/lib/ohai/provides_map.rb +184 -0
- data/lib/ohai/runner.rb +109 -0
- data/lib/ohai/system.rb +103 -184
- data/lib/ohai/version.rb +4 -3
- data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
- data/spec/data/plugins/___lib___libc.so.6.output +135 -0
- data/spec/data/plugins/cc.output +135 -0
- data/spec/data/plugins/cl.output +135 -0
- data/spec/data/plugins/devenv.com.output +135 -0
- data/spec/data/plugins/env.output +71 -0
- data/spec/data/plugins/erl.output +144 -0
- data/spec/data/plugins/gcc.output +135 -0
- data/spec/data/plugins/groovy.output +159 -0
- data/spec/data/plugins/java.output +143 -0
- data/spec/data/plugins/lua.output +143 -0
- data/spec/data/plugins/messages.rb +8 -0
- data/spec/data/plugins/node.output +143 -0
- data/spec/data/plugins/perl.output +143 -0
- data/spec/data/plugins/php.output +143 -0
- data/spec/data/plugins/python.output +143 -0
- data/spec/data/plugins/uname.output +71 -0
- data/spec/data/plugins/v6message.rb +2 -0
- data/spec/data/plugins/v7message.rb +7 -0
- data/spec/data/plugins/what.output +135 -0
- data/spec/data/plugins/xlc.output +135 -0
- data/spec/spec_helper.rb +52 -18
- data/spec/support/integration_helper.rb +44 -0
- data/spec/unit/dsl/plugin_spec.rb +298 -0
- data/spec/unit/hints_spec.rb +65 -0
- data/spec/unit/loader_spec.rb +226 -0
- data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
- data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
- data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
- data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
- data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
- data/spec/unit/plugins/aix/network_spec.rb +66 -45
- data/spec/unit/plugins/aix/platform_spec.rb +11 -10
- data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
- data/spec/unit/plugins/azure_spec.rb +20 -21
- data/spec/unit/plugins/c_spec.rb +88 -87
- data/spec/unit/plugins/chef_spec.rb +5 -6
- data/spec/unit/plugins/cloud_spec.rb +81 -82
- data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
- data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
- data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
- data/spec/unit/plugins/darwin/network_spec.rb +375 -378
- data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
- data/spec/unit/plugins/dmi_spec.rb +7 -12
- data/spec/unit/plugins/ec2_spec.rb +70 -59
- data/spec/unit/plugins/erlang_spec.rb +18 -20
- data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
- data/spec/unit/plugins/fail_spec.rb +276 -23
- data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
- data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
- data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
- data/spec/unit/plugins/gce_spec.rb +19 -25
- data/spec/unit/plugins/groovy_spec.rb +10 -16
- data/spec/unit/plugins/hostname_spec.rb +45 -20
- data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
- data/spec/unit/plugins/java_spec.rb +145 -99
- data/spec/unit/plugins/kernel_spec.rb +51 -15
- data/spec/unit/plugins/linode_spec.rb +31 -29
- data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
- data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
- data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
- data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
- data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
- data/spec/unit/plugins/linux/network_spec.rb +196 -238
- data/spec/unit/plugins/linux/platform_spec.rb +186 -205
- data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
- data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
- data/spec/unit/plugins/lua_spec.rb +12 -15
- data/spec/unit/plugins/mono_spec.rb +10 -15
- data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
- data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
- data/spec/unit/plugins/network_spec.rb +358 -235
- data/spec/unit/plugins/nodejs_spec.rb +13 -15
- data/spec/unit/plugins/ohai_spec.rb +3 -4
- data/spec/unit/plugins/ohai_time_spec.rb +8 -9
- data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
- data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
- data/spec/unit/plugins/openstack_spec.rb +214 -0
- data/spec/unit/plugins/os_spec.rb +13 -16
- data/spec/unit/plugins/passwd_spec.rb +12 -13
- data/spec/unit/plugins/perl_spec.rb +20 -44
- data/spec/unit/plugins/php_spec.rb +20 -15
- data/spec/unit/plugins/platform_spec.rb +24 -29
- data/spec/unit/plugins/python_spec.rb +13 -17
- data/spec/unit/plugins/rackspace_spec.rb +90 -57
- data/spec/unit/plugins/root_group_spec.rb +17 -19
- data/spec/unit/plugins/ruby_spec.rb +15 -16
- data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
- data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
- data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
- data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
- data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
- data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
- data/spec/unit/provides_map_spec.rb +208 -0
- data/spec/unit/runner_spec.rb +488 -0
- data/spec/unit/system_spec.rb +639 -104
- metadata +151 -87
- checksums.yaml +0 -7
- data/lib/ohai/mixin/from_file.rb +0 -36
- data/lib/ohai/plugins/aix/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/kernel.rb +0 -37
- data/lib/ohai/plugins/darwin/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/uptime.rb +0 -32
- data/lib/ohai/plugins/dmi_common.rb +0 -121
- data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
- data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
- data/lib/ohai/plugins/freebsd/ps.rb +0 -24
- data/lib/ohai/plugins/hpux/cpu.rb +0 -19
- data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
- data/lib/ohai/plugins/hpux/hostname.rb +0 -19
- data/lib/ohai/plugins/hpux/memory.rb +0 -19
- data/lib/ohai/plugins/hpux/network.rb +0 -19
- data/lib/ohai/plugins/hpux/platform.rb +0 -19
- data/lib/ohai/plugins/hpux/ps.rb +0 -23
- data/lib/ohai/plugins/hpux/uptime.rb +0 -19
- data/lib/ohai/plugins/linux/hostname.rb +0 -40
- data/lib/ohai/plugins/linux/ps.rb +0 -23
- data/lib/ohai/plugins/linux/uptime.rb +0 -28
- data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/netbsd/ps.rb +0 -24
- data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
- data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/openbsd/ps.rb +0 -24
- data/lib/ohai/plugins/sigar/hostname.rb +0 -28
- data/lib/ohai/plugins/sigar/uptime.rb +0 -27
- data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
- data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
- data/lib/ohai/plugins/solaris2/ps.rb +0 -23
- data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
- data/lib/ohai/plugins/windows/hostname.rb +0 -33
- data/lib/ohai/plugins/windows/kernel.rb +0 -58
- data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
- data/lib/ohai/plugins/windows/uptime.rb +0 -23
- data/spec/unit/mixin/from_file_spec.rb +0 -53
data/lib/ohai/plugins/gce.rb
CHANGED
@@ -14,45 +14,39 @@
|
|
14
14
|
# See the License for the specific language governing permissions and
|
15
15
|
# limitations under the License.
|
16
16
|
|
17
|
-
provides "gce"
|
18
|
-
|
19
17
|
require 'ohai/mixin/gce_metadata'
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
# === Return
|
25
|
-
# true:: If gce dmi matches
|
26
|
-
# false:: Otherwise
|
27
|
-
GOOGLE_SYSFS_DMI = '/sys/firmware/dmi/entries/1-0/raw'
|
28
|
-
def has_google_dmi?
|
29
|
-
::File.read(GOOGLE_SYSFS_DMI).include?('Google')
|
30
|
-
end
|
19
|
+
Ohai.plugin(:GCE) do
|
20
|
+
include Ohai::Mixin::GCEMetadata
|
31
21
|
|
32
|
-
|
33
|
-
#
|
34
|
-
# === Return
|
35
|
-
# true:: If gce metadata server found
|
36
|
-
# false:: Otherwise
|
37
|
-
def has_gce_metadata?
|
38
|
-
Ohai::Mixin::GCEMetadata.can_metadata_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR,80)
|
39
|
-
end
|
22
|
+
provides "gce"
|
40
23
|
|
41
|
-
#
|
42
|
-
#
|
43
|
-
# === Return
|
44
|
-
# true:: If gce
|
45
|
-
# false:: Otherwise
|
46
|
-
def
|
47
|
-
|
48
|
-
end
|
24
|
+
# Checks for gce metadata server
|
25
|
+
#
|
26
|
+
# === Return
|
27
|
+
# true:: If gce metadata server found
|
28
|
+
# false:: Otherwise
|
29
|
+
def has_gce_metadata?
|
30
|
+
can_metadata_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR,80)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Identifies gce
|
34
|
+
#
|
35
|
+
# === Return
|
36
|
+
# true:: If gce can be identified
|
37
|
+
# false:: Otherwise
|
38
|
+
def looks_like_gce?
|
39
|
+
hint?('gce') || has_gce_metadata?
|
40
|
+
end
|
49
41
|
|
50
|
-
|
51
|
-
if looks_like_gce?
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
else
|
56
|
-
|
57
|
-
|
42
|
+
collect_data do
|
43
|
+
if looks_like_gce?
|
44
|
+
Ohai::Log.debug("looks_like_gce? == true")
|
45
|
+
gce Mash.new
|
46
|
+
fetch_metadata.each {|k, v| gce[k] = v }
|
47
|
+
else
|
48
|
+
Ohai::Log.debug("looks_like_gce? == false")
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
58
52
|
end
|
data/lib/ohai/plugins/groovy.rb
CHANGED
@@ -16,20 +16,23 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
Ohai.plugin(:Groovy) do
|
20
|
+
provides "languages/groovy"
|
20
21
|
|
21
|
-
|
22
|
+
depends "languages"
|
22
23
|
|
23
|
-
|
24
|
+
collect_data do
|
25
|
+
output = nil
|
24
26
|
|
25
|
-
groovy = Mash.new
|
27
|
+
groovy = Mash.new
|
26
28
|
|
27
|
-
|
28
|
-
if
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
so = shell_out("groovy -v")
|
30
|
+
if so.exitstatus == 0
|
31
|
+
output = so.stdout.split
|
32
|
+
if output.length >= 2
|
33
|
+
groovy[:version] = output[2]
|
34
|
+
end
|
35
|
+
languages[:groovy] = groovy if groovy[:version]
|
36
|
+
end
|
32
37
|
end
|
33
|
-
languages[:groovy] = groovy if groovy[:version]
|
34
38
|
end
|
35
|
-
|
@@ -1,14 +1,22 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
#
|
3
|
+
# Author:: Benjamin Black (<nostromo@gmail.com>)
|
4
|
+
# Author:: Bryan McLellan (<btm@loftninjas.org>)
|
5
|
+
# Author:: Daniel DeLeo (<dan@kallistec.com>)
|
6
|
+
# Author:: Doug MacEachern (<dougm@vmware.com>)
|
7
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
8
|
+
# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc.
|
9
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
10
|
+
# Copyright:: Copyright (c) 2009 Daniel DeLeo
|
11
|
+
# Copyright:: Copyright (c) 2010 VMware, Inc.
|
4
12
|
# License:: Apache License, Version 2.0
|
5
13
|
#
|
6
14
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
15
|
# you may not use this file except in compliance with the License.
|
8
16
|
# You may obtain a copy of the License at
|
9
|
-
#
|
17
|
+
#
|
10
18
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
19
|
+
#
|
12
20
|
# Unless required by applicable law or agreed to in writing, software
|
13
21
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
22
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
@@ -16,13 +24,127 @@
|
|
16
24
|
# limitations under the License.
|
17
25
|
#
|
18
26
|
|
19
|
-
|
27
|
+
require 'socket'
|
28
|
+
require 'ipaddr'
|
29
|
+
|
30
|
+
Ohai.plugin(:Hostname) do
|
31
|
+
provides "domain", "hostname", "fqdn", "machinename"
|
32
|
+
|
33
|
+
# hostname : short hostname
|
34
|
+
# machinename : output of hostname command (might be short on solaris)
|
35
|
+
# fqdn : result of canonicalizing hostname using DNS or /etc/hosts
|
36
|
+
# domain : domain part of FQDN
|
37
|
+
#
|
38
|
+
# hostname and machinename should always exist
|
39
|
+
# fqdn and domain may be broken if DNS is broken on the host
|
40
|
+
|
41
|
+
def from_cmd(cmd)
|
42
|
+
so = shell_out(cmd)
|
43
|
+
so.stdout.split($/)[0]
|
44
|
+
end
|
45
|
+
|
46
|
+
# forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
|
47
|
+
# this is ipv6-safe, works on ruby 1.8.7+
|
48
|
+
def resolve_fqdn
|
49
|
+
begin
|
50
|
+
hostname = from_cmd("hostname")
|
51
|
+
addrinfo = Socket.getaddrinfo(hostname, nil).first
|
52
|
+
iaddr = IPAddr.new(addrinfo[3])
|
53
|
+
Socket.gethostbyaddr(iaddr.hton)[0]
|
54
|
+
rescue
|
55
|
+
nil
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def collect_domain
|
60
|
+
# Domain is everything after the first dot
|
61
|
+
if fqdn
|
62
|
+
fqdn =~ /.+?\.(.*)/
|
63
|
+
domain $1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def collect_hostname
|
68
|
+
# Hostname is everything before the first dot
|
69
|
+
if machinename
|
70
|
+
machinename =~ /(.+?)\./
|
71
|
+
hostname $1
|
72
|
+
elsif fqdn
|
73
|
+
fqdn =~ /(.+?)\./
|
74
|
+
hostname $1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_fqdn_from_sigar
|
79
|
+
require 'sigar'
|
80
|
+
sigar = Sigar.new
|
81
|
+
sigar.fqdn
|
82
|
+
end
|
83
|
+
|
84
|
+
def sigar_is_available?
|
85
|
+
begin
|
86
|
+
require 'sigar'
|
87
|
+
true
|
88
|
+
rescue LoadError
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
collect_data(:aix, :hpux, :default) do
|
94
|
+
machinename from_cmd("hostname")
|
95
|
+
fqdn sigar_is_available? ? get_fqdn_from_sigar : resolve_fqdn
|
96
|
+
collect_hostname
|
97
|
+
collect_domain
|
98
|
+
end
|
99
|
+
|
100
|
+
collect_data(:darwin, :netbsd, :openbsd) do
|
101
|
+
hostname from_cmd("hostname -s")
|
102
|
+
fqdn resolve_fqdn
|
103
|
+
machinename from_cmd("hostname")
|
104
|
+
collect_domain
|
105
|
+
end
|
106
|
+
|
107
|
+
collect_data(:freebsd) do
|
108
|
+
hostname from_cmd("hostname -s")
|
109
|
+
machinename from_cmd("hostname")
|
110
|
+
fqdn from_cmd("hostname -f")
|
111
|
+
collect_domain
|
112
|
+
end
|
113
|
+
|
114
|
+
collect_data(:linux) do
|
115
|
+
hostname from_cmd("hostname -s")
|
116
|
+
machinename from_cmd("hostname")
|
117
|
+
begin
|
118
|
+
fqdn from_cmd("hostname --fqdn")
|
119
|
+
rescue
|
120
|
+
Ohai::Log.debug("hostname -f returned an error, probably no domain is set")
|
121
|
+
end
|
122
|
+
domain collect_domain
|
123
|
+
end
|
124
|
+
|
125
|
+
collect_data(:solaris2) do
|
126
|
+
machinename from_cmd("hostname")
|
127
|
+
hostname from_cmd("hostname")
|
128
|
+
fqdn resolve_fqdn
|
129
|
+
domain collect_domain
|
130
|
+
end
|
131
|
+
|
132
|
+
collect_data(:windows) do
|
133
|
+
require 'ruby-wmi'
|
134
|
+
require 'socket'
|
20
135
|
|
21
|
-
|
22
|
-
|
136
|
+
host = WMI::Win32_ComputerSystem.find(:first)
|
137
|
+
hostname "#{host.Name}"
|
138
|
+
machinename "#{host.Name}"
|
23
139
|
|
24
|
-
|
25
|
-
if
|
26
|
-
|
27
|
-
|
140
|
+
info = Socket.gethostbyname(Socket.gethostname)
|
141
|
+
if info.first =~ /.+?\.(.*)/
|
142
|
+
fqdn info.first
|
143
|
+
else
|
144
|
+
#host is not in dns. optionally use:
|
145
|
+
#C:\WINDOWS\system32\drivers\etc\hosts
|
146
|
+
fqdn Socket.gethostbyaddr(info.last).first
|
147
|
+
end
|
148
|
+
domain collect_domain
|
149
|
+
end
|
28
150
|
end
|
@@ -15,28 +15,43 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
|
18
|
-
|
19
|
-
require 'ipaddr_extensions'
|
20
|
-
|
18
|
+
Ohai.plugin(:IpScopes) do
|
21
19
|
provides "network_ip_scope", "privateaddress"
|
22
20
|
|
23
|
-
|
24
|
-
|
21
|
+
depends "network/interfaces"
|
22
|
+
|
23
|
+
collect_data do
|
24
|
+
begin
|
25
|
+
require 'ipaddr_extensions'
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
network['interfaces'].keys.sort.each do |ifName|
|
28
|
+
next if network['interfaces'][ifName]['addresses'].nil?
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
interface = network['interfaces'][ifName]
|
31
|
+
interface['addresses'].each do |address,attrs|
|
32
|
+
begin
|
33
|
+
attrs.merge! 'ip_scope' => address.to_ip.scope
|
34
|
+
|
35
|
+
if private_addr?(address) && !tunnel_iface?(interface)
|
36
|
+
privateaddress(address)
|
37
|
+
end
|
38
|
+
rescue ArgumentError
|
39
|
+
# Just silently fail if we can't create an IP from the string.
|
40
|
+
end
|
41
|
+
end
|
35
42
|
end
|
43
|
+
|
44
|
+
rescue LoadError => e
|
45
|
+
# our favourite gem is not installed. Boohoo.
|
46
|
+
Ohai::Log.debug("ip_scopes: cannot load gem, plugin disabled: #{e}")
|
36
47
|
end
|
37
48
|
end
|
38
49
|
|
39
|
-
|
40
|
-
|
41
|
-
|
50
|
+
def private_addr?(address)
|
51
|
+
address.to_ip.scope =~ /PRIVATE/
|
52
|
+
end
|
53
|
+
|
54
|
+
def tunnel_iface?(interface)
|
55
|
+
interface['type'] == 'ppp'
|
56
|
+
end
|
42
57
|
end
|
data/lib/ohai/plugins/java.rb
CHANGED
@@ -15,32 +15,56 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
-
provides "languages/java"
|
19
18
|
|
20
|
-
|
19
|
+
Ohai.plugin(:Java) do
|
20
|
+
provides "languages/java"
|
21
|
+
depends "languages"
|
21
22
|
|
22
|
-
|
23
|
+
def get_java_info
|
24
|
+
java = Mash.new
|
25
|
+
so = shell_out("java -version")
|
26
|
+
if so.exitstatus == 0
|
27
|
+
so.stderr.split(/\r?\n/).each do |line|
|
28
|
+
case line
|
29
|
+
when /java version \"([0-9\.\_]+)\"/
|
30
|
+
java[:version] = $1
|
31
|
+
when /^(.+Runtime Environment.*) \((build )?(.+)\)$/
|
32
|
+
java[:runtime] = { "name" => $1, "build" => $3 }
|
33
|
+
when /^(.+ (Client|Server) VM) \(build (.+)\)$/
|
34
|
+
java[:hotspot] = { "name" => $1, "build" => $3 }
|
35
|
+
end
|
36
|
+
end
|
23
37
|
|
24
|
-
|
25
|
-
|
26
|
-
if system("/usr/libexec/java_home >/dev/null 2>&1")
|
27
|
-
status, stdout, stderr = run_command(:no_status_check => true, :command => "java -mx64m -version")
|
38
|
+
languages[:java] = java if java[:version]
|
39
|
+
end
|
28
40
|
end
|
29
|
-
else
|
30
|
-
status, stdout, stderr = run_command(:no_status_check => true, :command => "java -mx64m -version")
|
31
|
-
end
|
32
41
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
42
|
+
# On Mac OS X, the development tools include "stubs" for JVM executables that
|
43
|
+
# prompt the user to install the JVM if they desire. In our case we simply
|
44
|
+
# wish to detect if the JVM is there and do not want to trigger a popup
|
45
|
+
# window. As a workaround, we can run the java_home executable and check its
|
46
|
+
# exit status to determine if the `java` executable is the real one or the OS
|
47
|
+
# X stub. In the terminal, it looks like this:
|
48
|
+
#
|
49
|
+
# $ /usr/libexec/java_home
|
50
|
+
# Unable to find any JVMs matching version "(null)".
|
51
|
+
# No Java runtime present, try --request to install.
|
52
|
+
#
|
53
|
+
# $ echo $?
|
54
|
+
# 1
|
55
|
+
#
|
56
|
+
# This check always returns true when not on darwin because it is just a
|
57
|
+
# workaround for this particular annoyance.
|
58
|
+
def has_real_java?
|
59
|
+
return true unless on_darwin?
|
60
|
+
shell_out("/usr/libexec/java_home").status.success?
|
43
61
|
end
|
44
62
|
|
45
|
-
|
63
|
+
def on_darwin?
|
64
|
+
RUBY_PLATFORM.downcase.include?("darwin")
|
65
|
+
end
|
66
|
+
|
67
|
+
collect_data do
|
68
|
+
get_java_info if has_real_java?
|
69
|
+
end
|
46
70
|
end
|
data/lib/ohai/plugins/kernel.rb
CHANGED
@@ -1,34 +1,201 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Adam Jacob (<adam@opscode.com>)
|
3
|
-
#
|
3
|
+
# Author:: Benjamin Black (<nostromo@gmail.com>)
|
4
|
+
# Author:: Bryan McLellan (<btm@loftninjas.org>)
|
5
|
+
# Author:: Claire McQuin (<claire@opscode.com>)
|
6
|
+
# Author:: James Gartrell (<jgartrel@gmail.com>)
|
7
|
+
# Copyright:: Copyright (c) 2008, 2009, 2013 Opscode, Inc.
|
8
|
+
# Copyright:: Copyright (c) 2009 Bryan McLellan
|
4
9
|
# License:: Apache License, Version 2.0
|
5
10
|
#
|
6
11
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
12
|
# you may not use this file except in compliance with the License.
|
8
13
|
# You may obtain a copy of the License at
|
9
|
-
#
|
14
|
+
#
|
10
15
|
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
16
|
+
#
|
12
17
|
# Unless required by applicable law or agreed to in writing, software
|
13
18
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
19
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
20
|
+
# implied.
|
15
21
|
# See the License for the specific language governing permissions and
|
16
22
|
# limitations under the License.
|
17
23
|
#
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
Ohai.plugin(:Kernel) do
|
26
|
+
provides "kernel", "kernel/modules"
|
27
|
+
|
28
|
+
# common initial kernel attribute values
|
29
|
+
def init_kernel
|
30
|
+
kernel Mash.new
|
31
|
+
[["uname -s", :name], ["uname -r", :release],
|
32
|
+
["uname -v", :version], ["uname -m", :machine]].each do |cmd, property|
|
33
|
+
so = shell_out(cmd)
|
34
|
+
kernel[property] = so.stdout.split($/)[0]
|
35
|
+
end
|
36
|
+
kernel
|
37
|
+
end
|
38
|
+
|
39
|
+
# common *bsd code for collecting modules data
|
40
|
+
def bsd_modules(path)
|
41
|
+
modules = Mash.new
|
42
|
+
so = shell_out("#{Ohai.abs_path(path)}")
|
43
|
+
so.stdout.lines do |line|
|
44
|
+
# 1 7 0xc0400000 97f830 kernel
|
45
|
+
if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/
|
46
|
+
modules[$5] = { :size => $4, :refcount => $2 }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
modules
|
50
|
+
end
|
51
|
+
|
52
|
+
# windows
|
53
|
+
def machine_lookup(sys_type)
|
54
|
+
return "i386" if sys_type.eql?("X86-based PC")
|
55
|
+
return "x86_64" if sys_type.eql?("x64-based PC")
|
56
|
+
sys_type
|
57
|
+
end
|
58
|
+
|
59
|
+
# windows
|
60
|
+
def os_lookup(sys_type)
|
61
|
+
return "Unknown" if sys_type.to_s.eql?("0")
|
62
|
+
return "Other" if sys_type.to_s.eql?("1")
|
63
|
+
return "MSDOS" if sys_type.to_s.eql?("14")
|
64
|
+
return "WIN3x" if sys_type.to_s.eql?("15")
|
65
|
+
return "WIN95" if sys_type.to_s.eql?("16")
|
66
|
+
return "WIN98" if sys_type.to_s.eql?("17")
|
67
|
+
return "WINNT" if sys_type.to_s.eql?("18")
|
68
|
+
return "WINCE" if sys_type.to_s.eql?("19")
|
69
|
+
return nil
|
70
|
+
end
|
71
|
+
|
72
|
+
collect_data(:default) do
|
73
|
+
kernel init_kernel
|
74
|
+
end
|
75
|
+
|
76
|
+
collect_data(:darwin) do
|
77
|
+
kernel init_kernel
|
78
|
+
kernel[:os] = kernel[:name]
|
79
|
+
|
80
|
+
so = shell_out("sysctl -n hw.optional.x86_64")
|
81
|
+
if so.stdout.split($/)[0].to_i == 1
|
82
|
+
kernel[:machine] = 'x86_64'
|
83
|
+
end
|
84
|
+
|
85
|
+
modules = Mash.new
|
86
|
+
so = shell_out("kextstat -k -l")
|
87
|
+
so.stdout.lines do |line|
|
88
|
+
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\.]+)\)/
|
89
|
+
modules[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
kernel[:modules] = modules
|
94
|
+
end
|
95
|
+
|
96
|
+
collect_data(:freebsd) do
|
97
|
+
kernel init_kernel
|
98
|
+
kernel[:os] = kernel[:name]
|
99
|
+
|
100
|
+
so = shell_out("uname -i")
|
101
|
+
kernel[:ident] = so.stdout.split($/)[0]
|
102
|
+
so = shell_out("sysctl kern.securelevel")
|
103
|
+
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
|
104
|
+
|
105
|
+
kernel[:modules] = bsd_modules("/sbin/kldstat")
|
106
|
+
end
|
107
|
+
|
108
|
+
collect_data(:linux) do
|
109
|
+
kernel init_kernel
|
110
|
+
|
111
|
+
so = shell_out("uname -o")
|
112
|
+
kernel[:os] = so.stdout.split($/)[0]
|
113
|
+
|
114
|
+
modules = Mash.new
|
115
|
+
so = shell_out("env lsmod")
|
116
|
+
so.stdout.lines do |line|
|
117
|
+
if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
|
118
|
+
modules[$1] = { :size => $2, :refcount => $3 }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
kernel[:modules] = modules
|
123
|
+
end
|
124
|
+
|
125
|
+
collect_data(:netbsd, :openbsd) do
|
126
|
+
kernel init_kernel
|
127
|
+
kernel[:os] = kernel[:name]
|
128
|
+
|
129
|
+
so = shell_out("sysctl kern.securelevel")
|
130
|
+
kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ }
|
131
|
+
|
132
|
+
kernel[:modules] = bsd_modules("/usr/bin/modstat")
|
133
|
+
end
|
134
|
+
|
135
|
+
collect_data(:solaris2) do
|
136
|
+
kernel init_kernel
|
137
|
+
|
138
|
+
so = shell_out("uname -s")
|
139
|
+
kernel[:os] = so.stdout.split($/)[0]
|
140
|
+
|
141
|
+
modules = Mash.new
|
142
|
+
|
143
|
+
so = shell_out("modinfo")
|
144
|
+
# EXAMPLE:
|
145
|
+
# Id Loadaddr Size Info Rev Module Name
|
146
|
+
# 6 1180000 4623 1 1 specfs (filesystem for specfs)
|
147
|
+
module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
|
148
|
+
so.stdout.lines do |line|
|
149
|
+
if mod = module_description.match(line)
|
150
|
+
modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
kernel[:modules] = modules
|
155
|
+
end
|
156
|
+
|
157
|
+
collect_data(:windows) do
|
158
|
+
require 'ruby-wmi'
|
159
|
+
WIN32OLE.codepage = WIN32OLE::CP_UTF8
|
160
|
+
|
161
|
+
kernel Mash.new
|
162
|
+
|
163
|
+
host = WMI::Win32_OperatingSystem.find(:first)
|
164
|
+
kernel[:os_info] = Mash.new
|
165
|
+
host.properties_.each do |p|
|
166
|
+
kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
|
167
|
+
end
|
168
|
+
|
169
|
+
kernel[:name] = "#{kernel[:os_info][:caption]}"
|
170
|
+
kernel[:release] = "#{kernel[:os_info][:version]}"
|
171
|
+
kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}"
|
172
|
+
kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os]
|
173
|
+
|
174
|
+
host = WMI::Win32_ComputerSystem.find(:first)
|
175
|
+
kernel[:cs_info] = Mash.new
|
176
|
+
host.properties_.each do |p|
|
177
|
+
kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name)
|
178
|
+
end
|
179
|
+
|
180
|
+
kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}")
|
181
|
+
|
182
|
+
kext = Mash.new
|
183
|
+
pnp_drivers = Mash.new
|
184
|
+
|
185
|
+
drivers = WMI::Win32_PnPSignedDriver.find(:all)
|
186
|
+
drivers.each do |driver|
|
187
|
+
pnp_drivers[driver.DeviceID] = Mash.new
|
188
|
+
driver.properties_.each do |p|
|
189
|
+
pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name)
|
190
|
+
end
|
191
|
+
if driver.DeviceName
|
192
|
+
kext[driver.DeviceName] = pnp_drivers[driver.DeviceID]
|
193
|
+
kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version]
|
194
|
+
kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
kernel[:pnp_drivers] = pnp_drivers
|
199
|
+
kernel[:modules] = kext
|
200
|
+
end
|
34
201
|
end
|