ohai 8.17.1 → 8.18.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b474815c9a67658b2190cad18967511a48593d4
4
- data.tar.gz: 268d26318d08819041eb136cb06dff59a15cab5e
3
+ metadata.gz: 1b422d14afdb82f8fe3f07aa0aaa8dd82c30fa06
4
+ data.tar.gz: f99bb4675dcbfca6ffbb28420fbcae88072b55ff
5
5
  SHA512:
6
- metadata.gz: 5a7d729b4dab3483ab3d08ed0e383503a7720ef3bad30b0395c44a1c00419531db582f7d9e9fdb6f6d93ac40049da37fbcbde3fb1bae666b2368187e7aeba980
7
- data.tar.gz: 8dfa9640dcf754831ebf088fa544e81d9de823a1b5dc9040f4d1fd2c34ce358d3dab20f5cfa758d319d7132185a31e2718cee7f34638cac7a41cd90cdf91cdbd
6
+ metadata.gz: 0755c29277022af57f5535a3ced25262ab34e190f8c25d2ed390e0b0324374511ed9ec9c2ca93848fcf2287dfd34d83a849a369ab3271a5e950c9268c8ab430f
7
+ data.tar.gz: 99d5e61254335f5e2274c2ef0f36cf401fa11c0b2ea69cfd3a5514025297e5fdca1d9546670a7364a1c765a434fc57979da777b39c9390391ce766ece3b3d270
@@ -22,6 +22,7 @@ require "ohai/mixin/os"
22
22
  require "ohai/mixin/command"
23
23
  require "ohai/mixin/seconds_to_human"
24
24
  require "ohai/hints"
25
+ require "ohai/util/file_helper"
25
26
 
26
27
  module Ohai
27
28
 
@@ -81,6 +82,7 @@ module Ohai
81
82
  include Ohai::Mixin::OS
82
83
  include Ohai::Mixin::Command
83
84
  include Ohai::Mixin::SecondsToHuman
85
+ include Ohai::Util::FileHelper
84
86
 
85
87
  attr_reader :data
86
88
 
@@ -19,9 +19,8 @@
19
19
 
20
20
  require "ohai/mixin/dmi_decode"
21
21
 
22
- include Ohai::Mixin::DmiDecode
23
-
24
22
  Ohai.plugin(:Virtualization) do
23
+ include Ohai::Mixin::DmiDecode
25
24
  provides "virtualization"
26
25
 
27
26
  collect_data(:freebsd, :openbsd, :netbsd, :dragonflybsd) do
@@ -0,0 +1,98 @@
1
+ #
2
+ # Author:: Nate Walck (<nate.walck@gmail.com>)
3
+ # Copyright:: Copyright (c) 2016-present Facebook, 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
+ Ohai.plugin(:Hardware) do
20
+ provides "hardware"
21
+
22
+ def system_profiler(datatype)
23
+ sp_cmd = "system_profiler #{datatype} -xml"
24
+ # Hardware queries
25
+ sp_std = shell_out(sp_cmd)
26
+ sp_hash = Plist.parse_xml(sp_std.stdout)
27
+ end
28
+
29
+ collect_data(:darwin) do
30
+ unless hardware
31
+ hardware Mash.new
32
+ else
33
+ Ohai::Log.debug("Plugin Darwin Hardware: namespace already exists")
34
+ next
35
+ end
36
+
37
+ begin
38
+ require "plist"
39
+ rescue LoadError => e
40
+ # In case the plist gem isn't present, skip this plugin.
41
+ Ohai::Log.debug("Plugin Hardware: Can't load gem: #{e}. Cannot continue.")
42
+ next
43
+ end
44
+
45
+ hw_hash = system_profiler("SPHardwareDataType")
46
+ hw_hash[0]["_items"][0].delete("_name")
47
+ hardware.merge!(hw_hash[0]["_items"][0])
48
+
49
+ {
50
+ "operating_system" => "sw_vers -productName",
51
+ "operating_system_version" => "sw_vers -productVersion",
52
+ "build_version" => "sw_vers -buildVersion",
53
+ "architecture" => "uname -m",
54
+ }.each do |var, cmd|
55
+ os_info = shell_out(cmd).stdout
56
+ hardware[var] = os_info.strip unless os_info.nil?
57
+ end
58
+
59
+ # Storage queries
60
+ storage = []
61
+ storage_hash = system_profiler("SPStorageDataType")
62
+ drives = storage_hash[0]["_items"]
63
+ drives.each do |drive_entry|
64
+ drive = Mash.new
65
+ drive[:name] = drive_entry["_name"]
66
+ drive[:bsd_name] = drive_entry["bsd_name"]
67
+ drive[:capacity] = drive_entry["size_in_bytes"]
68
+ if drive_entry.has_key?("com.apple.corestorage.pv")
69
+ drive[:drive_type] = drive_entry["com.apple.corestorage.pv"][0]["medium_type"]
70
+ drive[:smart_status] = drive_entry["com.apple.corestorage.pv"][0]["smart_status"]
71
+ drive[:partitions] = drive_entry["com.apple.corestorage.pv"].count
72
+ end
73
+ storage << drive
74
+ end
75
+
76
+ hardware["storage"] = storage
77
+
78
+ # Battery queries
79
+ battery_hash = system_profiler("SPPowerDataType")
80
+ power_entries = battery_hash[0]["_items"]
81
+ battery = Mash.new
82
+ power_entries.each do |entry|
83
+ if entry.value?("spbattery_information")
84
+ charge = entry["sppower_battery_charge_info"]
85
+ health = entry["sppower_battery_health_info"]
86
+ battery[:current_capacity] = charge["sppower_battery_current_capacity"]
87
+ battery[:max_capacity] = charge["sppower_battery_max_capacity"]
88
+ battery[:fully_charged] = charge["sppower_battery_fully_charged"].eql?("TRUE")
89
+ battery[:is_charging] = charge["sppower_battery_is_charging"].eql?("TRUE")
90
+ battery[:charge_cycle_count] = health["sppower_battery_cycle_count"]
91
+ battery[:health] = health["sppower_battery_health"]
92
+ battery[:serial] = entry["sppower_battery_model_info"]["sppower_battery_serial_number"]
93
+ battery[:remaining] = (battery["current_capacity"].to_f / battery["max_capacity"].to_f * 100).to_i
94
+ end
95
+ end
96
+ hardware[:battery] = battery
97
+ end
98
+ end
@@ -1,6 +1,8 @@
1
1
  #
2
2
  # Author:: Pavel Yudin (<pyudin@parallels.com>)
3
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
4
  # Copyright:: Copyright (c) 2015 Pavel Yudin
5
+ # Copyright:: Copyright (c) 2016 Chef Software, Inc.
4
6
  # License:: Apache License, Version 2.0
5
7
  #
6
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -16,13 +18,13 @@
16
18
  # limitations under the License.
17
19
  #
18
20
 
19
- require "ohai/util/file_helper"
20
-
21
- include Ohai::Util::FileHelper
22
-
23
21
  Ohai.plugin(:Virtualization) do
24
22
  provides "virtualization"
25
23
 
24
+ def vboxmanage_exists?
25
+ which("VBoxManage")
26
+ end
27
+
26
28
  def prlctl_exists?
27
29
  which("prlctl")
28
30
  end
@@ -31,18 +33,31 @@ Ohai.plugin(:Virtualization) do
31
33
  which("ioreg")
32
34
  end
33
35
 
36
+ def fusion_exists?
37
+ ::File.exist?("/Applications/VMware\ Fusion.app/")
38
+ end
39
+
34
40
  collect_data(:darwin) do
35
41
  virtualization Mash.new unless virtualization
36
42
  virtualization[:systems] = Mash.new unless virtualization[:systems]
37
43
 
44
+ if vboxmanage_exists?
45
+ virtualization[:system] = "vbox"
46
+ virtualization[:role] = "host"
47
+ virtualization[:systems][:vbox] = "host"
48
+ end
49
+
50
+ if fusion_exists?
51
+ virtualization[:system] = "vmware"
52
+ virtualization[:role] = "host"
53
+ virtualization[:systems][:vmware] = "host"
54
+ end
55
+
38
56
  if prlctl_exists?
39
57
  virtualization[:system] = "parallels"
40
58
  virtualization[:role] = "host"
41
59
  virtualization[:systems][:parallels] = "host"
42
- end
43
-
44
- # Detect Parallels virtual machine from pci devices
45
- if ioreg_exists?
60
+ elsif ioreg_exists?
46
61
  so = shell_out("ioreg -l")
47
62
  if so.stdout =~ /pci1ab8,4000/
48
63
  virtualization[:system] = "parallels"
@@ -35,7 +35,7 @@ Ohai.plugin(:BlockDevice) do
35
35
  File.open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
36
36
  end
37
37
  end
38
- %w{rotational}.each do |check|
38
+ %w{rotational physical_block_size logical_block_size}.each do |check|
39
39
  if File.exists?("/sys/block/#{dir}/queue/#{check}")
40
40
  File.open("/sys/block/#{dir}/queue/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
41
41
  end
@@ -22,6 +22,7 @@ Ohai.plugin(:Memory) do
22
22
  collect_data(:linux) do
23
23
  memory Mash.new
24
24
  memory[:swap] = Mash.new
25
+ memory[:hugepages] = Mash.new
25
26
 
26
27
  File.open("/proc/meminfo").each do |line|
27
28
  case line
@@ -81,6 +82,16 @@ Ohai.plugin(:Memory) do
81
82
  memory[:swap][:total] = "#{$1}#{$2}"
82
83
  when /^SwapFree:\s+(\d+) (.+)$/
83
84
  memory[:swap][:free] = "#{$1}#{$2}"
85
+ when /^HugePages_Total:\s+(\d+)$/
86
+ memory[:hugepages][:total] = "#{$1}"
87
+ when /^HugePages_Free:\s+(\d+)$/
88
+ memory[:hugepages][:free] = "#{$1}"
89
+ when /^HugePages_Rsvd:\s+(\d+)$/
90
+ memory[:hugepages][:reserved] = "#{$1}"
91
+ when /^HugePages_Surp:\s+(\d+)$/
92
+ memory[:hugepages][:surplus] = "#{$1}"
93
+ when /^Hugepagesize:\s+(\d+) (.+)$/
94
+ memory[:hugepage_size] = "#{$1}#{$2}"
84
95
  end
85
96
  end
86
97
  end
@@ -16,10 +16,6 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai/util/file_helper"
20
-
21
- include Ohai::Util::FileHelper
22
-
23
19
  Ohai.plugin(:Sessions) do
24
20
  provides "sessions/by_session", "sessions/by_user"
25
21
 
@@ -16,13 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai/util/file_helper"
20
19
  require "ohai/mixin/dmi_decode"
21
20
 
22
- include Ohai::Util::FileHelper
23
- include Ohai::Mixin::DmiDecode
24
-
25
21
  Ohai.plugin(:Virtualization) do
22
+ include Ohai::Mixin::DmiDecode
26
23
  provides "virtualization"
27
24
 
28
25
  def lxc_version_exists?
@@ -33,7 +33,7 @@ Ohai.plugin(:PHP) do
33
33
  php = Mash.new
34
34
  so.stdout.each_line do |line|
35
35
  case line
36
- when /PHP (\S+).+built: ([^)]+)/
36
+ when /^PHP (\S+)(?:.*built: ([^)]+))?/
37
37
  php[:version] = $1
38
38
  php[:builddate] = $2
39
39
  when /Zend Engine v([^\s]+),/
@@ -0,0 +1,31 @@
1
+ #
2
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
+ # Copyright:: Copyright (c) 2016 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
+
19
+ Ohai.plugin(:Shells) do
20
+ provides "shells"
21
+
22
+ collect_data do
23
+ if ::File.exist?("/etc/shells")
24
+ shells []
25
+ ::File.readlines("/etc/shells").each do |line|
26
+ # remove carriage returns and skip over comments / empty lines
27
+ shells << line.chomp if line[0] == "/"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -19,9 +19,9 @@
19
19
  #
20
20
 
21
21
  require "ohai/mixin/dmi_decode"
22
- include Ohai::Mixin::DmiDecode
23
22
 
24
23
  Ohai.plugin(:Virtualization) do
24
+ include Ohai::Mixin::DmiDecode
25
25
  provides "virtualization"
26
26
 
27
27
  def collect_solaris_guestid
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "8.17.1"
21
+ VERSION = "8.18.0"
22
22
  end
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.email = "adam@chef.io"
14
14
  s.homepage = "https://docs.chef.io/ohai.html"
15
15
 
16
- s.required_ruby_version = ">= 2.0.0"
16
+ s.required_ruby_version = ">= 2.1.0"
17
17
 
18
18
  s.add_dependency "systemu", "~> 2.6.4"
19
19
  s.add_dependency "ffi-yajl", "~> 2.2"
@@ -0,0 +1,116 @@
1
+ #
2
+ # Author:: Nate Walck (<nate.walck@gmail.com>)
3
+ # Copyright:: Copyright (c) 2016-present Facebook, 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
+ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
+ require File.expand_path("#{File.dirname(__FILE__)}/hardware_system_profiler_output.rb")
21
+
22
+ describe Ohai::System, "Darwin hardware plugin", :unix_only do
23
+ let (:plugin) { get_plugin("darwin/hardware") }
24
+ before(:each) do
25
+ allow(plugin).to receive(:collect_os).and_return(:darwin)
26
+ # Make sure it always runs correct commands and mock the data as it calls them
27
+ allow(plugin).to receive(:shell_out).with(
28
+ "system_profiler SPHardwareDataType -xml"
29
+ ).and_return(
30
+ mock_shell_out(0, HardwareSystemProfilerOutput::Hardware, "")
31
+ )
32
+
33
+ allow(plugin).to receive(:shell_out).with(
34
+ "sw_vers -productName"
35
+ ).and_return(
36
+ mock_shell_out(0, "Mac OS X", "")
37
+ )
38
+
39
+ allow(plugin).to receive(:shell_out).with(
40
+ "sw_vers -productVersion"
41
+ ).and_return(
42
+ mock_shell_out(0, "10.12", "")
43
+ )
44
+
45
+ allow(plugin).to receive(:shell_out).with(
46
+ "sw_vers -buildVersion"
47
+ ).and_return(
48
+ mock_shell_out(0, "16A239j", "")
49
+ )
50
+
51
+ allow(plugin).to receive(:shell_out).with(
52
+ "uname -m"
53
+ ).and_return(
54
+ mock_shell_out(0, "x86_64", "")
55
+ )
56
+
57
+ allow(plugin).to receive(:shell_out).with(
58
+ "system_profiler SPStorageDataType -xml"
59
+ ).and_return(
60
+ mock_shell_out(0, HardwareSystemProfilerOutput::Storage, "")
61
+ )
62
+
63
+ allow(plugin).to receive(:shell_out).with(
64
+ "system_profiler SPPowerDataType -xml"
65
+ ).and_return(
66
+ mock_shell_out(0, HardwareSystemProfilerOutput::Power, "")
67
+ )
68
+ end
69
+
70
+ it "parses hardware data correctly" do
71
+ plugin.run
72
+ expect(plugin["hardware"]["SMC_version_system"]).to eq("2.16f68")
73
+ expect(plugin["hardware"]["boot_rom_version"]).to eq("MBP111.0138.B17")
74
+ expect(plugin["hardware"]["cpu_type"]).to eq("Intel Core i7")
75
+ expect(plugin["hardware"]["current_processor_speed"]).to eq("3 GHz")
76
+ expect(plugin["hardware"]["l2_cache_core"]).to eq("256 KB")
77
+ expect(plugin["hardware"]["l3_cache"]).to eq("4 MB")
78
+ expect(plugin["hardware"]["machine_model"]).to eq("MacBookPro11,1")
79
+ expect(plugin["hardware"]["machine_name"]).to eq("MacBook Pro")
80
+ expect(plugin["hardware"]["number_processors"]).to eq(2)
81
+ expect(plugin["hardware"]["packages"]).to eq(1)
82
+ expect(plugin["hardware"]["physical_memory"]).to eq("16 GB")
83
+ expect(plugin["hardware"]["platform_UUID"]).to eq("F1A4AE0F-84A8-45D8-83C7-F3F904464FC5")
84
+ expect(plugin["hardware"]["serial_number"]).to eq("ABCDEFG12345")
85
+ end
86
+
87
+ it "parses sw_vers and uname data correctly" do
88
+ plugin.run
89
+ expect(plugin["hardware"]["operating_system"]).to eq("Mac OS X")
90
+ expect(plugin["hardware"]["operating_system_version"]).to eq("10.12")
91
+ expect(plugin["hardware"]["build_version"]).to eq("16A239j")
92
+ expect(plugin["hardware"]["architecture"]).to eq("x86_64")
93
+ end
94
+
95
+ it "parses storage data correctly" do
96
+ plugin.run
97
+ expect(plugin["hardware"]["storage"][0]["name"]).to eq("Macintosh HD")
98
+ expect(plugin["hardware"]["storage"][0]["bsd_name"]).to eq("disk1")
99
+ expect(plugin["hardware"]["storage"][0]["capacity"]).to eq(249661751296)
100
+ expect(plugin["hardware"]["storage"][0]["drive_type"]).to eq("ssd")
101
+ expect(plugin["hardware"]["storage"][0]["smart_status"]).to eq("Verified")
102
+ expect(plugin["hardware"]["storage"][0]["partitions"]).to eq(1)
103
+ end
104
+
105
+ it "parses storage data correctly" do
106
+ plugin.run
107
+ expect(plugin["hardware"]["battery"]["current_capacity"]).to eq(5841)
108
+ expect(plugin["hardware"]["battery"]["max_capacity"]).to eq(5841)
109
+ expect(plugin["hardware"]["battery"]["fully_charged"]).to eq(true)
110
+ expect(plugin["hardware"]["battery"]["is_charging"]).to eq(false)
111
+ expect(plugin["hardware"]["battery"]["charge_cycle_count"]).to eq(201)
112
+ expect(plugin["hardware"]["battery"]["health"]).to eq("Good")
113
+ expect(plugin["hardware"]["battery"]["serial"]).to eq("D123456789ABCDEFG")
114
+ expect(plugin["hardware"]["battery"]["remaining"]).to eq(100)
115
+ end
116
+ end