ohai 16.5.4 → 16.8.1

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 +10 -9
  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 +14 -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 +2 -1
  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 +7 -6
  90. data/lib/ohai/plugins/linux/platform.rb +31 -30
  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 +21 -4
  158. data/lib/ohai/plugins/joyent.rb +0 -77
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Copyright:: Copyright (c) Chef Software Inc.
3
4
  # License:: Apache License, Version 2.0
@@ -47,7 +48,7 @@ Ohai.plugin(:Docker) do
47
48
  docker[:swarm] = shellout_data["Swarm"]
48
49
  end
49
50
 
50
- collect_data do
51
+ collect_data(:linux, :windows, :darwin) do
51
52
  require "json" unless defined?(JSON)
52
53
 
53
54
  if virtualization[:systems][:docker]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
@@ -25,22 +26,22 @@ Ohai.plugin(:Memory) do
25
26
 
26
27
  # /usr/src/sys/sys/vmmeter.h
27
28
  so = shell_out("sysctl -n vm.stats.vm.v_page_size")
28
- memory[:page_size] = so.stdout.split($/)[0]
29
+ memory[:page_size] = so.stdout.strip
29
30
  so = shell_out("sysctl -n vm.stats.vm.v_page_count")
30
- memory[:page_count] = so.stdout.split($/)[0]
31
+ memory[:page_count] = so.stdout.strip
31
32
  memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i
32
33
  so = shell_out("sysctl -n vm.stats.vm.v_free_count")
33
- memory[:free] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
34
+ memory[:free] = memory[:page_size].to_i * so.stdout.strip.to_i
34
35
  so = shell_out("sysctl -n vm.status.vm.v_active_count")
35
- memory[:active] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
36
+ memory[:active] = memory[:page_size].to_i * so.stdout.strip.to_i
36
37
  so = shell_out("sysctl -n vm.status.vm.v_inactive_count")
37
- memory[:inactive] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
38
+ memory[:inactive] = memory[:page_size].to_i * so.stdout.strip.to_i
38
39
  so = shell_out("sysctl -n vm.stats.vm.v_cache_count")
39
- memory[:cache] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
40
+ memory[:cache] = memory[:page_size].to_i * so.stdout.strip.to_i
40
41
  so = shell_out("sysctl -n vm.stats.vm.v_wire_count")
41
- memory[:wired] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
42
+ memory[:wired] = memory[:page_size].to_i * so.stdout.strip.to_i
42
43
  so = shell_out("sysctl -n vfs.bufspace")
43
- memory[:buffers] = so.stdout.split($/)[0]
44
+ memory[:buffers] = so.stdout.strip
44
45
 
45
46
  so = shell_out("swapinfo")
46
47
  so.stdout.lines do |line|
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
@@ -20,8 +21,8 @@ Ohai.plugin(:Platform) do
20
21
  provides "platform", "platform_version", "platform_family"
21
22
 
22
23
  collect_data(:dragonflybsd) do
23
- platform shell_out("uname -s").stdout.split($/)[0].downcase
24
- platform_version shell_out("uname -r").stdout.split($/)[0]
24
+ platform shell_out("uname -s").stdout.strip.downcase
25
+ platform_version shell_out("uname -r").stdout.strip
25
26
  platform_family "dragonflybsd"
26
27
  end
27
28
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Tim Dysinger (<tim@dysinger.net>)
3
4
  # Author:: Benjamin Black (<bb@chef.io>)
@@ -97,8 +98,8 @@ Ohai.plugin(:EC2) do
97
98
  # @param path[String] abs path to the file
98
99
  # @return [String] contents of the file if it exists
99
100
  def file_val_if_exists(path)
100
- if ::File.exist?(path)
101
- ::File.read(path)
101
+ if file_exist?(path)
102
+ file_read(path)
102
103
  end
103
104
  end
104
105
 
@@ -122,11 +123,17 @@ Ohai.plugin(:EC2) do
122
123
  fetch_metadata.each do |k, v|
123
124
  # fetch_metadata returns IAM security credentials, including the IAM user's
124
125
  # secret access key. We'd rather not have ohai send this information
125
- # to the server.
126
- # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
127
- next if k == "iam" && !hint?("iam")
128
-
129
- ec2[k] = v
126
+ # to the server. If the instance is associated with an IAM role we grab
127
+ # only the "info" key and the IAM role name.
128
+ # https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html
129
+ if k == "iam" && !hint?("iam")
130
+ ec2[:iam] = v.select { |key, value| key == "info" }
131
+ if v["security-credentials"] && v["security-credentials"].keys.length == 1
132
+ ec2[:iam]["role_name"] = v["security-credentials"].keys[0]
133
+ end
134
+ else
135
+ ec2[k] = v
136
+ end
130
137
  end
131
138
  ec2[:userdata] = fetch_userdata
132
139
  ec2[:account_id] = fetch_dynamic_data["accountId"]
@@ -15,7 +15,7 @@
15
15
 
16
16
  Ohai.plugin(:Elixir) do
17
17
  provides "languages/elixir"
18
- depends "languages"
18
+ depends "languages".freeze
19
19
 
20
20
  collect_data do
21
21
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Joe Williams (<joe@joetify.com>)
3
4
  # Copyright:: Copyright (c) Chef Software Inc.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Tim Dysinger (<tim@dysinger.net>)
3
4
  # Author:: Benjamin Black (<bb@chef.io>)
@@ -28,6 +29,8 @@ Ohai.plugin(:Eucalyptus) do
28
29
  provides "eucalyptus"
29
30
  depends "network/interfaces"
30
31
 
32
+ MAC_MATCH = /^[dD]0:0[dD]:/.freeze
33
+
31
34
  # returns the mac address from the collection of all address types
32
35
  def get_mac_address(addresses)
33
36
  detected_addresses = addresses.detect { |address, keypair| keypair == { "family" => "lladdr" } }
@@ -42,7 +45,7 @@ Ohai.plugin(:Eucalyptus) do
42
45
  def has_euca_mac?
43
46
  network[:interfaces].each_value do |iface|
44
47
  mac = get_mac_address(iface[:addresses])
45
- if /^[dD]0:0[dD]:/.match?(mac)
48
+ if MAC_MATCH.match?(mac)
46
49
  logger.trace("Plugin Eucalyptus: has_euca_mac? == true (#{mac})")
47
50
  return true
48
51
  end
@@ -24,12 +24,12 @@
24
24
  #
25
25
 
26
26
  Ohai.plugin(:Filesystem) do
27
- provides "filesystem"
27
+ provides "filesystem".freeze
28
28
 
29
29
  def find_device(name)
30
30
  %w{/dev /dev/mapper}.each do |dir|
31
31
  path = File.join(dir, name)
32
- return path if File.exist?(path)
32
+ return path if file_exist?(path)
33
33
  end
34
34
  name
35
35
  end
@@ -371,11 +371,11 @@ Ohai.plugin(:Filesystem) do
371
371
  end
372
372
 
373
373
  # Grab any missing mount information from /proc/mounts
374
- if File.exist?("/proc/mounts")
374
+ if file_exist?("/proc/mounts")
375
375
  mounts = ""
376
376
  # Due to https://tickets.opscode.com/browse/OHAI-196
377
377
  # we have to non-block read dev files. Ew.
378
- f = File.open("/proc/mounts")
378
+ f = file_open("/proc/mounts")
379
379
  loop do
380
380
  data = f.read_nonblock(4096)
381
381
  mounts << data
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Matt Wrock (<matt@mattwrock.com>)
3
4
  # Copyright:: Copyright (c) Chef Software Inc.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
@@ -25,22 +26,22 @@ Ohai.plugin(:Memory) do
25
26
 
26
27
  # /usr/src/sys/sys/vmmeter.h
27
28
  so = shell_out("sysctl -n vm.stats.vm.v_page_size")
28
- memory[:page_size] = so.stdout.split($/)[0]
29
+ memory[:page_size] = so.stdout.strip
29
30
  so = shell_out("sysctl -n vm.stats.vm.v_page_count")
30
- memory[:page_count] = so.stdout.split($/)[0]
31
+ memory[:page_count] = so.stdout.strip
31
32
  memory[:total] = memory[:page_size].to_i * memory[:page_count].to_i
32
33
  so = shell_out("sysctl -n vm.stats.vm.v_free_count")
33
- memory[:free] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
34
+ memory[:free] = memory[:page_size].to_i * so.stdout.strip.to_i
34
35
  so = shell_out("sysctl -n vm.status.vm.v_active_count")
35
- memory[:active] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
36
+ memory[:active] = memory[:page_size].to_i * so.stdout.strip.to_i
36
37
  so = shell_out("sysctl -n vm.status.vm.v_inactive_count")
37
- memory[:inactive] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
38
+ memory[:inactive] = memory[:page_size].to_i * so.stdout.strip.to_i
38
39
  so = shell_out("sysctl -n vm.stats.vm.v_cache_count")
39
- memory[:cache] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
40
+ memory[:cache] = memory[:page_size].to_i * so.stdout.strip.to_i
40
41
  so = shell_out("sysctl -n vm.stats.vm.v_wire_count")
41
- memory[:wired] = memory[:page_size].to_i * so.stdout.split($/)[0].to_i
42
+ memory[:wired] = memory[:page_size].to_i * so.stdout.strip.to_i
42
43
  so = shell_out("sysctl -n vfs.bufspace")
43
- memory[:buffers] = so.stdout.split($/)[0]
44
+ memory[:buffers] = so.stdout.strip
44
45
 
45
46
  so = shell_out("swapinfo")
46
47
  so.stdout.lines do |line|
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Bryan McLellan (btm@loftninjas.org)
3
4
  # Copyright:: Copyright (c) 2009 Bryan McLellan
@@ -20,8 +21,8 @@ Ohai.plugin(:Platform) do
20
21
  provides "platform", "platform_version", "platform_family"
21
22
 
22
23
  collect_data(:freebsd) do
23
- platform shell_out("uname -s").stdout.split($/)[0].downcase
24
- platform_version shell_out("uname -r").stdout.split($/)[0]
24
+ platform shell_out("uname -s").stdout.strip.downcase
25
+ platform_version shell_out("uname -r").stdout.strip
25
26
  platform_family "freebsd"
26
27
  end
27
28
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Ranjib Dey (<dey.ranjib@google.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -40,8 +41,8 @@ Ohai.plugin(:GCE) do
40
41
  # @param path[String] abs path to the file
41
42
  # @return [String] contents of the file if it exists
42
43
  def file_val_if_exists(path)
43
- if ::File.exist?(path)
44
- ::File.read(path)
44
+ if file_exist?(path)
45
+ file_read(path)
45
46
  end
46
47
  end
47
48
 
@@ -15,7 +15,7 @@
15
15
 
16
16
  Ohai.plugin(:Go) do
17
17
  provides "languages/go"
18
- depends "languages"
18
+ depends "languages".freeze
19
19
 
20
20
  collect_data do
21
21
 
@@ -18,7 +18,7 @@
18
18
 
19
19
  Ohai.plugin(:Groovy) do
20
20
  provides "languages/groovy"
21
- depends "languages"
21
+ depends "languages".freeze
22
22
 
23
23
  collect_data do
24
24
 
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Author:: Davide Cavalca <dcavalca@fb.com>
4
+ # Copyright:: Copyright (c) 2020 Facebook
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ Ohai.plugin(:Grub2) do
21
+ provides "grub2/environment"
22
+ optional true
23
+
24
+ collect_data(:dragonflybsd, :freebsd, :linux, :netbsd) do
25
+ editenv_path = which("grub2-editenv")
26
+ if editenv_path
27
+ editenv_out = shell_out("#{editenv_path} list")
28
+
29
+ grub2 Mash.new unless grub2
30
+ grub2[:environment] ||= Mash.new
31
+
32
+ editenv_out.stdout.each_line do |line|
33
+ key, val = line.split("=", 2)
34
+ grub2[:environment][key] = val.strip
35
+ end
36
+ else
37
+ logger.trace("Plugin Grub2: Could not find grub2-editenv. Skipping plugin.")
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Author:: Chris Dituri (<csdituri@gmail.com>)
2
3
  # Copyright:: Copyright (c) 2016 Chris Dituri
3
4
  # License:: Apache License, Version 2.0
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Adam Jacob (<adam@chef.io>)
3
4
  # Author:: Benjamin Black (<nostromo@gmail.com>)
@@ -37,8 +38,7 @@ Ohai.plugin(:Hostname) do
37
38
  # fqdn and domain may be broken if DNS is broken on the host
38
39
 
39
40
  def from_cmd(cmd)
40
- so = shell_out(cmd)
41
- so.stdout.split($/)[0]
41
+ shell_out(cmd).stdout.strip
42
42
  end
43
43
 
44
44
  # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Caleb Tennis (<caleb.tennis@gmail.com>)
3
4
  # Copyright:: Copyright (c) Chef Software Inc.
@@ -20,6 +21,6 @@ Ohai.plugin(:InitPackage) do
20
21
  provides "init_package"
21
22
 
22
23
  collect_data(:linux) do
23
- init_package File.exist?("/proc/1/comm") ? File.open("/proc/1/comm").gets.chomp : "init"
24
+ init_package file_exist?("/proc/1/comm") ? file_open("/proc/1/comm").gets.chomp : "init"
24
25
  end
25
26
  end
@@ -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.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Adam Jacob (<adam@chef.io>)
3
4
  # Author:: Benjamin Black (<nostromo@gmail.com>)
@@ -33,7 +34,7 @@ Ohai.plugin(:Kernel) do
33
34
  ["uname -v", :version], ["uname -m", :machine],
34
35
  ["uname -p", :processor]].each do |cmd, property|
35
36
  so = shell_out(cmd)
36
- kernel[property] = so.stdout.split($/)[0]
37
+ kernel[property] = so.stdout.strip
37
38
  end
38
39
  kernel
39
40
  end
@@ -114,7 +115,6 @@ Ohai.plugin(:Kernel) do
114
115
  when 16 then "WIN95"
115
116
  when 17 then "WIN98"
116
117
  when 19 then "WINCE"
117
- else nil
118
118
  end
119
119
  end
120
120
 
@@ -133,7 +133,6 @@ Ohai.plugin(:Kernel) do
133
133
  when 6 then "Appliance PC"
134
134
  when 7 then "Performance Server"
135
135
  when 8 then "Maximum"
136
- else nil
137
136
  end
138
137
  end
139
138
 
@@ -156,6 +155,10 @@ Ohai.plugin(:Kernel) do
156
155
  ].include?(name)
157
156
  end
158
157
 
158
+ collect_data(:target) do
159
+ # intentionally left blank
160
+ end
161
+
159
162
  collect_data(:default) do
160
163
  kernel init_kernel
161
164
  end
@@ -165,7 +168,7 @@ Ohai.plugin(:Kernel) do
165
168
  kernel[:os] = kernel[:name]
166
169
 
167
170
  so = shell_out("sysctl -n hw.optional.x86_64")
168
- if so.stdout.split($/)[0].to_i == 1
171
+ if so.stdout.strip.to_i == 1
169
172
  kernel[:machine] = "x86_64"
170
173
  end
171
174
 
@@ -185,7 +188,7 @@ Ohai.plugin(:Kernel) do
185
188
  kernel[:os] = kernel[:name]
186
189
 
187
190
  so = shell_out("uname -i")
188
- kernel[:ident] = so.stdout.split($/)[0]
191
+ kernel[:ident] = so.stdout.strip
189
192
  so = shell_out("sysctl kern.securelevel")
190
193
  kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ }
191
194
 
@@ -196,7 +199,7 @@ Ohai.plugin(:Kernel) do
196
199
  kernel init_kernel
197
200
 
198
201
  so = shell_out("uname -o")
199
- kernel[:os] = so.stdout.split($/)[0]
202
+ kernel[:os] = so.stdout.strip
200
203
 
201
204
  modules = Mash.new
202
205
  so = shell_out("env lsmod")
@@ -204,8 +207,8 @@ Ohai.plugin(:Kernel) do
204
207
  if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/
205
208
  modules[$1] = { size: $2, refcount: $3 }
206
209
  # Making sure to get the module version that has been loaded
207
- if File.exist?("/sys/module/#{$1}/version")
208
- version = File.read("/sys/module/#{$1}/version").chomp.strip
210
+ if file_exist?("/sys/module/#{$1}/version")
211
+ version = file_read("/sys/module/#{$1}/version").chomp.strip
209
212
  modules[$1]["version"] = version unless version.empty?
210
213
  end
211
214
  end
@@ -228,9 +231,9 @@ Ohai.plugin(:Kernel) do
228
231
  kernel init_kernel
229
232
 
230
233
  so = shell_out("uname -s")
231
- kernel[:os] = so.stdout.split($/)[0]
234
+ kernel[:os] = so.stdout.strip
232
235
 
233
- so = File.open("/etc/release", &:gets)
236
+ so = file_open("/etc/release", &:gets)
234
237
  md = /(?<update>\d.*\d)/.match(so)
235
238
  kernel[:update] = md[:update] if md
236
239
 
@@ -240,7 +243,7 @@ Ohai.plugin(:Kernel) do
240
243
  # EXAMPLE:
241
244
  # Id Loadaddr Size Info Rev Module Name
242
245
  # 6 1180000 4623 1 1 specfs (filesystem for specfs)
243
- module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/
246
+ module_description = /\s*(\d+)\s+([a-f\d]+)\s+([a-f\d]+)\s+(?:[\-\d]+)\s+(?:\d+)\s+(\S+)\s+\((.+)\)$/
244
247
  so.stdout.lines do |line|
245
248
  if ( mod = module_description.match(line) )
246
249
  modules[mod[4]] = { id: mod[1].to_i, loadaddr: mod[2], size: mod[3].to_i(16), description: mod[5] }