ohai 16.5.6 → 16.10.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +7 -8
  3. data/bin/ohai +1 -0
  4. data/lib/ohai.rb +1 -0
  5. data/lib/ohai/application.rb +40 -0
  6. data/lib/ohai/common/dmi.rb +8 -3
  7. data/lib/ohai/config.rb +1 -0
  8. data/lib/ohai/dsl.rb +1 -0
  9. data/lib/ohai/dsl/plugin.rb +9 -1
  10. data/lib/ohai/dsl/plugin/versionvii.rb +28 -17
  11. data/lib/ohai/exception.rb +1 -0
  12. data/lib/ohai/hints.rb +1 -0
  13. data/lib/ohai/log.rb +1 -0
  14. data/lib/ohai/mash.rb +1 -0
  15. data/lib/ohai/mixin/azure_metadata.rb +4 -3
  16. data/lib/ohai/mixin/chef_utils_wiring.rb +14 -1
  17. data/lib/ohai/mixin/command.rb +1 -0
  18. data/lib/ohai/mixin/constant_helper.rb +1 -0
  19. data/lib/ohai/mixin/dmi_decode.rb +1 -0
  20. data/lib/ohai/mixin/do_metadata.rb +3 -2
  21. data/lib/ohai/mixin/ec2_metadata.rb +37 -11
  22. data/lib/ohai/mixin/gce_metadata.rb +4 -3
  23. data/lib/ohai/mixin/http_helper.rb +1 -0
  24. data/lib/ohai/mixin/network_helper.rb +1 -0
  25. data/lib/ohai/mixin/os.rb +67 -1
  26. data/lib/ohai/mixin/scaleway_metadata.rb +3 -2
  27. data/lib/ohai/mixin/seconds_to_human.rb +1 -0
  28. data/lib/ohai/mixin/shell_out.rb +1 -0
  29. data/lib/ohai/mixin/softlayer_metadata.rb +2 -1
  30. data/lib/ohai/mixin/string.rb +1 -0
  31. data/lib/ohai/mixin/train_helpers.rb +36 -0
  32. data/lib/ohai/mixin/which.rb +1 -0
  33. data/lib/ohai/plugin_config.rb +1 -0
  34. data/lib/ohai/plugins/aix/kernel.rb +7 -4
  35. data/lib/ohai/plugins/aix/memory.rb +4 -3
  36. data/lib/ohai/plugins/aix/network.rb +51 -58
  37. data/lib/ohai/plugins/aix/platform.rb +3 -2
  38. data/lib/ohai/plugins/aix/uptime.rb +3 -2
  39. data/lib/ohai/plugins/aix/virtualization.rb +6 -6
  40. data/lib/ohai/plugins/azure.rb +25 -4
  41. data/lib/ohai/plugins/bsd/virtualization.rb +3 -2
  42. data/lib/ohai/plugins/c.rb +4 -3
  43. data/lib/ohai/plugins/chef.rb +2 -1
  44. data/lib/ohai/plugins/cloud.rb +2 -1
  45. data/lib/ohai/plugins/command.rb +1 -0
  46. data/lib/ohai/plugins/cpu.rb +31 -32
  47. data/lib/ohai/plugins/darwin/hardware.rb +1 -0
  48. data/lib/ohai/plugins/darwin/memory.rb +2 -3
  49. data/lib/ohai/plugins/darwin/network.rb +8 -9
  50. data/lib/ohai/plugins/darwin/platform.rb +1 -0
  51. data/lib/ohai/plugins/darwin/virtualization.rb +2 -1
  52. data/lib/ohai/plugins/digital_ocean.rb +3 -1
  53. data/lib/ohai/plugins/dmi.rb +6 -5
  54. data/lib/ohai/plugins/docker.rb +2 -1
  55. data/lib/ohai/plugins/dragonflybsd/memory.rb +9 -8
  56. data/lib/ohai/plugins/dragonflybsd/network.rb +1 -0
  57. data/lib/ohai/plugins/dragonflybsd/platform.rb +3 -2
  58. data/lib/ohai/plugins/ec2.rb +17 -7
  59. data/lib/ohai/plugins/elixir.rb +1 -1
  60. data/lib/ohai/plugins/erlang.rb +1 -0
  61. data/lib/ohai/plugins/eucalyptus.rb +4 -1
  62. data/lib/ohai/plugins/filesystem.rb +4 -4
  63. data/lib/ohai/plugins/fips.rb +1 -0
  64. data/lib/ohai/plugins/freebsd/memory.rb +9 -8
  65. data/lib/ohai/plugins/freebsd/network.rb +1 -0
  66. data/lib/ohai/plugins/freebsd/platform.rb +3 -2
  67. data/lib/ohai/plugins/gce.rb +3 -2
  68. data/lib/ohai/plugins/go.rb +1 -1
  69. data/lib/ohai/plugins/groovy.rb +1 -1
  70. data/lib/ohai/plugins/grub2.rb +40 -0
  71. data/lib/ohai/plugins/haskell.rb +1 -0
  72. data/lib/ohai/plugins/hostname.rb +2 -2
  73. data/lib/ohai/plugins/init_package.rb +2 -1
  74. data/lib/ohai/plugins/java.rb +1 -0
  75. data/lib/ohai/plugins/kernel.rb +14 -11
  76. data/lib/ohai/plugins/keys.rb +1 -0
  77. data/lib/ohai/plugins/languages.rb +1 -0
  78. data/lib/ohai/plugins/libvirt.rb +4 -3
  79. data/lib/ohai/plugins/linode.rb +22 -14
  80. data/lib/ohai/plugins/linux/block_device.rb +9 -8
  81. data/lib/ohai/plugins/linux/hostnamectl.rb +3 -2
  82. data/lib/ohai/plugins/linux/interrupts.rb +4 -3
  83. data/lib/ohai/plugins/linux/ipc.rb +1 -0
  84. data/lib/ohai/plugins/linux/lsb.rb +7 -20
  85. data/lib/ohai/plugins/linux/lspci.rb +1 -1
  86. data/lib/ohai/plugins/linux/machineid.rb +5 -4
  87. data/lib/ohai/plugins/linux/mdadm.rb +3 -2
  88. data/lib/ohai/plugins/linux/memory.rb +38 -37
  89. data/lib/ohai/plugins/linux/network.rb +33 -7
  90. data/lib/ohai/plugins/linux/platform.rb +32 -31
  91. data/lib/ohai/plugins/linux/selinux.rb +1 -0
  92. data/lib/ohai/plugins/linux/sessions.rb +1 -0
  93. data/lib/ohai/plugins/linux/sysctl.rb +1 -0
  94. data/lib/ohai/plugins/linux/systemd_paths.rb +1 -0
  95. data/lib/ohai/plugins/linux/virtualization.rb +24 -23
  96. data/lib/ohai/plugins/lua.rb +1 -1
  97. data/lib/ohai/plugins/mono.rb +1 -1
  98. data/lib/ohai/plugins/netbsd/memory.rb +1 -0
  99. data/lib/ohai/plugins/netbsd/network.rb +1 -0
  100. data/lib/ohai/plugins/netbsd/platform.rb +3 -2
  101. data/lib/ohai/plugins/network.rb +2 -1
  102. data/lib/ohai/plugins/nodejs.rb +1 -1
  103. data/lib/ohai/plugins/ohai.rb +1 -0
  104. data/lib/ohai/plugins/ohai_time.rb +2 -1
  105. data/lib/ohai/plugins/openbsd/memory.rb +1 -0
  106. data/lib/ohai/plugins/openbsd/network.rb +1 -0
  107. data/lib/ohai/plugins/openbsd/platform.rb +3 -2
  108. data/lib/ohai/plugins/openstack.rb +1 -0
  109. data/lib/ohai/plugins/os.rb +6 -1
  110. data/lib/ohai/plugins/packages.rb +2 -1
  111. data/lib/ohai/plugins/passwd.rb +58 -1
  112. data/lib/ohai/plugins/perl.rb +1 -1
  113. data/lib/ohai/plugins/php.rb +1 -1
  114. data/lib/ohai/plugins/platform.rb +1 -0
  115. data/lib/ohai/plugins/powershell.rb +1 -1
  116. data/lib/ohai/plugins/ps.rb +1 -0
  117. data/lib/ohai/plugins/python.rb +1 -1
  118. data/lib/ohai/plugins/rackspace.rb +6 -5
  119. data/lib/ohai/plugins/root_group.rb +1 -0
  120. data/lib/ohai/plugins/ruby.rb +3 -2
  121. data/lib/ohai/plugins/rust.rb +1 -1
  122. data/lib/ohai/plugins/scala.rb +1 -0
  123. data/lib/ohai/plugins/scaleway.rb +3 -2
  124. data/lib/ohai/plugins/scsi.rb +1 -1
  125. data/lib/ohai/plugins/shard.rb +1 -1
  126. data/lib/ohai/plugins/shells.rb +3 -2
  127. data/lib/ohai/plugins/softlayer.rb +1 -0
  128. data/lib/ohai/plugins/solaris2/dmi.rb +2 -1
  129. data/lib/ohai/plugins/solaris2/memory.rb +1 -0
  130. data/lib/ohai/plugins/solaris2/network.rb +2 -1
  131. data/lib/ohai/plugins/solaris2/platform.rb +8 -14
  132. data/lib/ohai/plugins/solaris2/virtualization.rb +4 -4
  133. data/lib/ohai/plugins/ssh_host_key.rb +13 -12
  134. data/lib/ohai/plugins/sysconf.rb +1 -0
  135. data/lib/ohai/plugins/timezone.rb +1 -0
  136. data/lib/ohai/plugins/train.rb +35 -0
  137. data/lib/ohai/plugins/uptime.rb +2 -1
  138. data/lib/ohai/plugins/virtualbox.rb +2 -1
  139. data/lib/ohai/plugins/vmware.rb +3 -3
  140. data/lib/ohai/plugins/windows/dmi.rb +1 -0
  141. data/lib/ohai/plugins/windows/drivers.rb +1 -0
  142. data/lib/ohai/plugins/windows/memory.rb +1 -0
  143. data/lib/ohai/plugins/windows/network.rb +2 -1
  144. data/lib/ohai/plugins/windows/platform.rb +1 -0
  145. data/lib/ohai/plugins/windows/system_enclosure.rb +1 -0
  146. data/lib/ohai/plugins/windows/virtualization.rb +1 -0
  147. data/lib/ohai/plugins/zpools.rb +5 -3
  148. data/lib/ohai/provides_map.rb +1 -0
  149. data/lib/ohai/runner.rb +7 -4
  150. data/lib/ohai/system.rb +33 -4
  151. data/lib/ohai/train_transport.rb +29 -0
  152. data/lib/ohai/util/file_helper.rb +1 -0
  153. data/lib/ohai/util/ip_helper.rb +2 -1
  154. data/lib/ohai/util/win32.rb +1 -0
  155. data/lib/ohai/version.rb +2 -1
  156. data/ohai.gemspec +3 -1
  157. metadata +22 -5
  158. data/lib/ohai/plugins/joyent.rb +0 -77
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Cookbook Name:: apache2
3
4
  # Recipe:: default
@@ -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.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Benjamin Black (<bb@chef.io>)
3
4
  # Copyright:: Copyright (c) Chef Software Inc.
@@ -16,11 +17,11 @@
16
17
  # limitations under the License.
17
18
  #
18
19
 
19
- # Note: This plugin requires libvirt-bin/libvirt-dev as well as the ruby-libvirt
20
+ # NOTE: This plugin requires libvirt-bin/libvirt-dev as well as the ruby-libvirt
20
21
  # gem to be installed before it will properly parse data
21
22
 
22
23
  Ohai.plugin(:Libvirt) do
23
- %w{ uri capabilities nodeinfo domains networks storage }.each do |info|
24
+ %w{uri capabilities nodeinfo domains networks storage}.each do |info|
24
25
  provides "libvirt/#{info}"
25
26
  depends "virtualization"
26
27
  end
@@ -88,7 +89,7 @@ Ohai.plugin(:Libvirt) do
88
89
  storage_data
89
90
  end
90
91
 
91
- collect_data do
92
+ collect_data(:linux) do
92
93
  if virtualization[:role].eql?("host")
93
94
  load_libvirt
94
95
  begin
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Aaron Kalin (<akalin@martinisoftware.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -17,31 +18,38 @@
17
18
  Ohai.plugin(:Linode) do
18
19
  provides "linode"
19
20
 
20
- depends "kernel"
21
+ depends "domain"
21
22
  depends "network/interfaces"
22
23
 
23
- # Checks for matching linode kernel name
24
+ # Checks to see if the node is in the members.linode.com domain
24
25
  #
25
- # Returns true or false
26
- def has_linode_kernel?
27
- if ( kernel_data = kernel )
28
- kernel_data[:release].split("-").last.include?("linode")
29
- end
26
+ # @return [Boolean]
27
+ #
28
+ def has_linode_domain?
29
+ domain&.include?("linode")
30
+ end
31
+
32
+ # Checks for linode mirrors in the apt sources.list file
33
+ #
34
+ # @return [Boolean]
35
+ #
36
+ def has_linode_apt_repos?
37
+ file_exist?("/etc/apt/sources.list") && file_read("/etc/apt/sources.list").include?("linode")
30
38
  end
31
39
 
32
40
  # Identifies the linode cloud by preferring the hint, then
33
41
  #
34
- # Returns true or false
42
+ # @return [Boolean]
43
+ #
35
44
  def looks_like_linode?
36
- hint?("linode") || has_linode_kernel?
45
+ hint?("linode") || has_linode_domain? || has_linode_apt_repos?
37
46
  end
38
47
 
39
- # Names linode ip address
48
+ # Alters linode mash with new interface based on name parameter
40
49
  #
41
- # name - symbol of ohai name (e.g. :public_ip)
42
- # eth - Interface name (e.g. :eth0)
50
+ # @param [Symbol] name Ohai name (e.g. :public_ip)
51
+ # @param [Symbol] eth Interface name (e.g. :eth0)
43
52
  #
44
- # Alters linode mash with new interface based on name parameter
45
53
  def get_ip_address(name, eth)
46
54
  if ( eth_iface = network[:interfaces][eth] )
47
55
  eth_iface[:addresses].each do |key, info|
@@ -50,7 +58,7 @@ Ohai.plugin(:Linode) do
50
58
  end
51
59
  end
52
60
 
53
- collect_data do
61
+ collect_data(:linux) do
54
62
  # Setup linode mash if it is a linode system
55
63
  if looks_like_linode?
56
64
  logger.trace("Plugin Linode: looks_like_linode? == true")
@@ -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.
@@ -20,24 +21,24 @@ Ohai.plugin(:BlockDevice) do
20
21
  provides "block_device"
21
22
 
22
23
  collect_data(:linux) do
23
- if File.exist?("/sys/block")
24
+ if file_exist?("/sys/block")
24
25
  block = Mash.new
25
- Dir["/sys/block/*"].each do |block_device_dir|
26
+ dir_glob("/sys/block/*").each do |block_device_dir|
26
27
  dir = File.basename(block_device_dir)
27
28
  block[dir] = Mash.new
28
29
  %w{size removable}.each do |check|
29
- if File.exist?("/sys/block/#{dir}/#{check}")
30
- File.open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
30
+ if file_exist?("/sys/block/#{dir}/#{check}")
31
+ file_open("/sys/block/#{dir}/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
31
32
  end
32
33
  end
33
34
  %w{model rev state timeout vendor queue_depth}.each do |check|
34
- if File.exist?("/sys/block/#{dir}/device/#{check}")
35
- File.open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
35
+ if file_exist?("/sys/block/#{dir}/device/#{check}")
36
+ file_open("/sys/block/#{dir}/device/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
36
37
  end
37
38
  end
38
39
  %w{rotational physical_block_size logical_block_size}.each do |check|
39
- if File.exist?("/sys/block/#{dir}/queue/#{check}")
40
- File.open("/sys/block/#{dir}/queue/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
40
+ if file_exist?("/sys/block/#{dir}/queue/#{check}")
41
+ file_open("/sys/block/#{dir}/queue/#{check}") { |f| block[dir][check] = f.read_nonblock(1024).strip }
41
42
  end
42
43
  end
43
44
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Davide Cavalca (<dcavalca@fb.com>)
3
4
  # Copyright:: Copyright (c) 2016 Facebook
@@ -25,8 +26,8 @@ Ohai.plugin(:Hostnamectl) do
25
26
  hostnamectl_path = which("hostnamectl")
26
27
  if hostnamectl_path
27
28
  shell_out(hostnamectl_path).stdout.split("\n").each do |line|
28
- key, val = line.split(":")
29
- hostnamectl[key.chomp.lstrip.tr(" ", "_").downcase] = val.chomp.lstrip
29
+ key, val = line.split(": ", 2)
30
+ hostnamectl[key.chomp.lstrip.tr(" ", "_").downcase] = val
30
31
  end
31
32
  end
32
33
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Davide Cavalca <dcavalca@fb.com>
3
4
  # Copyright:: Copyright (c) 2020 Facebook
@@ -25,7 +26,7 @@ Ohai.plugin(:Interrupts) do
25
26
  # format: comma-separate list of 32bit bitmask in hex
26
27
  # each bit is a CPU, right to left ordering (i.e. CPU0 is rightmost)
27
28
  def parse_smp_affinity(path, cpus)
28
- masks = File.read(path).strip
29
+ masks = file_read(path).strip
29
30
  bit_masks = []
30
31
  masks.split(",").each do |mask|
31
32
  bit_masks << mask.rjust(8, "0").to_i(16).to_s(2)
@@ -47,7 +48,7 @@ Ohai.plugin(:Interrupts) do
47
48
  parse_smp_affinity("/proc/irq/default_smp_affinity", cpus)
48
49
 
49
50
  interrupts[:irq] = Mash.new
50
- File.open("/proc/interrupts").each do |line|
51
+ file_open("/proc/interrupts").each do |line|
51
52
  # Documentation: https://www.kernel.org/doc/Documentation/filesystems/proc.txt
52
53
  # format is "{irqn}: {CPUn...} [type] [vector] [device]"
53
54
  irqn, fields = line.split(":", 2)
@@ -70,7 +71,7 @@ Ohai.plugin(:Interrupts) do
70
71
  interrupts[:irq][irqn][:vector],
71
72
  interrupts[:irq][irqn][:device] =
72
73
  fields[cpus].split
73
- if File.exist?("/proc/irq/#{irqn}/smp_affinity")
74
+ if file_exist?("/proc/irq/#{irqn}/smp_affinity")
74
75
  interrupts[:irq][irqn][:smp_affinity_by_cpu] =
75
76
  parse_smp_affinity("/proc/irq/#{irqn}/smp_affinity", cpus)
76
77
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Jay Vana <jsvana@fb.com>
3
4
  # Author:: Davide Cavalca <dcavalca@fb.com>
@@ -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.
@@ -22,38 +23,24 @@ Ohai.plugin(:LSB) do
22
23
  collect_data(:linux) do
23
24
  lsb Mash.new
24
25
 
25
- if File.exist?("/usr/bin/lsb_release")
26
+ if file_exist?("/usr/bin/lsb_release")
26
27
  # From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu
27
28
  shell_out("lsb_release -a").stdout.lines do |line|
28
29
  case line
29
- when /^Distributor ID:\s+(.+)$/
30
+ when /^Distributor ID:\s+(.+)/
30
31
  lsb[:id] = $1
31
- when /^Description:\s+(.+)$/
32
+ when /^Description:\s+(.+)/
32
33
  lsb[:description] = $1
33
- when /^Release:\s+(.+)$/
34
+ when /^Release:\s+(.+)/
34
35
  lsb[:release] = $1
35
- when /^Codename:\s+(.+)$/
36
+ when /^Codename:\s+(.+)/
36
37
  lsb[:codename] = $1
37
38
  else
38
39
  lsb[:id] = line
39
40
  end
40
41
  end
41
- elsif File.exist?("/etc/lsb-release")
42
- # Old, non-standard Debian support
43
- File.open("/etc/lsb-release").each do |line|
44
- case line
45
- when /^DISTRIB_ID=["']?(.+?)["']?$/
46
- lsb[:id] = $1
47
- when /^DISTRIB_RELEASE=["']?(.+?)["']?$/
48
- lsb[:release] = $1
49
- when /^DISTRIB_CODENAME=["']?(.+?)["']?$/
50
- lsb[:codename] = $1
51
- when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/
52
- lsb[:description] = $1
53
- end
54
- end
55
42
  else
56
- logger.trace("Plugin LSB: Skipping LSB, cannot find /etc/lsb-release or /usr/bin/lsb_release")
43
+ logger.trace("Plugin LSB: Skipping LSB, cannot find /usr/bin/lsb_release")
57
44
  end
58
45
  end
59
46
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Joerg Herzinger <joerg.herzinger@oiml.at>
3
4
  # Author:: Phil Dibowitz <phil@ipom.com>
@@ -18,7 +19,6 @@
18
19
  # limitations under the License.
19
20
 
20
21
  Ohai.plugin(:Lspci) do
21
- depends "platform"
22
22
  provides "pci"
23
23
  optional true
24
24
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Davide Cavalca (<dcavalca@fb.com>)
3
4
  # Copyright:: Copyright (c) 2016 Facebook
@@ -20,10 +21,10 @@ Ohai.plugin(:Machineid) do
20
21
  provides "machine_id"
21
22
 
22
23
  collect_data(:linux) do
23
- if ::File.exist?("/etc/machine-id")
24
- mid = ::File.read("/etc/machine-id").chomp
25
- elsif ::File.exist?("/var/lib/dbus/machine-id")
26
- mid = ::File.read("/var/lib/dbus/machine-id").chomp
24
+ if file_exist?("/etc/machine-id")
25
+ mid = file_read("/etc/machine-id").chomp
26
+ elsif file_exist?("/var/lib/dbus/machine-id")
27
+ mid = file_read("/var/lib/dbus/machine-id").chomp
27
28
  else
28
29
  mid = nil
29
30
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Tim Smith <tsmith@limelight.com>
3
4
  # Author:: Phil Dibowitz <phild@ipomc.com>
@@ -53,9 +54,9 @@ Ohai.plugin(:Mdadm) do
53
54
 
54
55
  collect_data(:linux) do
55
56
  # gather a list of all raid arrays
56
- if File.exist?("/proc/mdstat")
57
+ if file_exist?("/proc/mdstat")
57
58
  devices = {}
58
- File.open("/proc/mdstat").each do |line|
59
+ file_open("/proc/mdstat").each do |line|
59
60
  if line =~ /(md[0-9]+)/
60
61
  device = Regexp.last_match[1]
61
62
  pieces = line.split(/\s+/)
@@ -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.
@@ -25,79 +26,79 @@ Ohai.plugin(:Memory) do
25
26
  memory[:hugepages] = Mash.new
26
27
  memory[:directmap] = Mash.new
27
28
 
28
- File.open("/proc/meminfo").each do |line|
29
+ file_open("/proc/meminfo").each do |line|
29
30
  case line
30
- when /^MemTotal:\s+(\d+) (.+)$/
31
+ when /^MemTotal:\s+(\d+) (.+)/
31
32
  memory[:total] = "#{$1}#{$2}"
32
- when /^MemFree:\s+(\d+) (.+)$/
33
+ when /^MemFree:\s+(\d+) (.+)/
33
34
  memory[:free] = "#{$1}#{$2}"
34
- when /^MemAvailable:\s+(\d+) (.+)$/
35
+ when /^MemAvailable:\s+(\d+) (.+)/
35
36
  memory[:available] = "#{$1}#{$2}"
36
- when /^Buffers:\s+(\d+) (.+)$/
37
+ when /^Buffers:\s+(\d+) (.+)/
37
38
  memory[:buffers] = "#{$1}#{$2}"
38
- when /^Cached:\s+(\d+) (.+)$/
39
+ when /^Cached:\s+(\d+) (.+)/
39
40
  memory[:cached] = "#{$1}#{$2}"
40
- when /^Active:\s+(\d+) (.+)$/
41
+ when /^Active:\s+(\d+) (.+)/
41
42
  memory[:active] = "#{$1}#{$2}"
42
- when /^Inactive:\s+(\d+) (.+)$/
43
+ when /^Inactive:\s+(\d+) (.+)/
43
44
  memory[:inactive] = "#{$1}#{$2}"
44
- when /^HighTotal:\s+(\d+) (.+)$/
45
+ when /^HighTotal:\s+(\d+) (.+)/
45
46
  memory[:high_total] = "#{$1}#{$2}"
46
- when /^HighFree:\s+(\d+) (.+)$/
47
+ when /^HighFree:\s+(\d+) (.+)/
47
48
  memory[:high_free] = "#{$1}#{$2}"
48
- when /^LowTotal:\s+(\d+) (.+)$/
49
+ when /^LowTotal:\s+(\d+) (.+)/
49
50
  memory[:low_total] = "#{$1}#{$2}"
50
- when /^LowFree:\s+(\d+) (.+)$/
51
+ when /^LowFree:\s+(\d+) (.+)/
51
52
  memory[:low_free] = "#{$1}#{$2}"
52
- when /^Dirty:\s+(\d+) (.+)$/
53
+ when /^Dirty:\s+(\d+) (.+)/
53
54
  memory[:dirty] = "#{$1}#{$2}"
54
- when /^Writeback:\s+(\d+) (.+)$/
55
+ when /^Writeback:\s+(\d+) (.+)/
55
56
  memory[:writeback] = "#{$1}#{$2}"
56
- when /^AnonPages:\s+(\d+) (.+)$/
57
+ when /^AnonPages:\s+(\d+) (.+)/
57
58
  memory[:anon_pages] = "#{$1}#{$2}"
58
- when /^Mapped:\s+(\d+) (.+)$/
59
+ when /^Mapped:\s+(\d+) (.+)/
59
60
  memory[:mapped] = "#{$1}#{$2}"
60
- when /^Slab:\s+(\d+) (.+)$/
61
+ when /^Slab:\s+(\d+) (.+)/
61
62
  memory[:slab] = "#{$1}#{$2}"
62
- when /^SReclaimable:\s+(\d+) (.+)$/
63
+ when /^SReclaimable:\s+(\d+) (.+)/
63
64
  memory[:slab_reclaimable] = "#{$1}#{$2}"
64
- when /^SUnreclaim:\s+(\d+) (.+)$/
65
+ when /^SUnreclaim:\s+(\d+) (.+)/
65
66
  memory[:slab_unreclaim] = "#{$1}#{$2}"
66
- when /^PageTables:\s+(\d+) (.+)$/
67
+ when /^PageTables:\s+(\d+) (.+)/
67
68
  memory[:page_tables] = "#{$1}#{$2}"
68
- when /^NFS_Unstable:\s+(\d+) (.+)$/
69
+ when /^NFS_Unstable:\s+(\d+) (.+)/
69
70
  memory[:nfs_unstable] = "#{$1}#{$2}"
70
- when /^Bounce:\s+(\d+) (.+)$/
71
+ when /^Bounce:\s+(\d+) (.+)/
71
72
  memory[:bounce] = "#{$1}#{$2}"
72
- when /^CommitLimit:\s+(\d+) (.+)$/
73
+ when /^CommitLimit:\s+(\d+) (.+)/
73
74
  memory[:commit_limit] = "#{$1}#{$2}"
74
- when /^Committed_AS:\s+(\d+) (.+)$/
75
+ when /^Committed_AS:\s+(\d+) (.+)/
75
76
  memory[:committed_as] = "#{$1}#{$2}"
76
- when /^VmallocTotal:\s+(\d+) (.+)$/
77
+ when /^VmallocTotal:\s+(\d+) (.+)/
77
78
  memory[:vmalloc_total] = "#{$1}#{$2}"
78
- when /^VmallocUsed:\s+(\d+) (.+)$/
79
+ when /^VmallocUsed:\s+(\d+) (.+)/
79
80
  memory[:vmalloc_used] = "#{$1}#{$2}"
80
- when /^VmallocChunk:\s+(\d+) (.+)$/
81
+ when /^VmallocChunk:\s+(\d+) (.+)/
81
82
  memory[:vmalloc_chunk] = "#{$1}#{$2}"
82
- when /^SwapCached:\s+(\d+) (.+)$/
83
+ when /^SwapCached:\s+(\d+) (.+)/
83
84
  memory[:swap][:cached] = "#{$1}#{$2}"
84
- when /^SwapTotal:\s+(\d+) (.+)$/
85
+ when /^SwapTotal:\s+(\d+) (.+)/
85
86
  memory[:swap][:total] = "#{$1}#{$2}"
86
- when /^SwapFree:\s+(\d+) (.+)$/
87
+ when /^SwapFree:\s+(\d+) (.+)/
87
88
  memory[:swap][:free] = "#{$1}#{$2}"
88
- when /^HugePages_Total:\s+(\d+)$/
89
+ when /^HugePages_Total:\s+(\d+)/
89
90
  memory[:hugepages][:total] = $1.to_s
90
- when /^HugePages_Free:\s+(\d+)$/
91
+ when /^HugePages_Free:\s+(\d+)/
91
92
  memory[:hugepages][:free] = $1.to_s
92
- when /^HugePages_Rsvd:\s+(\d+)$/
93
+ when /^HugePages_Rsvd:\s+(\d+)/
93
94
  memory[:hugepages][:reserved] = $1.to_s
94
- when /^HugePages_Surp:\s+(\d+)$/
95
+ when /^HugePages_Surp:\s+(\d+)/
95
96
  memory[:hugepages][:surplus] = $1.to_s
96
- when /^Hugepagesize:\s+(\d+) (.+)$/
97
+ when /^Hugepagesize:\s+(\d+) (.+)/
97
98
  memory[:hugepage_size] = "#{$1}#{$2}"
98
- when /^Hugetlb:\s+(\d+) (.+)$/
99
+ when /^Hugetlb:\s+(\d+) (.+)/
99
100
  memory[:hugetlb] = "#{$1}#{$2}"
100
- when /^DirectMap([0-9]+[a-zA-Z]):\s+(\d+) (.+)$/
101
+ when /^DirectMap([0-9]+[a-zA-Z]):\s+(\d+) (.+)/
101
102
  memory[:directmap][$1.to_sym] = "#{$2}#{$3}"
102
103
  end
103
104
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Adam Jacob (<adam@chef.io>)
3
4
  # Author:: Chris Read <chris.read@gmail.com>
@@ -35,7 +36,7 @@ Ohai.plugin(:Network) do
35
36
  end
36
37
 
37
38
  def ipv6_enabled?
38
- File.exist? "/proc/net/if_inet6"
39
+ file_exist? "/proc/net/if_inet6"
39
40
  end
40
41
 
41
42
  def ethtool_binary_path
@@ -43,11 +44,11 @@ Ohai.plugin(:Network) do
43
44
  end
44
45
 
45
46
  def is_openvz?
46
- @openvz ||= ::File.directory?("/proc/vz")
47
+ @openvz ||= file_directory?("/proc/vz")
47
48
  end
48
49
 
49
50
  def is_openvz_host?
50
- is_openvz? && ::File.directory?("/proc/bc")
51
+ is_openvz? && file_directory?("/proc/bc")
51
52
  end
52
53
 
53
54
  def extract_neighbors(family, iface, neigh_attr)
@@ -153,7 +154,7 @@ Ohai.plugin(:Network) do
153
154
  def ethernet_layer_one(iface)
154
155
  return iface unless ethtool_binary_path
155
156
 
156
- keys = %w{ Speed Duplex Port Transceiver Auto-negotiation MDI-X }
157
+ keys = %w{Speed Duplex Port Transceiver Auto-negotiation MDI-X}
157
158
  iface.each_key do |tmp_int|
158
159
  next unless iface[tmp_int][:encapsulation] == "Ethernet"
159
160
 
@@ -272,6 +273,30 @@ Ohai.plugin(:Network) do
272
273
  iface
273
274
  end
274
275
 
276
+ # determine pause parameters for the interface using ethtool
277
+ def ethernet_pause_parameters(iface)
278
+ return iface unless ethtool_binary_path
279
+
280
+ iface.each_key do |tmp_int|
281
+ next unless iface[tmp_int][:encapsulation] == "Ethernet"
282
+
283
+ so = shell_out("#{ethtool_binary_path} -a #{tmp_int}")
284
+ logger.trace("Plugin Network: Parsing ethtool output: #{so.stdout}")
285
+ iface[tmp_int]["pause_params"] = {}
286
+ so.stdout.lines.each do |line|
287
+ next if line.start_with?("Pause parameters for")
288
+ next if line.strip.nil?
289
+
290
+ key, val = line.split(/:\s+/)
291
+ if val
292
+ pause_key = "#{key.downcase.tr(" ", "_")}"
293
+ iface[tmp_int]["pause_params"][pause_key] = val.strip.eql? "on"
294
+ end
295
+ end
296
+ end
297
+ iface
298
+ end
299
+
275
300
  # determine driver info for the interface using ethtool
276
301
  def ethernet_driver_info(iface)
277
302
  return iface unless ethtool_binary_path
@@ -384,7 +409,7 @@ Ohai.plugin(:Network) do
384
409
  if line =~ IPROUTE_INT_REGEX
385
410
  cint = $2
386
411
  iface[cint] = Mash.new
387
- if cint =~ /^(\w+)(\d+.*)/
412
+ if cint =~ /^(\w+?)(\d+.*)/
388
413
  iface[cint][:type] = $1
389
414
  iface[cint][:number] = $2
390
415
  end
@@ -465,7 +490,7 @@ Ohai.plugin(:Network) do
465
490
  iface[cint][:addresses] ||= Mash.new
466
491
  tmp_addr = $1
467
492
  tags = $4 || ""
468
- tags = tags.split(" ")
493
+ tags = tags.split
469
494
 
470
495
  iface[cint][:addresses][tmp_addr] = {
471
496
  "family" => "inet6",
@@ -695,7 +720,7 @@ Ohai.plugin(:Network) do
695
720
  if line =~ /^([0-9a-zA-Z@\.\:\-_]+)\s+/
696
721
  cint = $1
697
722
  iface[cint] = Mash.new
698
- if cint =~ /^(\w+)(\d+.*)/
723
+ if cint =~ /^(\w+?)(\d+.*)/
699
724
  iface[cint][:type] = $1
700
725
  iface[cint][:number] = $2
701
726
  end
@@ -769,6 +794,7 @@ Ohai.plugin(:Network) do
769
794
  iface = ethernet_channel_parameters(iface)
770
795
  iface = ethernet_coalesce_parameters(iface)
771
796
  iface = ethernet_driver_info(iface)
797
+ iface = ethernet_pause_parameters(iface)
772
798
  counters[:network][:interfaces] = net_counters
773
799
  network["interfaces"] = iface
774
800
  end