ohai 16.5.4 → 16.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +7 -8
- data/bin/ohai +1 -0
- data/lib/ohai.rb +1 -0
- data/lib/ohai/application.rb +40 -0
- data/lib/ohai/common/dmi.rb +8 -3
- data/lib/ohai/config.rb +1 -0
- data/lib/ohai/dsl.rb +1 -0
- data/lib/ohai/dsl/plugin.rb +9 -1
- data/lib/ohai/dsl/plugin/versionvii.rb +28 -17
- data/lib/ohai/exception.rb +1 -0
- data/lib/ohai/hints.rb +1 -0
- data/lib/ohai/log.rb +1 -0
- data/lib/ohai/mash.rb +1 -0
- data/lib/ohai/mixin/azure_metadata.rb +4 -3
- data/lib/ohai/mixin/chef_utils_wiring.rb +14 -1
- data/lib/ohai/mixin/command.rb +1 -0
- data/lib/ohai/mixin/constant_helper.rb +1 -0
- data/lib/ohai/mixin/dmi_decode.rb +1 -0
- data/lib/ohai/mixin/do_metadata.rb +3 -2
- data/lib/ohai/mixin/ec2_metadata.rb +10 -9
- data/lib/ohai/mixin/gce_metadata.rb +4 -3
- data/lib/ohai/mixin/http_helper.rb +1 -0
- data/lib/ohai/mixin/network_helper.rb +1 -0
- data/lib/ohai/mixin/os.rb +67 -1
- data/lib/ohai/mixin/scaleway_metadata.rb +3 -2
- data/lib/ohai/mixin/seconds_to_human.rb +1 -0
- data/lib/ohai/mixin/shell_out.rb +1 -0
- data/lib/ohai/mixin/softlayer_metadata.rb +2 -1
- data/lib/ohai/mixin/string.rb +1 -0
- data/lib/ohai/mixin/train_helpers.rb +36 -0
- data/lib/ohai/mixin/which.rb +1 -0
- data/lib/ohai/plugin_config.rb +1 -0
- data/lib/ohai/plugins/aix/kernel.rb +7 -4
- data/lib/ohai/plugins/aix/memory.rb +4 -3
- data/lib/ohai/plugins/aix/network.rb +51 -58
- data/lib/ohai/plugins/aix/platform.rb +3 -2
- data/lib/ohai/plugins/aix/uptime.rb +3 -2
- data/lib/ohai/plugins/aix/virtualization.rb +6 -6
- data/lib/ohai/plugins/azure.rb +25 -4
- data/lib/ohai/plugins/bsd/virtualization.rb +3 -2
- data/lib/ohai/plugins/c.rb +4 -3
- data/lib/ohai/plugins/chef.rb +2 -1
- data/lib/ohai/plugins/cloud.rb +2 -1
- data/lib/ohai/plugins/command.rb +1 -0
- data/lib/ohai/plugins/cpu.rb +31 -32
- data/lib/ohai/plugins/darwin/hardware.rb +1 -0
- data/lib/ohai/plugins/darwin/memory.rb +2 -3
- data/lib/ohai/plugins/darwin/network.rb +8 -9
- data/lib/ohai/plugins/darwin/platform.rb +1 -0
- data/lib/ohai/plugins/darwin/virtualization.rb +2 -1
- data/lib/ohai/plugins/digital_ocean.rb +3 -1
- data/lib/ohai/plugins/dmi.rb +6 -5
- data/lib/ohai/plugins/docker.rb +2 -1
- data/lib/ohai/plugins/dragonflybsd/memory.rb +9 -8
- data/lib/ohai/plugins/dragonflybsd/network.rb +1 -0
- data/lib/ohai/plugins/dragonflybsd/platform.rb +3 -2
- data/lib/ohai/plugins/ec2.rb +14 -7
- data/lib/ohai/plugins/elixir.rb +1 -1
- data/lib/ohai/plugins/erlang.rb +1 -0
- data/lib/ohai/plugins/eucalyptus.rb +4 -1
- data/lib/ohai/plugins/filesystem.rb +4 -4
- data/lib/ohai/plugins/fips.rb +1 -0
- data/lib/ohai/plugins/freebsd/memory.rb +9 -8
- data/lib/ohai/plugins/freebsd/network.rb +1 -0
- data/lib/ohai/plugins/freebsd/platform.rb +3 -2
- data/lib/ohai/plugins/gce.rb +3 -2
- data/lib/ohai/plugins/go.rb +1 -1
- data/lib/ohai/plugins/groovy.rb +1 -1
- data/lib/ohai/plugins/grub2.rb +40 -0
- data/lib/ohai/plugins/haskell.rb +1 -0
- data/lib/ohai/plugins/hostname.rb +2 -2
- data/lib/ohai/plugins/init_package.rb +2 -1
- data/lib/ohai/plugins/java.rb +1 -0
- data/lib/ohai/plugins/kernel.rb +14 -11
- data/lib/ohai/plugins/keys.rb +1 -0
- data/lib/ohai/plugins/languages.rb +1 -0
- data/lib/ohai/plugins/libvirt.rb +4 -3
- data/lib/ohai/plugins/linode.rb +22 -14
- data/lib/ohai/plugins/linux/block_device.rb +9 -8
- data/lib/ohai/plugins/linux/hostnamectl.rb +3 -2
- data/lib/ohai/plugins/linux/interrupts.rb +4 -3
- data/lib/ohai/plugins/linux/ipc.rb +2 -1
- data/lib/ohai/plugins/linux/lsb.rb +7 -20
- data/lib/ohai/plugins/linux/lspci.rb +1 -1
- data/lib/ohai/plugins/linux/machineid.rb +5 -4
- data/lib/ohai/plugins/linux/mdadm.rb +3 -2
- data/lib/ohai/plugins/linux/memory.rb +38 -37
- data/lib/ohai/plugins/linux/network.rb +7 -6
- data/lib/ohai/plugins/linux/platform.rb +31 -30
- data/lib/ohai/plugins/linux/selinux.rb +1 -0
- data/lib/ohai/plugins/linux/sessions.rb +1 -0
- data/lib/ohai/plugins/linux/sysctl.rb +1 -0
- data/lib/ohai/plugins/linux/systemd_paths.rb +1 -0
- data/lib/ohai/plugins/linux/virtualization.rb +24 -23
- data/lib/ohai/plugins/lua.rb +1 -1
- data/lib/ohai/plugins/mono.rb +1 -1
- data/lib/ohai/plugins/netbsd/memory.rb +1 -0
- data/lib/ohai/plugins/netbsd/network.rb +1 -0
- data/lib/ohai/plugins/netbsd/platform.rb +3 -2
- data/lib/ohai/plugins/network.rb +2 -1
- data/lib/ohai/plugins/nodejs.rb +1 -1
- data/lib/ohai/plugins/ohai.rb +1 -0
- data/lib/ohai/plugins/ohai_time.rb +2 -1
- data/lib/ohai/plugins/openbsd/memory.rb +1 -0
- data/lib/ohai/plugins/openbsd/network.rb +1 -0
- data/lib/ohai/plugins/openbsd/platform.rb +3 -2
- data/lib/ohai/plugins/openstack.rb +1 -0
- data/lib/ohai/plugins/os.rb +6 -1
- data/lib/ohai/plugins/packages.rb +2 -1
- data/lib/ohai/plugins/passwd.rb +58 -1
- data/lib/ohai/plugins/perl.rb +1 -1
- data/lib/ohai/plugins/php.rb +1 -1
- data/lib/ohai/plugins/platform.rb +1 -0
- data/lib/ohai/plugins/powershell.rb +1 -1
- data/lib/ohai/plugins/ps.rb +1 -0
- data/lib/ohai/plugins/python.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +6 -5
- data/lib/ohai/plugins/root_group.rb +1 -0
- data/lib/ohai/plugins/ruby.rb +3 -2
- data/lib/ohai/plugins/rust.rb +1 -1
- data/lib/ohai/plugins/scala.rb +1 -0
- data/lib/ohai/plugins/scaleway.rb +3 -2
- data/lib/ohai/plugins/scsi.rb +1 -1
- data/lib/ohai/plugins/shard.rb +1 -1
- data/lib/ohai/plugins/shells.rb +3 -2
- data/lib/ohai/plugins/softlayer.rb +1 -0
- data/lib/ohai/plugins/solaris2/dmi.rb +2 -1
- data/lib/ohai/plugins/solaris2/memory.rb +1 -0
- data/lib/ohai/plugins/solaris2/network.rb +2 -1
- data/lib/ohai/plugins/solaris2/platform.rb +8 -14
- data/lib/ohai/plugins/solaris2/virtualization.rb +4 -4
- data/lib/ohai/plugins/ssh_host_key.rb +13 -12
- data/lib/ohai/plugins/sysconf.rb +1 -0
- data/lib/ohai/plugins/timezone.rb +1 -0
- data/lib/ohai/plugins/train.rb +35 -0
- data/lib/ohai/plugins/uptime.rb +2 -1
- data/lib/ohai/plugins/virtualbox.rb +2 -1
- data/lib/ohai/plugins/vmware.rb +3 -3
- data/lib/ohai/plugins/windows/dmi.rb +1 -0
- data/lib/ohai/plugins/windows/drivers.rb +1 -0
- data/lib/ohai/plugins/windows/memory.rb +1 -0
- data/lib/ohai/plugins/windows/network.rb +2 -1
- data/lib/ohai/plugins/windows/platform.rb +1 -0
- data/lib/ohai/plugins/windows/system_enclosure.rb +1 -0
- data/lib/ohai/plugins/windows/virtualization.rb +1 -0
- data/lib/ohai/plugins/zpools.rb +5 -3
- data/lib/ohai/provides_map.rb +1 -0
- data/lib/ohai/runner.rb +7 -4
- data/lib/ohai/system.rb +33 -4
- data/lib/ohai/train_transport.rb +29 -0
- data/lib/ohai/util/file_helper.rb +1 -0
- data/lib/ohai/util/ip_helper.rb +2 -1
- data/lib/ohai/util/win32.rb +1 -0
- data/lib/ohai/version.rb +2 -1
- data/ohai.gemspec +3 -1
- metadata +21 -4
- data/lib/ohai/plugins/joyent.rb +0 -77
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Ranjib Dey (<dey.ranjib@gmail.com>)
|
3
4
|
# License:: Apache License, Version 2.0
|
@@ -21,8 +22,8 @@ module Ohai
|
|
21
22
|
module GCEMetadata
|
22
23
|
|
23
24
|
# Trailing dot to host is added to avoid DNS search path
|
24
|
-
GCE_METADATA_ADDR ||= "metadata.google.internal."
|
25
|
-
GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true"
|
25
|
+
GCE_METADATA_ADDR ||= "metadata.google.internal."
|
26
|
+
GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true"
|
26
27
|
|
27
28
|
# fetch the meta content with a timeout and the required header
|
28
29
|
def http_get(uri)
|
@@ -71,7 +72,7 @@ module Ohai
|
|
71
72
|
#
|
72
73
|
# @return [Boolean] is there a trailing /?
|
73
74
|
def has_trailing_slash?(data)
|
74
|
-
!!
|
75
|
+
!!( data =~ %r{/$} )
|
75
76
|
end
|
76
77
|
|
77
78
|
def sanitize_key(key)
|
data/lib/ohai/mixin/os.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Adam Jacob (<adam@chef.io>)
|
3
4
|
# Copyright:: Copyright (c) Chef Software Inc.
|
@@ -27,6 +28,71 @@ module Ohai
|
|
27
28
|
#
|
28
29
|
# @return [String] the OS
|
29
30
|
def collect_os
|
31
|
+
if target_mode?
|
32
|
+
collect_os_target
|
33
|
+
else
|
34
|
+
collect_os_local
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# This should exactly preserve the semantics of collect_os_local below, which is authoritative
|
39
|
+
# for the API and must adhere to pre-existing ohai semantics and not follow inspec's notion of
|
40
|
+
# os/family/hierarchy.
|
41
|
+
#
|
42
|
+
# Right or wrong the ohai `os` variable has matched the ruby `host_os` definition for the past
|
43
|
+
# 10+ years, preceding inspec/train's definitions and this is the documented correct API of
|
44
|
+
# these methods. Mismatches between the ruby notion and the train version will be fixed as
|
45
|
+
# bugfixes in these methods and may not be considered semver violating even though they make
|
46
|
+
# break downstream consumers. Please ensure that both methods produce the same results if
|
47
|
+
# you are on a platform which supports running ruby (train is considered authoritative for
|
48
|
+
# any "OS" which cannot run ruby -- server consoles, REST APIs, etc...)
|
49
|
+
#
|
50
|
+
# @api private
|
51
|
+
def collect_os_target
|
52
|
+
case
|
53
|
+
when transport_connection.os.aix?
|
54
|
+
"aix"
|
55
|
+
when transport_connection.os.darwin?
|
56
|
+
"darwin"
|
57
|
+
when transport_connection.os.linux?
|
58
|
+
"linux"
|
59
|
+
when transport_connection.os.family == "freebsd"
|
60
|
+
"freebsd"
|
61
|
+
when transport_connection.os.family == "openbsd"
|
62
|
+
"openbsd"
|
63
|
+
when transport_connection.os.family == "netbsd"
|
64
|
+
"netbsd"
|
65
|
+
when transport_connection.os.family == "dragonflybsd"
|
66
|
+
"dragonflybsd"
|
67
|
+
when transport_connection.os.solaris?
|
68
|
+
"solaris2"
|
69
|
+
when transport_connection.os.windows?
|
70
|
+
"windows"
|
71
|
+
|
72
|
+
#
|
73
|
+
# The purpose of the next two lines is that anything which runs Unix is presumed to be able to run ruby, and
|
74
|
+
# if it was not caught above, we MUST translate whatever train uses as the 'os' into the proper ruby host_os
|
75
|
+
# string. If it is not unix and not caught above we assume it is something like a REST API which cannot run
|
76
|
+
# ruby. If these assumptions are incorrect then it is a bug, which should be submitted to fix it, and the
|
77
|
+
# values should not be relied upon until that bug is fixed. The train os is NEVER considered authoritative
|
78
|
+
# for any target which can run ruby.
|
79
|
+
#
|
80
|
+
when transport_connection.os.unix?
|
81
|
+
raise "Target mode unsupported on this Unix-like host, please update the collect_os_target case statement with the correct ruby host_os value."
|
82
|
+
else
|
83
|
+
# now we have something like an IPMI console that isn't Unix-like or Windows, presumably cannot run ruby, and
|
84
|
+
# so we just trust the train O/S information.
|
85
|
+
transport_connection.os
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# @api private
|
90
|
+
def nonruby_target?
|
91
|
+
transport_connection && !transport_connection.os.unix? && !transport_connection.os.windows
|
92
|
+
end
|
93
|
+
|
94
|
+
# @api private
|
95
|
+
def collect_os_local
|
30
96
|
case ::RbConfig::CONFIG["host_os"]
|
31
97
|
when /aix(.+)$/
|
32
98
|
"aix"
|
@@ -56,7 +122,7 @@ module Ohai
|
|
56
122
|
end
|
57
123
|
end
|
58
124
|
|
59
|
-
|
125
|
+
extend self
|
60
126
|
end
|
61
127
|
end
|
62
128
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Jonathan Amiez (<jonathan.amiez@gmail.com>)
|
3
4
|
# License:: Apache License, Version 2.0
|
@@ -20,8 +21,8 @@ module Ohai
|
|
20
21
|
module Mixin
|
21
22
|
module ScalewayMetadata
|
22
23
|
|
23
|
-
SCALEWAY_METADATA_ADDR ||= "169.254.42.42"
|
24
|
-
SCALEWAY_METADATA_URL ||= "/conf?format=json"
|
24
|
+
SCALEWAY_METADATA_ADDR ||= "169.254.42.42"
|
25
|
+
SCALEWAY_METADATA_URL ||= "/conf?format=json"
|
25
26
|
|
26
27
|
# @return [Net::HTTP] net/http object without timeout set to 6
|
27
28
|
def http_client
|
data/lib/ohai/mixin/shell_out.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Alexey Karpik <alexey.karpik@rightscale.com>
|
3
4
|
# Author:: Peter Schroeter <peter.schroeter@rightscale.com>
|
@@ -22,7 +23,7 @@ require "uri" unless defined?(URI)
|
|
22
23
|
|
23
24
|
# https://softlayer.github.io/reference/services/SoftLayer_Resource_Metadata/
|
24
25
|
module ::Ohai::Mixin::SoftlayerMetadata
|
25
|
-
SOFTLAYER_API_QUERY_URL ||= "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata"
|
26
|
+
SOFTLAYER_API_QUERY_URL ||= "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata"
|
26
27
|
|
27
28
|
# fetch metadata items and build out hash of data
|
28
29
|
#
|
data/lib/ohai/mixin/string.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
#
|
3
|
+
# Copyright:: Copyright (c) Chef Software Inc.
|
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
|
+
require "chef-utils/dsl/train_helpers" unless defined?(ChefUtils::DSL::TrainHelpers)
|
19
|
+
require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
|
20
|
+
|
21
|
+
module Ohai
|
22
|
+
module Mixin
|
23
|
+
module TrainHelpers
|
24
|
+
include ChefUtils::DSL::TrainHelpers
|
25
|
+
include ChefUtilsWiring
|
26
|
+
|
27
|
+
# anything added to this file temporarily should be pushed back up
|
28
|
+
# into ChefUtils::DSL::TrainHelpers
|
29
|
+
|
30
|
+
# XXX: this needs better support directly in train
|
31
|
+
def dir_glob(path)
|
32
|
+
shell_out!("ls -d #{path}").stdout.split
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/ohai/mixin/which.rb
CHANGED
data/lib/ohai/plugin_config.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Joshua Timberman <joshua@chef.io>
|
3
4
|
# Author:: Isa Farnik (<isa@chef.io>)
|
@@ -23,10 +24,12 @@ Ohai.plugin(:Kernel) do
|
|
23
24
|
collect_data(:aix) do
|
24
25
|
kernel Mash.new
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
kernel[:
|
29
|
-
kernel[:
|
27
|
+
uname_so = shell_out("uname -rvp").stdout.split
|
28
|
+
|
29
|
+
kernel[:name] = "aix" # this is here for historical reasons, but it's always aix
|
30
|
+
kernel[:release] = uname_so[0]
|
31
|
+
kernel[:version] = uname_so[1]
|
32
|
+
kernel[:machine] = uname_so[2]
|
30
33
|
kernel[:bits] = shell_out("getconf KERNEL_BITMODE").stdout.strip
|
31
34
|
|
32
35
|
modules = Mash.new
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Joshua Timberman <joshua@chef.io>
|
3
4
|
# Author:: Isa Farnik (<isa@chef.io>)
|
@@ -24,10 +25,10 @@ Ohai.plugin(:Memory) do
|
|
24
25
|
memory Mash.new
|
25
26
|
memory[:swap] = Mash.new
|
26
27
|
|
27
|
-
meminfo = shell_out("svmon -G -O unit=
|
28
|
+
meminfo = shell_out("svmon -G -O unit=KB,summary=longreal | grep '[0-9]'").stdout
|
28
29
|
total_in_mb, _u, free_in_mb = meminfo.split
|
29
|
-
memory[:total] = "#{total_in_mb.to_i
|
30
|
-
memory[:free] = "#{free_in_mb.to_i
|
30
|
+
memory[:total] = "#{total_in_mb.to_i}kB"
|
31
|
+
memory[:free] = "#{free_in_mb.to_i}kB"
|
31
32
|
|
32
33
|
swap_info = shell_out("swap -s").stdout.split # returns swap info in 4K blocks
|
33
34
|
memory[:swap]["total"] = "#{swap_info[2].to_i * 4}kB"
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
|
3
4
|
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
@@ -21,7 +22,7 @@
|
|
21
22
|
Ohai.plugin(:Network) do
|
22
23
|
require_relative "../../mixin/network_helper"
|
23
24
|
|
24
|
-
provides "network", "counters/network", "macaddress"
|
25
|
+
provides "network", "network/interfaces", "counters/network", "macaddress"
|
25
26
|
|
26
27
|
include Ohai::Mixin::NetworkHelper
|
27
28
|
|
@@ -37,46 +38,44 @@ Ohai.plugin(:Network) do
|
|
37
38
|
# => state up/down (ifconfig/lsattr)
|
38
39
|
# => arp (arp -an)
|
39
40
|
|
40
|
-
|
41
|
+
ifaces = Mash.new
|
41
42
|
|
42
43
|
network Mash.new unless network
|
43
|
-
network[:interfaces] ||= Mash.new
|
44
44
|
|
45
45
|
# We unfortunately have to do things a bit different here, if ohai is running
|
46
46
|
# within a WPAR. For instance, the WPAR isn't aware of some of its own networking
|
47
|
-
# minutia such as default gateway/route.
|
47
|
+
# minutia such as default gateway/route. lpars return 0 here. wpars return > 0
|
48
48
|
unless shell_out("uname -W").stdout.to_i > 0
|
49
49
|
# :default_interface, :default_gateway - route -n get 0
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
end
|
50
|
+
default_line = shell_out("netstat -rn")
|
51
|
+
.stdout
|
52
|
+
.each_line
|
53
|
+
.detect { |l| l.start_with?("default") }
|
54
|
+
.split
|
55
|
+
network[:default_gateway] = default_line[1]
|
56
|
+
network[:default_interface] = default_line[5]
|
58
57
|
end
|
59
58
|
|
60
|
-
# Splits the ifconfig output
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
case lin
|
59
|
+
# Splits the ifconfig output into arrays of interface strings
|
60
|
+
shell_out("ifconfig -a").stdout.split(/\n(?=\w)/).each do |int_lines|
|
61
|
+
int_name, int_data = int_lines.split(":", 2)
|
62
|
+
|
63
|
+
ifaces[int_name] = Mash.new
|
64
|
+
ifaces[int_name][:addresses] ||= Mash.new
|
65
|
+
ifaces[int_name][:state] = (int_data.include?("<UP,") ? "up" : "down")
|
66
|
+
|
67
|
+
int_data.each_line do |line|
|
68
|
+
case line
|
71
69
|
when /flags=\S+<(\S+)>/
|
72
|
-
|
73
|
-
|
70
|
+
ifaces[int_name][:flags] = $1.split(",")
|
71
|
+
ifaces[int_name][:metric] = $1 if line =~ /metric\s(\S+)/
|
74
72
|
else
|
75
73
|
# We have key value pairs.
|
76
|
-
if
|
77
|
-
tmp_addr
|
74
|
+
if line =~ %r{inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/(\d{1,2}))?}
|
75
|
+
tmp_addr = $1
|
76
|
+
tmp_prefix = $3
|
78
77
|
if tmp_prefix.nil?
|
79
|
-
netmask = hex_to_dec_netmask($1) if
|
78
|
+
netmask = hex_to_dec_netmask($1) if line =~ /netmask\s0x(\S+)\s/
|
80
79
|
unless netmask
|
81
80
|
tmp_prefix ||= "32"
|
82
81
|
netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
|
@@ -85,57 +84,51 @@ Ohai.plugin(:Network) do
|
|
85
84
|
netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
|
86
85
|
end
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
iface[interface][:addresses][tmp_addr][:netmask] = netmask
|
87
|
+
ifaces[int_name][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
|
88
|
+
ifaces[int_name][:addresses][tmp_addr][:netmask] = netmask
|
91
89
|
|
92
|
-
if
|
93
|
-
|
90
|
+
if line =~ /broadcast\s(\S+)\s/
|
91
|
+
ifaces[int_name][:addresses][tmp_addr][:broadcast] = $1
|
94
92
|
end
|
95
|
-
elsif
|
96
|
-
# TODO do we have more properties on inet6 in aix? broadcast
|
97
|
-
|
98
|
-
|
93
|
+
elsif line =~ %r{inet6 ([a-f0-9\:]+)%?(\d*)/?(\d*)?}
|
94
|
+
# TODO: do we have more properties on inet6 in aix? broadcast
|
95
|
+
ifaces[int_name][:addresses] ||= Mash.new
|
96
|
+
ifaces[int_name][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
|
99
97
|
else
|
100
|
-
#
|
101
|
-
|
102
|
-
|
103
|
-
(
|
104
|
-
|
98
|
+
# add all key value data into the interface mash
|
99
|
+
# for example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
|
100
|
+
# has keys tcp_sendspace, tcp_recvspace, and rfc1323
|
101
|
+
line.split.each_slice(2) do |key, value|
|
102
|
+
ifaces[int_name][key] = value
|
105
103
|
end
|
106
104
|
end
|
107
105
|
end
|
108
106
|
end
|
109
107
|
|
110
108
|
# Query macaddress
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" }
|
116
|
-
macaddress $1.upcase unless shell_out("uname -W").stdout.to_i > 0
|
117
|
-
end
|
109
|
+
shell_out("entstat -d #{int_name}").stdout =~ /Hardware Address: (\S+)/
|
110
|
+
if $1
|
111
|
+
ifaces[int_name][:addresses][$1.upcase] = { "family" => "lladdr" }
|
112
|
+
macaddress $1.upcase unless shell_out("uname -W").stdout.to_i > 0
|
118
113
|
end
|
119
114
|
end # ifconfig stdout
|
120
115
|
|
121
116
|
# Query routes information
|
122
117
|
%w{inet inet6}.each do |family|
|
123
|
-
|
124
|
-
so_n.stdout.lines.each do |line|
|
118
|
+
shell_out("netstat -nrf #{family}").stdout.each_line do |line|
|
125
119
|
if line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/
|
126
120
|
interface = $6
|
127
|
-
|
128
|
-
|
129
|
-
|
121
|
+
ifaces[interface][:routes] ||= []
|
122
|
+
ifaces[interface][:routes] << Mash.new( destination: $1, family: family,
|
123
|
+
via: $2, flags: $3)
|
130
124
|
end
|
131
125
|
end
|
132
126
|
end
|
133
127
|
|
134
128
|
# List the arp entries in system.
|
135
|
-
so = shell_out("arp -an")
|
136
129
|
count = 0
|
137
|
-
|
138
|
-
|
130
|
+
network[:arp] ||= Mash.new
|
131
|
+
shell_out("arp -an").stdout.each_line do |line|
|
139
132
|
if line =~ /\s*(\S+) \((\S+)\) at ([a-fA-F0-9\:]+) \[(\w+)\] stored in bucket/
|
140
133
|
network[:arp][count] ||= Mash.new
|
141
134
|
network[:arp][count][:remote_host] = $1
|
@@ -144,6 +137,6 @@ Ohai.plugin(:Network) do
|
|
144
137
|
count += 1
|
145
138
|
end
|
146
139
|
end
|
147
|
-
network["interfaces"] =
|
140
|
+
network["interfaces"] = ifaces
|
148
141
|
end
|
149
142
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
#
|
2
3
|
# Author:: Joshua Timberman <joshua@chef.io>
|
3
4
|
# Author:: Isa Farnik (<isa@chef.io>)
|
@@ -22,8 +23,8 @@ Ohai.plugin(:Platform) do
|
|
22
23
|
depends "kernel"
|
23
24
|
|
24
25
|
collect_data(:aix) do
|
25
|
-
platform
|
26
|
+
platform "aix"
|
27
|
+
platform_family "aix"
|
26
28
|
platform_version [kernel[:version], kernel[:release]].join(".")
|
27
|
-
platform_family platform
|
28
29
|
end
|
29
30
|
end
|