ohai 6.18.0 → 6.20.0.rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/ohai/mixin/command.rb +4 -3
- data/lib/ohai/mixin/gce_metadata.rb +1 -1
- data/lib/ohai/plugins/aix/cpu.rb +33 -3
- data/lib/ohai/plugins/aix/filesystem.rb +57 -3
- data/lib/ohai/plugins/aix/hostname.rb +3 -1
- data/lib/ohai/plugins/aix/kernel.rb +27 -0
- data/lib/ohai/plugins/aix/memory.rb +8 -3
- data/lib/ohai/plugins/aix/network.rb +139 -3
- data/lib/ohai/plugins/aix/platform.rb +9 -3
- data/lib/ohai/plugins/aix/uptime.rb +18 -3
- data/lib/ohai/plugins/cloud.rb +13 -6
- data/lib/ohai/plugins/gce.rb +22 -4
- data/lib/ohai/plugins/linux/platform.rb +3 -6
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/mixin/command_spec.rb +22 -2
- data/spec/unit/plugins/aix/cpu_spec.rb +81 -0
- data/spec/unit/plugins/aix/filesystem_spec.rb +111 -0
- data/spec/unit/plugins/aix/hostname_spec.rb +28 -0
- data/spec/unit/plugins/aix/kernel_spec.rb +51 -0
- data/spec/unit/plugins/aix/network_spec.rb +258 -0
- data/spec/unit/plugins/aix/platform_spec.rb +42 -0
- data/spec/unit/plugins/aix/uptime_spec.rb +40 -0
- data/spec/unit/plugins/gce_spec.rb +28 -68
- data/spec/unit/plugins/linux/platform_spec.rb +0 -6
- metadata +45 -11
- checksums.yaml +0 -15
data/lib/ohai/mixin/command.rb
CHANGED
@@ -128,12 +128,12 @@ module Ohai
|
|
128
128
|
#
|
129
129
|
# Thanks Ara!
|
130
130
|
def popen4(cmd, args={}, &b)
|
131
|
-
|
131
|
+
|
132
132
|
## Disable garbage collection to work around possible bug in MRI
|
133
133
|
# Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select
|
134
134
|
# See OHAI-330 / CHEF-2916 / CHEF-1305
|
135
135
|
GC.disable
|
136
|
-
|
136
|
+
|
137
137
|
# Waitlast - this is magic.
|
138
138
|
#
|
139
139
|
# Do we wait for the child process to die before we yield
|
@@ -329,9 +329,10 @@ module Ohai
|
|
329
329
|
# have encoding methods.
|
330
330
|
if "".respond_to?(:force_encoding) && defined?(Encoding)
|
331
331
|
o.string.force_encoding(Encoding.default_external)
|
332
|
+
o.string.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
|
332
333
|
e.string.force_encoding(Encoding.default_external)
|
334
|
+
e.string.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
|
333
335
|
end
|
334
|
-
|
335
336
|
b[cid, pi[0], o, e]
|
336
337
|
results.last
|
337
338
|
end
|
@@ -24,7 +24,7 @@ module Ohai
|
|
24
24
|
extend self
|
25
25
|
|
26
26
|
GCE_METADATA_ADDR = "metadata.google.internal" unless defined?(GCE_METADATA_ADDR)
|
27
|
-
GCE_METADATA_URL = "/
|
27
|
+
GCE_METADATA_URL = "/computeMetadata/v1beta1/?recursive=true" unless defined?(GCE_METADATA_URL)
|
28
28
|
|
29
29
|
def can_metadata_connect?(addr, port, timeout=2)
|
30
30
|
t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
|
data/lib/ohai/plugins/aix/cpu.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
#
|
2
|
+
# Author:: Joshua Timberman <joshua@opscode.com>
|
3
|
+
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
4
|
+
# Copyright:: Copyright (c) 2013, Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,4 +17,33 @@
|
|
16
17
|
# limitations under the License.
|
17
18
|
#
|
18
19
|
|
19
|
-
|
20
|
+
provides "cpu"
|
21
|
+
|
22
|
+
cpu Mash.new
|
23
|
+
|
24
|
+
# IBM is the only maker of CPUs for AIX systems.
|
25
|
+
cpu[:vendor_id] = "IBM"
|
26
|
+
# At least one CPU will be available, but we'll wait to increment this later.
|
27
|
+
cpu[:available] = 0
|
28
|
+
cpu[:total] = 0
|
29
|
+
|
30
|
+
cpudevs = from("lsdev -Cc processor").lines
|
31
|
+
cpudevs.each do |c|
|
32
|
+
cpu[:total] += 1
|
33
|
+
name, status, location = c.split
|
34
|
+
cpu[name] = Mash.new
|
35
|
+
cpu[name][:status] = status
|
36
|
+
cpu[name][:location] = location
|
37
|
+
if status =~ /Available/
|
38
|
+
cpu[:available] += 1
|
39
|
+
lsattr = from("lsattr -El #{name}").lines
|
40
|
+
lsattr.each do |attribute|
|
41
|
+
attrib, value = attribute.split
|
42
|
+
cpu[name][attrib] = value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# Every AIX system has proc0.
|
48
|
+
cpu[:model] = cpu[:proc0][:type]
|
49
|
+
cpu[:mhz] = cpu[:proc0][:frequency].to_i / 1024
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
#
|
2
|
+
# Author:: Deepali Jagtap (<deepali.jagtap@clogeny.com>)
|
3
|
+
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
4
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,4 +17,57 @@
|
|
16
17
|
# limitations under the License.
|
17
18
|
#
|
18
19
|
|
19
|
-
|
20
|
+
provides "filesystem"
|
21
|
+
|
22
|
+
fs = Mash.new
|
23
|
+
|
24
|
+
# Grab filesystem data from df
|
25
|
+
popen4("df -P") do |pid, stdin, stdout, stderr|
|
26
|
+
stdin.close
|
27
|
+
stdout.each do |line|
|
28
|
+
case line
|
29
|
+
when /^Filesystem\s+1024-blocks/
|
30
|
+
next
|
31
|
+
when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
|
32
|
+
filesystem = $1
|
33
|
+
fs[filesystem] = Mash.new
|
34
|
+
fs[filesystem][:kb_size] = $2
|
35
|
+
fs[filesystem][:kb_used] = $3
|
36
|
+
fs[filesystem][:kb_available] = $4
|
37
|
+
fs[filesystem][:percent_used] = $5
|
38
|
+
fs[filesystem][:mount] = $6
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Grab mount information from /bin/mount
|
44
|
+
popen4("mount") do |pid, stdin, stdout, stderr|
|
45
|
+
stdin.close
|
46
|
+
stdout.each do |line|
|
47
|
+
case line
|
48
|
+
when /^\s*node/
|
49
|
+
next
|
50
|
+
when /^\s*---/
|
51
|
+
next
|
52
|
+
when /^\s*\/\w/
|
53
|
+
fields = line.split
|
54
|
+
filesystem = fields[0]
|
55
|
+
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
|
56
|
+
fs[filesystem][:mount] = fields[1]
|
57
|
+
fs[filesystem][:fs_type] = fields[2]
|
58
|
+
#fs[filesystem][:mount_options] = fields[6]
|
59
|
+
fs[filesystem][:mount_options] = fields[6]
|
60
|
+
else
|
61
|
+
fields = line.split
|
62
|
+
filesystem = fields[0] + ":" + fields[1]
|
63
|
+
fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
|
64
|
+
fs[filesystem][:mount] = fields[2]
|
65
|
+
fs[filesystem][:fs_type] = fields[3]
|
66
|
+
fs[filesystem][:mount_options] = fields[7]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# Set the filesystem data
|
72
|
+
filesystem fs
|
73
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Joshua Timberman <joshua@opscode.com>
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, 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
|
+
|
19
|
+
provides "kernel"
|
20
|
+
|
21
|
+
kernel Mash.new
|
22
|
+
|
23
|
+
kernel[:name] = from("uname -s").downcase
|
24
|
+
kernel[:release] = from("uname -r")
|
25
|
+
kernel[:version] = from("uname -v")
|
26
|
+
kernel[:machine] = from("uname -p")
|
27
|
+
kernel[:modules] = Mash.new
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Author:: Joshua Timberman <joshua@opscode.com>
|
3
|
+
# Copyright:: Copyright (c) 2013, Opscode, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,4 +16,9 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
|
19
|
+
provides "memory"
|
20
|
+
|
21
|
+
memory = Mash.new
|
22
|
+
|
23
|
+
meminfo = from("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'")
|
24
|
+
memory[:total], u, memory[:free] = meminfo.split
|
@@ -1,6 +1,7 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
#
|
2
|
+
# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
|
3
|
+
# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
|
4
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
5
|
# License:: Apache License, Version 2.0
|
5
6
|
#
|
6
7
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,4 +17,139 @@
|
|
16
17
|
# limitations under the License.
|
17
18
|
#
|
18
19
|
|
19
|
-
|
20
|
+
require 'ipaddr'
|
21
|
+
provides "network", "counters/network"
|
22
|
+
|
23
|
+
# Loads following information.
|
24
|
+
# :default_interface, :default_gateway - route -n get 0
|
25
|
+
# :interfaces
|
26
|
+
# => routes(netstat -nr | grep en0)
|
27
|
+
# => addresses (ifconfig en0 or lsattr -El en0), macaddress (entstat -d en0 = Hardware Address: be:42:80:00:b0:05)
|
28
|
+
# => flags (ifconfig en0)
|
29
|
+
# => state up/down (ifconfig/lsattr)
|
30
|
+
# => arp (arp -an)
|
31
|
+
|
32
|
+
iface = Mash.new
|
33
|
+
|
34
|
+
|
35
|
+
# :default_interface, :default_gateway - route -n get 0
|
36
|
+
popen4("route -n get 0") do |pid, stdin, stdout, stderr|
|
37
|
+
stdin.close
|
38
|
+
stdout.each do |line|
|
39
|
+
case line
|
40
|
+
when /gateway: (\S+)/
|
41
|
+
network[:default_gateway] = $1
|
42
|
+
when /interface: (\S+)/
|
43
|
+
network[:default_interface] = $1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Helpers
|
49
|
+
def hex_to_dec_netmask(netmask)
|
50
|
+
# example '0xffff0000' -> '255.255.0.0'
|
51
|
+
dec = netmask[2..3].to_i(16).to_s(10)
|
52
|
+
[4,6,8].each { |n| dec = dec + "." + netmask[n..n+1].to_i(16).to_s(10) }
|
53
|
+
dec
|
54
|
+
end
|
55
|
+
|
56
|
+
# List the interfaces in system.
|
57
|
+
popen4("lsdev -Cc if") do |pid, stdin, stdout, stderr|
|
58
|
+
stdin.close
|
59
|
+
stdout.each do |line|
|
60
|
+
if line =~ /(\S+) (\S+)\s+(.+)/
|
61
|
+
interface = $1
|
62
|
+
iface[interface] = Mash.new unless iface[interface]
|
63
|
+
iface[interface][:state] = ($2 == 'Available' ? 'up' : 'down')
|
64
|
+
iface[interface][:description] = $3
|
65
|
+
|
66
|
+
# Query the interface information
|
67
|
+
popen4("ifconfig #{interface}") do |if_pid, if_stdin, if_stdout, if_stderr|
|
68
|
+
if_stdin.close
|
69
|
+
if_stdout.each do |line|
|
70
|
+
case line
|
71
|
+
when /^#{interface}:\sflags=\S+<(\S+)>/
|
72
|
+
iface[interface][:flags] = $1.split(',')
|
73
|
+
iface[interface][:metric] = $1 if line =~ /metric\s(\S+)/
|
74
|
+
else
|
75
|
+
# We have key value pairs.
|
76
|
+
if line =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/
|
77
|
+
tmp_addr, tmp_prefix = $1, $3
|
78
|
+
if tmp_prefix.nil?
|
79
|
+
netmask = hex_to_dec_netmask($1) if line =~ /netmask\s(\S+)\s/
|
80
|
+
unless netmask
|
81
|
+
tmp_prefix ||= "32"
|
82
|
+
netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
|
83
|
+
end
|
84
|
+
else
|
85
|
+
netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
|
86
|
+
end
|
87
|
+
|
88
|
+
iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
|
89
|
+
iface[interface][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
|
90
|
+
iface[interface][:addresses][tmp_addr][:netmask] = netmask
|
91
|
+
|
92
|
+
if line =~ /broadcast\s(\S+)\s/
|
93
|
+
iface[interface][:addresses][tmp_addr][:broadcast] = $1
|
94
|
+
end
|
95
|
+
elsif line =~ /inet6 ([a-f0-9\:%]+)\/(\d+)/
|
96
|
+
# TODO do we have more properties on inet6 in aix? broadcast
|
97
|
+
iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
|
98
|
+
iface[interface][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2 }
|
99
|
+
else
|
100
|
+
# load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
|
101
|
+
properties = line.split
|
102
|
+
n = properties.length/2 - 1
|
103
|
+
(0..n).each do |i|
|
104
|
+
iface[interface][properties[i*2]] = properties[(i*2+1)]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end #ifconfig stdout
|
110
|
+
|
111
|
+
# Query macaddress
|
112
|
+
popen4("entstat -d #{interface} | grep \"Hardware Address\"") do |e_pid, e_stdin, e_stdout, e_stderr|
|
113
|
+
e_stdin.close
|
114
|
+
iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
|
115
|
+
e_stdout.each do |line|
|
116
|
+
iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } if line =~ /Hardware Address: (\S+)/
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end #lsdev stdout
|
121
|
+
end
|
122
|
+
|
123
|
+
# Query routes information
|
124
|
+
%w{inet inet6}.each do |family|
|
125
|
+
popen4("netstat -nrf #{family}") do |n_pid, n_stdin, n_stdout, n_stderr|
|
126
|
+
n_stdin.close
|
127
|
+
n_stdout.each do |line|
|
128
|
+
if line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/
|
129
|
+
interface = $6
|
130
|
+
iface[interface][:routes] = Array.new unless iface[interface][:routes]
|
131
|
+
iface[interface][:routes] << Mash.new( :destination => $1, :family => family,
|
132
|
+
:via => $2, :flags => $3)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# List the arp entries in system.
|
139
|
+
popen4("arp -an") do |pid, stdin, stdout, stderr|
|
140
|
+
stdin.close
|
141
|
+
count = 0
|
142
|
+
stdout.each do |line|
|
143
|
+
network[:arp] = Mash.new unless network[:arp]
|
144
|
+
if line =~ /\s*(\S+) \((\S+)\) at ([a-fA-F0-9\:]+) \[(\w+)\] stored in bucket/
|
145
|
+
network[:arp][count] = Mash.new unless network[:arp][count]
|
146
|
+
network[:arp][count][:remote_host] = $1
|
147
|
+
network[:arp][count][:remote_ip] = $2
|
148
|
+
network[:arp][count][:remote_mac] = $3.downcase
|
149
|
+
count += 1
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
network["interfaces"] = iface
|
155
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Author:: Joshua Timberman <joshua@opscode.com>
|
3
|
+
# Copyright:: Copyright (c) 2013, Opscode, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,4 +16,10 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require_plugin "
|
19
|
+
require_plugin "#{os}::kernel"
|
20
|
+
|
21
|
+
provides "platform", "platform_version", "platform_family"
|
22
|
+
|
23
|
+
platform kernel[:name]
|
24
|
+
platform_version [kernel[:version], kernel[:release]].join(".")
|
25
|
+
platform_family platform
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
# Copyright:: Copyright (c)
|
2
|
+
# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
4
|
# License:: Apache License, Version 2.0
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -15,5 +15,20 @@
|
|
15
15
|
# See the License for the specific language governing permissions and
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
|
+
require 'date'
|
18
19
|
|
19
|
-
|
20
|
+
provides "uptime", "uptime_seconds"
|
21
|
+
|
22
|
+
# Example output:
|
23
|
+
# $ who -b
|
24
|
+
# . system boot Jul 9 17:51
|
25
|
+
popen4('who -b') do |pid, stdin, stdout, stderr|
|
26
|
+
stdin.close
|
27
|
+
stdout.each do |line|
|
28
|
+
if line =~ /.* boot (.+)/
|
29
|
+
uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
|
30
|
+
uptime self._seconds_to_human(uptime_seconds)
|
31
|
+
break
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/ohai/plugins/cloud.rb
CHANGED
@@ -35,20 +35,27 @@ end
|
|
35
35
|
# Google Compute Engine (gce)
|
36
36
|
#--------------------------------------
|
37
37
|
|
38
|
+
# Is current cloud gce?
|
39
|
+
#
|
40
|
+
# === Return
|
41
|
+
# true:: If gce Hash is defined
|
42
|
+
# false:: Otherwise
|
38
43
|
def on_gce?
|
39
44
|
gce != nil
|
40
45
|
end
|
46
|
+
|
47
|
+
# Fill cloud hash with gce values
|
41
48
|
def get_gce_values
|
42
49
|
cloud[:public_ipv4] = []
|
43
50
|
cloud[:local_ipv4] = []
|
44
51
|
|
45
|
-
public_ips = gce['
|
46
|
-
if interface.has_key?('
|
47
|
-
interface['
|
52
|
+
public_ips = gce['instance']["networkInterfaces"].collect do |interface|
|
53
|
+
if interface.has_key?('accessConfigs')
|
54
|
+
interface['accessConfigs'].collect{|ac| ac['externalIp']}
|
48
55
|
end
|
49
56
|
end.flatten.compact
|
50
57
|
|
51
|
-
private_ips = gce['
|
58
|
+
private_ips = gce['instance']["networkInterfaces"].collect do |interface|
|
52
59
|
interface['ip']
|
53
60
|
end.compact
|
54
61
|
|
@@ -57,7 +64,7 @@ def get_gce_values
|
|
57
64
|
cloud[:public_ipv4] += public_ips
|
58
65
|
cloud[:public_hostname] = nil
|
59
66
|
cloud[:local_ipv4] += private_ips
|
60
|
-
cloud[:local_hostname] = gce['hostname']
|
67
|
+
cloud[:local_hostname] = gce['instance']['hostname']
|
61
68
|
cloud[:provider] = "gce"
|
62
69
|
end
|
63
70
|
|
@@ -244,4 +251,4 @@ end
|
|
244
251
|
if on_azure?
|
245
252
|
create_objects
|
246
253
|
get_azure_values
|
247
|
-
end
|
254
|
+
end
|