ohai 13.3.0 → 13.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ohai/mixin/azure_metadata.rb +53 -0
  3. data/lib/ohai/plugins/aix/uptime.rb +25 -10
  4. data/lib/ohai/plugins/azure.rb +68 -8
  5. data/lib/ohai/plugins/cloud.rb +4 -2
  6. data/lib/ohai/plugins/digital_ocean.rb +3 -3
  7. data/lib/ohai/plugins/dragonflybsd/os.rb +1 -2
  8. data/lib/ohai/plugins/ec2.rb +24 -16
  9. data/lib/ohai/plugins/eucalyptus.rb +4 -4
  10. data/lib/ohai/plugins/freebsd/os.rb +1 -2
  11. data/lib/ohai/plugins/gce.rb +3 -3
  12. data/lib/ohai/plugins/hostname.rb +3 -3
  13. data/lib/ohai/plugins/linux/cpu.rb +33 -2
  14. data/lib/ohai/plugins/linux/filesystem.rb +47 -39
  15. data/lib/ohai/plugins/linux/systemd_paths.rb +3 -4
  16. data/lib/ohai/plugins/linux/virtualization.rb +6 -2
  17. data/lib/ohai/plugins/network.rb +2 -3
  18. data/lib/ohai/plugins/openstack.rb +2 -3
  19. data/lib/ohai/plugins/os.rb +1 -2
  20. data/lib/ohai/plugins/packages.rb +28 -2
  21. data/lib/ohai/plugins/passwd.rb +1 -2
  22. data/lib/ohai/plugins/rackspace.rb +1 -2
  23. data/lib/ohai/plugins/shard.rb +1 -2
  24. data/lib/ohai/plugins/softlayer.rb +1 -2
  25. data/lib/ohai/plugins/solaris2/virtualization.rb +1 -2
  26. data/lib/ohai/plugins/uptime.rb +1 -2
  27. data/lib/ohai/version.rb +1 -1
  28. data/spec/data/plugins/pacman.output +51 -0
  29. data/spec/unit/mixin/azure_metadata_spec.rb +67 -0
  30. data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
  31. data/spec/unit/plugins/aix/uptime_spec.rb +7 -9
  32. data/spec/unit/plugins/azure_spec.rb +81 -0
  33. data/spec/unit/plugins/cloud_spec.rb +37 -5
  34. data/spec/unit/plugins/ec2_spec.rb +34 -12
  35. data/spec/unit/plugins/linux/cpu_spec.rb +123 -87
  36. data/spec/unit/plugins/linux/filesystem_spec.rb +12 -0
  37. data/spec/unit/plugins/linux/virtualization_spec.rb +11 -0
  38. data/spec/unit/plugins/packages_spec.rb +37 -0
  39. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82da0b1a779fb8c56cc2d219a02483ee0cb1b457
4
- data.tar.gz: ca97f22a9aa2765a92d5ff2e5526f9f1a49e8caf
3
+ metadata.gz: 65368dc9cbcaede4fadbcbf469c90fb68a64b4c0
4
+ data.tar.gz: 6c5a528d552e9cf11a81f6b5181ad86f226ff6cc
5
5
  SHA512:
6
- metadata.gz: 76632d8ec3f46c4a926a8478de23248f364dedd4f088a9e93cce359bd5d2c7314955d6858e78be9d3b7df229f7eba8286e1048cc3584195aca62056dbef5e8fd
7
- data.tar.gz: 8f486adaead3001cdb19f51ee4c4c14eb6329664671f1b334f7198654d89387f5759ea1c4f67c31811b98cecb1751e63eb581d5624a6cdf6c975511daa52cdab
6
+ metadata.gz: 8b4557d434f813f5b4320274d48a14791a5bd6111c2163ffbc7934efe68d43a71d64d067196da68ca31895dd0947d0e021b80e936a9216e3a01bd398f6d80208
7
+ data.tar.gz: 848d151c7ff1b30b15971d9d4b7d2e9a34f239f9f256df3f7cc1324b39cb811bf7245f1e15ce39e7ede589f30e3412e4093f27043bd0e4b02da2aa39262ca2dd
@@ -0,0 +1,53 @@
1
+ #
2
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
+ # Copyright:: Copyright 2017 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 "net/http"
19
+
20
+ module Ohai
21
+ module Mixin
22
+ module AzureMetadata
23
+
24
+ AZURE_METADATA_ADDR = "169.254.169.254" unless defined?(AZURE_METADATA_ADDR)
25
+ AZURE_METADATA_URL = "/metadata/instance?api-version=2017-04-02" unless defined?(AZURE_METADATA_URL)
26
+
27
+ # fetch the meta content with a timeout and the required header
28
+ def http_get(uri)
29
+ conn = Net::HTTP.start(AZURE_METADATA_ADDR)
30
+ conn.read_timeout = 6
31
+ conn.get(uri, initheader = { "Metadata" => "true" })
32
+ end
33
+
34
+ def fetch_metadata
35
+ Ohai::Log.debug("Mixin AzureMetadata: Fetching metadata from host #{AZURE_METADATA_ADDR} at #{AZURE_METADATA_URL}")
36
+ response = http_get(AZURE_METADATA_URL)
37
+ if response.code == "200"
38
+ begin
39
+ data = StringIO.new(response.body)
40
+ parser = FFI_Yajl::Parser.new
41
+ parser.parse(data)
42
+ rescue FFI_Yajl::ParseError
43
+ Ohai::Log.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON")
44
+ nil
45
+ end
46
+ else
47
+ Ohai::Log.warn("Mixin AzureMetadata: Received resonse code #{response.code} requesting metadata")
48
+ nil
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -22,16 +22,31 @@ Ohai.plugin(:Uptime) do
22
22
 
23
23
  collect_data(:aix) do
24
24
  require "date"
25
- # Example output:
26
- # $ who -b
27
- # . system boot Jul 9 17:51
28
- so = shell_out("who -b")
29
- so.stdout.lines.each do |line|
30
- if line =~ /.* boot (.+)/
31
- uptime_seconds Time.now.to_i - DateTime.parse($1 + " #{Time.now.zone}").strftime("%s").to_i
32
- uptime seconds_to_human(uptime_seconds)
33
- break
34
- end
25
+ # below we're going to assume that PID 1 is init (this is true 99.99999% of the time)
26
+ # output will look like this
27
+ # 1148-20:54:50
28
+ # This reads as 1148 days, 20 hours, 54 minutes, 50 seconds since the process was started (elapsed)
29
+ # who -b does not return the YEAR, so we need something more concrete
30
+ so = shell_out("LC_ALL=POSIX ps -o etime= -p 1").stdout
31
+
32
+ # Here we'll check our shell_out for a dash, which indicates there is a # of days involved
33
+ # We'll chunk off the days, hours (where applicable), minutes, seconds into seperate vars
34
+ # We also need to do this because ps -o etime= will not display days if the machine has been up for less than 24 hours
35
+ # If the machine has been up for less than one hour, the shell_out will not output hours hence our else
36
+ # see here: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds4/ps.htm#ps__row-d3e109655
37
+ d = nil
38
+ h = nil
39
+ case so
40
+ when /^\d+-\d/
41
+ (d, h, m, s) = so.split(/[-:]/)
42
+ when /^\d+:\d+:\d/
43
+ (h, m, s) = so.split(/[:]/)
44
+ else
45
+ (m, s) = so.split(/[:]/)
35
46
  end
47
+ elapsed_seconds = ((d.to_i * 86400) + (h.to_i * 3600) + (m.to_i * 60) + s.to_i)
48
+
49
+ uptime_seconds Time.now.to_i - elapsed_seconds
50
+ uptime seconds_to_human(elapsed_seconds)
36
51
  end
37
52
  end
@@ -1,4 +1,4 @@
1
- # Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
1
+ # Copyright:: Copyright 2013-2017 Chef Software, Inc.
2
2
  # License:: Apache License, Version 2.0
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,23 +15,31 @@
15
15
  #
16
16
 
17
17
  Ohai.plugin(:Azure) do
18
+ require "ohai/mixin/azure_metadata"
19
+ require "ohai/mixin/http_helper"
20
+
21
+ include Ohai::Mixin::AzureMetadata
22
+ include Ohai::Mixin::HttpHelper
23
+
18
24
  provides "azure"
19
25
 
20
26
  collect_data do
21
- # The azure hints are populated by the knife plugin for Azure.
22
- # The project is located at https://github.com/chef/knife-azure
27
+ # Before we had the metadata endpoint we relied exclusively on
28
+ # the knife-azure plugin populating data to the hint file.
23
29
  # Please see the lib/chef/knife/azure_server_create.rb file in that
24
30
  # project for details
25
31
  azure_metadata_from_hints = hint?("azure")
26
32
  if azure_metadata_from_hints
27
- Ohai::Log.debug("Plugin Azure: azure_metadata_from_hints is present.")
33
+ Ohai::Log.debug("Plugin Azure: Azure hint is present. Parsing any hint data.")
28
34
  azure Mash.new
29
35
  azure_metadata_from_hints.each { |k, v| azure[k] = v }
36
+ azure["metadata"] = parse_metadata
30
37
  elsif has_waagent? || has_dhcp_option_245?
31
- Ohai::Log.debug("Plugin Azure: No hints present, but system appears to be on azure.")
38
+ Ohai::Log.debug("Plugin Azure: No hints present, but system appears to be on Azure.")
32
39
  azure Mash.new
40
+ azure["metadata"] = parse_metadata
33
41
  else
34
- Ohai::Log.debug("Plugin Azure: No hints present for azure and doesn't appear to be azure.")
42
+ Ohai::Log.debug("Plugin Azure: No hints present and doesn't appear to be on Azure.")
35
43
  false
36
44
  end
37
45
  end
@@ -40,7 +48,7 @@ Ohai.plugin(:Azure) do
40
48
  # http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/
41
49
  def has_waagent?
42
50
  if File.exist?("/usr/sbin/waagent") || Dir.exist?('C:\WindowsAzure')
43
- Ohai::Log.debug("Plugin Azure: Found waagent used by MS Azure.")
51
+ Ohai::Log.debug("Plugin Azure: Found waagent used by Azure.")
44
52
  true
45
53
  end
46
54
  end
@@ -50,7 +58,7 @@ Ohai.plugin(:Azure) do
50
58
  if File.exist?("/var/lib/dhcp/dhclient.eth0.leases")
51
59
  File.open("/var/lib/dhcp/dhclient.eth0.leases").each do |line|
52
60
  if line =~ /unknown-245/
53
- Ohai::Log.debug("Plugin Azure: Found unknown-245 DHCP option used by MS Azure.")
61
+ Ohai::Log.debug("Plugin Azure: Found unknown-245 DHCP option used by Azure.")
54
62
  has_245 = true
55
63
  break
56
64
  end
@@ -59,4 +67,56 @@ Ohai.plugin(:Azure) do
59
67
  has_245
60
68
  end
61
69
 
70
+ # create the basic structure we'll store our data in
71
+ def initialize_metadata_mash
72
+ metadata = Mash.new
73
+ metadata["compute"] = Mash.new
74
+ metadata["network"] = Mash.new
75
+ metadata["network"]["interfaces"] = Mash.new
76
+ %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
77
+ metadata["network"][type] = []
78
+ end
79
+ metadata
80
+ end
81
+
82
+ def fetch_ip_data(data, type, field)
83
+ ips = []
84
+
85
+ data[type]["ipAddress"].each do |val|
86
+ ips << val[field] unless val[field].empty?
87
+ end
88
+ ips
89
+ end
90
+
91
+ def parse_metadata
92
+ return nil unless can_socket_connect?(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80)
93
+
94
+ endpoint_data = fetch_metadata
95
+ return nil if endpoint_data.nil?
96
+ metadata = initialize_metadata_mash
97
+
98
+ # blindly add everything in compute to our data structure
99
+ endpoint_data["compute"].each do |k, v|
100
+ metadata["compute"][k] = v
101
+ end
102
+
103
+ # parse out per interface interface IP data
104
+ endpoint_data["network"]["interface"].each do |int|
105
+ metadata["network"]["interfaces"][int["macAddress"]] = Mash.new
106
+ metadata["network"]["interfaces"][int["macAddress"]]["mac"] = int["macAddress"]
107
+ metadata["network"]["interfaces"][int["macAddress"]]["public_ipv6"] = fetch_ip_data(int, "ipv6", "publicIpAddress")
108
+ metadata["network"]["interfaces"][int["macAddress"]]["public_ipv4"] = fetch_ip_data(int, "ipv4", "publicIpAddress")
109
+ metadata["network"]["interfaces"][int["macAddress"]]["local_ipv6"] = fetch_ip_data(int, "ipv6", "privateIpAddress")
110
+ metadata["network"]["interfaces"][int["macAddress"]]["local_ipv4"] = fetch_ip_data(int, "ipv4", "privateIpAddress")
111
+ end
112
+
113
+ # aggregate the total IP data
114
+ %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type|
115
+ metadata["network"]["interfaces"].each_value do |val|
116
+ metadata["network"][type].concat val[type] unless val[type].empty?
117
+ end
118
+ end
119
+
120
+ metadata
121
+ end
62
122
  end
@@ -265,8 +265,10 @@ Ohai.plugin(:Cloud) do
265
265
 
266
266
  # Fill cloud hash with azure values
267
267
  def get_azure_values
268
- @cloud_attr_obj.add_ipv4_addr(azure["public_ip"], :public)
269
- @cloud_attr_obj.add_ipv4_addr(azure["private_ip"], :private)
268
+ azure["metadata"]["network"]["public_ipv4"].each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) }
269
+ azure["metadata"]["network"]["public_ipv6"].each { |ipaddr| @cloud_attr_obj.add_ipv6_addr(ipaddr, :public) }
270
+ azure["metadata"]["network"]["local_ipv4"].each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) }
271
+ azure["metadata"]["network"]["local_ipv6"].each { |ipaddr| @cloud_attr_obj.add_ipv6_addr(ipaddr, :private) }
270
272
  @cloud_attr_obj.public_hostname = azure["public_fqdn"]
271
273
  @cloud_attr_obj.provider = "azure"
272
274
  end
@@ -15,10 +15,10 @@
15
15
  # See the License for the specific language governing permissions and
16
16
  # limitations under the License.
17
17
 
18
- require "ohai/mixin/do_metadata"
19
- require "ohai/mixin/http_helper"
20
-
21
18
  Ohai.plugin(:DigitalOcean) do
19
+ require "ohai/mixin/do_metadata"
20
+ require "ohai/mixin/http_helper"
21
+
22
22
  include Ohai::Mixin::DOMetadata
23
23
  include Ohai::Mixin::HttpHelper
24
24
 
@@ -18,9 +18,8 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require "ohai/mixin/os"
22
-
23
21
  Ohai.plugin(:OS) do
22
+ require "ohai/mixin/os"
24
23
  provides "os", "os_version"
25
24
 
26
25
  collect_data(:dragonflybsd) do
@@ -24,21 +24,20 @@
24
24
  # 3. DMI data mentions amazon. This catches HVM instances in a VPC
25
25
  # 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances
26
26
 
27
- require "ohai/mixin/ec2_metadata"
28
- require "ohai/mixin/http_helper"
29
- require "base64"
30
-
31
27
  Ohai.plugin(:EC2) do
28
+ require "ohai/mixin/ec2_metadata"
29
+ require "ohai/mixin/http_helper"
30
+ require "base64"
31
+
32
32
  include Ohai::Mixin::Ec2Metadata
33
33
  include Ohai::Mixin::HttpHelper
34
34
 
35
35
  provides "ec2"
36
-
37
36
  depends "dmi"
38
- depends "kernel"
39
37
 
40
38
  # look for amazon string in dmi bios data
41
39
  # this gets us detection of HVM instances that are within a VPC
40
+ # @return [Boolean] do we have Amazon DMI data?
42
41
  def has_ec2_dmi?
43
42
  # detect a version of '4.2.amazon'
44
43
  if get_attribute(:dmi, :bios, :all_records, 0, :Version) =~ /amazon/
@@ -51,7 +50,9 @@ Ohai.plugin(:EC2) do
51
50
  end
52
51
 
53
52
  # looks for a xen UUID that starts with ec2
54
- # this gets us detection of Linux HVM and Paravirt hosts
53
+ # uses the sys tree on Linux and a WMI query on windows
54
+ # this gets us detection of HVM and Paravirt hosts
55
+ # @return [Boolean] do we have a Xen UUID or not?
55
56
  def has_ec2_xen_uuid?
56
57
  if ::File.exist?("/sys/hypervisor/uuid")
57
58
  if ::File.read("/sys/hypervisor/uuid") =~ /^ec2/
@@ -63,24 +64,31 @@ Ohai.plugin(:EC2) do
63
64
  false
64
65
  end
65
66
 
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
- true
67
+ # looks at the identifying number WMI value to see if it starts with ec2.
68
+ # this is actually the same value we're looking at in has_ec2_xen_uuid? on
69
+ # linux hosts
70
+ # @return [Boolean] do we have a Xen Identifying Number or not?
71
+ def has_ec2_identifying_number?
72
+ if RUBY_PLATFORM =~ /mswin|mingw32|windows/
73
+ # require "wmi-lite/wmi"
74
+ wmi = WmiLite::Wmi.new
75
+ if wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"] =~ /^ec2/
76
+ Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == true")
77
+ return true
78
+ end
73
79
  else
74
- Ohai::Log.debug("Plugin EC2: has_amazon_org? == false")
80
+ Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == false")
75
81
  false
76
82
  end
77
83
  end
78
84
 
85
+ # a single check that combines all the various detection methods for EC2
86
+ # @return [Boolean] Does the system appear to be on EC2
79
87
  def looks_like_ec2?
80
88
  return true if hint?("ec2")
81
89
 
82
90
  # Even if it looks like EC2 try to connect first
83
- if has_ec2_xen_uuid? || has_ec2_dmi? || has_amazon_org?
91
+ if has_ec2_xen_uuid? || has_ec2_dmi? || has_ec2_identifying_number?
84
92
  return true if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
85
93
  end
86
94
  end
@@ -17,11 +17,11 @@
17
17
  # See the License for the specific language governing permissions and
18
18
  # limitations under the License.
19
19
 
20
- # eucalyptus metadata service is compatible with the ec2 service calls
21
- require "ohai/mixin/ec2_metadata"
22
- require "ohai/mixin/http_helper"
23
-
24
20
  Ohai.plugin(:Eucalyptus) do
21
+ # eucalyptus metadata service is compatible with the ec2 service calls
22
+ require "ohai/mixin/ec2_metadata"
23
+ require "ohai/mixin/http_helper"
24
+
25
25
  include Ohai::Mixin::Ec2Metadata
26
26
  include Ohai::Mixin::HttpHelper
27
27
 
@@ -18,10 +18,9 @@
18
18
  # limitations under the License.
19
19
  #
20
20
 
21
- require "ohai/mixin/os"
22
-
23
21
  Ohai.plugin(:OS) do
24
22
  provides "os", "os_version"
23
+ require "ohai/mixin/os"
25
24
 
26
25
  collect_data(:freebsd) do
27
26
  os collect_os
@@ -14,10 +14,10 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
- require "ohai/mixin/gce_metadata"
18
- require "ohai/mixin/http_helper"
19
-
20
17
  Ohai.plugin(:GCE) do
18
+ require "ohai/mixin/gce_metadata"
19
+ require "ohai/mixin/http_helper"
20
+
21
21
  include Ohai::Mixin::GCEMetadata
22
22
  include Ohai::Mixin::HttpHelper
23
23
 
@@ -25,10 +25,10 @@
25
25
  # limitations under the License.
26
26
  #
27
27
 
28
- require "socket"
29
- require "ipaddr"
30
-
31
28
  Ohai.plugin(:Hostname) do
29
+ require "socket"
30
+ require "ipaddr"
31
+
32
32
  provides "domain", "hostname", "fqdn", "machinename"
33
33
 
34
34
  # hostname : short hostname
@@ -82,8 +82,39 @@ Ohai.plugin(:CPU) do
82
82
  end
83
83
 
84
84
  cpu cpuinfo
85
+
85
86
  cpu[:total] = cpu_number
86
- cpu[:real] = real_cpu.keys.length
87
- cpu[:cores] = real_cpu.keys.length * cpu["0"]["cores"].to_i
87
+
88
+ # use data we collected unless cpuinfo is lacking core information
89
+ # which is the case on older linux distros
90
+ if !real_cpu.empty? && cpu["0"]["cores"]
91
+ cpu[:real] = real_cpu.keys.length
92
+ cpu[:cores] = real_cpu.keys.length * cpu["0"]["cores"].to_i
93
+ else
94
+ begin
95
+ Ohai::Log.debug("Plugin CPU: Falling back to aggregate data from lscpu as real cpu & core data is missing in /proc/cpuinfo")
96
+ so = shell_out("lscpu")
97
+ if so.exitstatus == 0
98
+ lscpu_data = Mash.new
99
+ so.stdout.each_line do |line|
100
+ case line
101
+ when /^Thread\(s\) per core:\s(.+)/ # http://rubular.com/r/lOw2pRrw1q
102
+ lscpu_data[:threads] = $1.to_i
103
+ when /^Core\(s\) per socket:\s(.+)/ # http://rubular.com/r/lOw2pRrw1q
104
+ lscpu_data[:cores] = $1.to_i
105
+ when /^Socket\(s\):\s(.+)/ # http://rubular.com/r/DIzmPtJFvK
106
+ lscpu_data[:sockets] = $1.to_i
107
+ end
108
+ end
109
+ cpu[:total] = lscpu_data[:sockets] * lscpu_data[:cores] * lscpu_data[:threads]
110
+ cpu[:real] = lscpu_data[:sockets]
111
+ cpu[:cores] = lscpu_data[:sockets] * lscpu_data[:cores]
112
+ else
113
+ Ohai::Log.debug("Plugin CPU: Error executing lscpu. CPU data may not be available.")
114
+ end
115
+ rescue Ohai::Exceptions::Exec # util-linux isn't installed most likely
116
+ Ohai::Log.debug("Plugin CPU: Error executing lscpu. util-linux may not be installed.")
117
+ end
118
+ end
88
119
  end
89
120
  end
@@ -95,52 +95,60 @@ Ohai.plugin(:Filesystem) do
95
95
  fs = Mash.new
96
96
 
97
97
  # Grab filesystem data from df
98
- so = shell_out("df -P")
99
- so.stdout.each_line do |line|
100
- case line
101
- when /^Filesystem\s+1024-blocks/
102
- next
103
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
104
- key = "#{$1},#{$6}"
105
- fs[key] = Mash.new
106
- fs[key][:device] = $1
107
- fs[key][:kb_size] = $2
108
- fs[key][:kb_used] = $3
109
- fs[key][:kb_available] = $4
110
- fs[key][:percent_used] = $5
111
- fs[key][:mount] = $6
98
+ begin
99
+ so = shell_out("df -P")
100
+ so.stdout.each_line do |line|
101
+ case line
102
+ when /^Filesystem\s+1024-blocks/
103
+ next
104
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
105
+ key = "#{$1},#{$6}"
106
+ fs[key] = Mash.new
107
+ fs[key][:device] = $1
108
+ fs[key][:kb_size] = $2
109
+ fs[key][:kb_used] = $3
110
+ fs[key][:kb_available] = $4
111
+ fs[key][:percent_used] = $5
112
+ fs[key][:mount] = $6
113
+ end
112
114
  end
113
- end
114
115
 
115
- # Grab filesystem inode data from df
116
- so = shell_out("df -iP")
117
- so.stdout.each_line do |line|
118
- case line
119
- when /^Filesystem\s+Inodes/
120
- next
121
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
122
- key = "#{$1},#{$6}"
123
- fs[key] ||= Mash.new
124
- fs[key][:device] = $1
125
- fs[key][:total_inodes] = $2
126
- fs[key][:inodes_used] = $3
127
- fs[key][:inodes_available] = $4
128
- fs[key][:inodes_percent_used] = $5
129
- fs[key][:mount] = $6
116
+ # Grab filesystem inode data from df
117
+ so = shell_out("df -iP")
118
+ so.stdout.each_line do |line|
119
+ case line
120
+ when /^Filesystem\s+Inodes/
121
+ next
122
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
123
+ key = "#{$1},#{$6}"
124
+ fs[key] ||= Mash.new
125
+ fs[key][:device] = $1
126
+ fs[key][:total_inodes] = $2
127
+ fs[key][:inodes_used] = $3
128
+ fs[key][:inodes_available] = $4
129
+ fs[key][:inodes_percent_used] = $5
130
+ fs[key][:mount] = $6
131
+ end
130
132
  end
133
+ rescue Ohai::Exceptions::Exec
134
+ Ohai::Log.warn("Plugin Filesystem: df binary is not available. Some data will not be available.")
131
135
  end
132
136
 
133
137
  # Grab mount information from /bin/mount
134
- so = shell_out("mount")
135
- so.stdout.each_line do |line|
136
- if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
137
- key = "#{$1},#{$2}"
138
- fs[key] = Mash.new unless fs.has_key?(key)
139
- fs[key][:device] = $1
140
- fs[key][:mount] = $2
141
- fs[key][:fs_type] = $3
142
- fs[key][:mount_options] = $4.split(",")
138
+ begin
139
+ so = shell_out("mount")
140
+ so.stdout.each_line do |line|
141
+ if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/
142
+ key = "#{$1},#{$2}"
143
+ fs[key] = Mash.new unless fs.has_key?(key)
144
+ fs[key][:device] = $1
145
+ fs[key][:mount] = $2
146
+ fs[key][:fs_type] = $3
147
+ fs[key][:mount_options] = $4.split(",")
148
+ end
143
149
  end
150
+ rescue Ohai::Exceptions::Exec
151
+ Ohai::Log.warn("Plugin Filesystem: mount binary is not available. Some data will not be available.")
144
152
  end
145
153
 
146
154
  # We used to try to decide if we wanted to run lsblk or blkid