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
  # Author:: Ranjib Dey (<dey.ranjib@gmail.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -21,8 +22,8 @@ module Ohai
21
22
  module GCEMetadata
22
23
 
23
24
  # Trailing dot to host is added to avoid DNS search path
24
- GCE_METADATA_ADDR ||= "metadata.google.internal.".freeze
25
- GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true".freeze
25
+ GCE_METADATA_ADDR ||= "metadata.google.internal."
26
+ GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true"
26
27
 
27
28
  # fetch the meta content with a timeout and the required header
28
29
  def http_get(uri)
@@ -71,7 +72,7 @@ module Ohai
71
72
  #
72
73
  # @return [Boolean] is there a trailing /?
73
74
  def has_trailing_slash?(data)
74
- !! ( data =~ %r{/$} )
75
+ !!( data =~ %r{/$} )
75
76
  end
76
77
 
77
78
  def sanitize_key(key)
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Serdar Sutay (<serdar@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
  # Copyright:: Copyright (c) Chef Software Inc.
@@ -27,6 +28,71 @@ module Ohai
27
28
  #
28
29
  # @return [String] the OS
29
30
  def collect_os
31
+ if target_mode?
32
+ collect_os_target
33
+ else
34
+ collect_os_local
35
+ end
36
+ end
37
+
38
+ # This should exactly preserve the semantics of collect_os_local below, which is authoritative
39
+ # for the API and must adhere to pre-existing ohai semantics and not follow inspec's notion of
40
+ # os/family/hierarchy.
41
+ #
42
+ # Right or wrong the ohai `os` variable has matched the ruby `host_os` definition for the past
43
+ # 10+ years, preceding inspec/train's definitions and this is the documented correct API of
44
+ # these methods. Mismatches between the ruby notion and the train version will be fixed as
45
+ # bugfixes in these methods and may not be considered semver violating even though they make
46
+ # break downstream consumers. Please ensure that both methods produce the same results if
47
+ # you are on a platform which supports running ruby (train is considered authoritative for
48
+ # any "OS" which cannot run ruby -- server consoles, REST APIs, etc...)
49
+ #
50
+ # @api private
51
+ def collect_os_target
52
+ case
53
+ when transport_connection.os.aix?
54
+ "aix"
55
+ when transport_connection.os.darwin?
56
+ "darwin"
57
+ when transport_connection.os.linux?
58
+ "linux"
59
+ when transport_connection.os.family == "freebsd"
60
+ "freebsd"
61
+ when transport_connection.os.family == "openbsd"
62
+ "openbsd"
63
+ when transport_connection.os.family == "netbsd"
64
+ "netbsd"
65
+ when transport_connection.os.family == "dragonflybsd"
66
+ "dragonflybsd"
67
+ when transport_connection.os.solaris?
68
+ "solaris2"
69
+ when transport_connection.os.windows?
70
+ "windows"
71
+
72
+ #
73
+ # The purpose of the next two lines is that anything which runs Unix is presumed to be able to run ruby, and
74
+ # if it was not caught above, we MUST translate whatever train uses as the 'os' into the proper ruby host_os
75
+ # string. If it is not unix and not caught above we assume it is something like a REST API which cannot run
76
+ # ruby. If these assumptions are incorrect then it is a bug, which should be submitted to fix it, and the
77
+ # values should not be relied upon until that bug is fixed. The train os is NEVER considered authoritative
78
+ # for any target which can run ruby.
79
+ #
80
+ when transport_connection.os.unix?
81
+ raise "Target mode unsupported on this Unix-like host, please update the collect_os_target case statement with the correct ruby host_os value."
82
+ else
83
+ # now we have something like an IPMI console that isn't Unix-like or Windows, presumably cannot run ruby, and
84
+ # so we just trust the train O/S information.
85
+ transport_connection.os
86
+ end
87
+ end
88
+
89
+ # @api private
90
+ def nonruby_target?
91
+ transport_connection && !transport_connection.os.unix? && !transport_connection.os.windows
92
+ end
93
+
94
+ # @api private
95
+ def collect_os_local
30
96
  case ::RbConfig::CONFIG["host_os"]
31
97
  when /aix(.+)$/
32
98
  "aix"
@@ -56,7 +122,7 @@ module Ohai
56
122
  end
57
123
  end
58
124
 
59
- module_function :collect_os
125
+ extend self
60
126
  end
61
127
  end
62
128
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Jonathan Amiez (<jonathan.amiez@gmail.com>)
3
4
  # License:: Apache License, Version 2.0
@@ -20,8 +21,8 @@ module Ohai
20
21
  module Mixin
21
22
  module ScalewayMetadata
22
23
 
23
- SCALEWAY_METADATA_ADDR ||= "169.254.42.42".freeze
24
- SCALEWAY_METADATA_URL ||= "/conf?format=json".freeze
24
+ SCALEWAY_METADATA_ADDR ||= "169.254.42.42"
25
+ SCALEWAY_METADATA_URL ||= "/conf?format=json"
25
26
 
26
27
  # @return [Net::HTTP] net/http object without timeout set to 6
27
28
  def http_client
@@ -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:: Adam Jacob (<adam@chef.io>)
3
4
  # Author:: Tim Smith (<tsmith@chef.io>)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Alexey Karpik <alexey.karpik@rightscale.com>
3
4
  # Author:: Peter Schroeter <peter.schroeter@rightscale.com>
@@ -22,7 +23,7 @@ require "uri" unless defined?(URI)
22
23
 
23
24
  # https://softlayer.github.io/reference/services/SoftLayer_Resource_Metadata/
24
25
  module ::Ohai::Mixin::SoftlayerMetadata
25
- SOFTLAYER_API_QUERY_URL ||= "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata".freeze
26
+ SOFTLAYER_API_QUERY_URL ||= "https://api.service.softlayer.com/rest/v3.1/SoftLayer_Resource_Metadata"
26
27
 
27
28
  # fetch metadata items and build out hash of data
28
29
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: James Gartrell (<jgartrel@gmail.com>)
3
4
  # Copyright:: Copyright (c) Chef Software Inc.
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Copyright:: Copyright (c) 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 "chef-utils/dsl/train_helpers" unless defined?(ChefUtils::DSL::TrainHelpers)
19
+ require_relative "chef_utils_wiring" unless defined?(Ohai::Mixin::ChefUtilsWiring)
20
+
21
+ module Ohai
22
+ module Mixin
23
+ module TrainHelpers
24
+ include ChefUtils::DSL::TrainHelpers
25
+ include ChefUtilsWiring
26
+
27
+ # anything added to this file temporarily should be pushed back up
28
+ # into ChefUtils::DSL::TrainHelpers
29
+
30
+ # XXX: this needs better support directly in train
31
+ def dir_glob(path)
32
+ shell_out!("ls -d #{path}").stdout.split
33
+ end
34
+ end
35
+ end
36
+ end
@@ -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
@@ -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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Joshua Timberman <joshua@chef.io>
3
4
  # Author:: Isa Farnik (<isa@chef.io>)
@@ -23,10 +24,12 @@ Ohai.plugin(:Kernel) do
23
24
  collect_data(:aix) do
24
25
  kernel Mash.new
25
26
 
26
- kernel[:name] = shell_out("uname -s").stdout.split($/)[0].downcase
27
- kernel[:release] = shell_out("uname -r").stdout.split($/)[0]
28
- kernel[:version] = shell_out("uname -v").stdout.split($/)[0]
29
- kernel[:machine] = shell_out("uname -p").stdout.split($/)[0]
27
+ uname_so = shell_out("uname -rvp").stdout.split
28
+
29
+ kernel[:name] = "aix" # this is here for historical reasons, but it's always aix
30
+ kernel[:release] = uname_so[0]
31
+ kernel[:version] = uname_so[1]
32
+ kernel[:machine] = uname_so[2]
30
33
  kernel[:bits] = shell_out("getconf KERNEL_BITMODE").stdout.strip
31
34
 
32
35
  modules = Mash.new
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Joshua Timberman <joshua@chef.io>
3
4
  # Author:: Isa Farnik (<isa@chef.io>)
@@ -24,10 +25,10 @@ Ohai.plugin(:Memory) do
24
25
  memory Mash.new
25
26
  memory[:swap] = Mash.new
26
27
 
27
- meminfo = shell_out("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'").stdout
28
+ meminfo = shell_out("svmon -G -O unit=KB,summary=longreal | grep '[0-9]'").stdout
28
29
  total_in_mb, _u, free_in_mb = meminfo.split
29
- memory[:total] = "#{total_in_mb.to_i * 1024}kB"
30
- memory[:free] = "#{free_in_mb.to_i * 1024}kB"
30
+ memory[:total] = "#{total_in_mb.to_i}kB"
31
+ memory[:free] = "#{free_in_mb.to_i}kB"
31
32
 
32
33
  swap_info = shell_out("swap -s").stdout.split # returns swap info in 4K blocks
33
34
  memory[:swap]["total"] = "#{swap_info[2].to_i * 4}kB"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
3
4
  # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
@@ -21,7 +22,7 @@
21
22
  Ohai.plugin(:Network) do
22
23
  require_relative "../../mixin/network_helper"
23
24
 
24
- provides "network", "counters/network", "macaddress"
25
+ provides "network", "network/interfaces", "counters/network", "macaddress"
25
26
 
26
27
  include Ohai::Mixin::NetworkHelper
27
28
 
@@ -37,46 +38,44 @@ Ohai.plugin(:Network) do
37
38
  # => state up/down (ifconfig/lsattr)
38
39
  # => arp (arp -an)
39
40
 
40
- iface = Mash.new
41
+ ifaces = Mash.new
41
42
 
42
43
  network Mash.new unless network
43
- network[:interfaces] ||= Mash.new
44
44
 
45
45
  # We unfortunately have to do things a bit different here, if ohai is running
46
46
  # within a WPAR. For instance, the WPAR isn't aware of some of its own networking
47
- # minutia such as default gateway/route.
47
+ # minutia such as default gateway/route. lpars return 0 here. wpars return > 0
48
48
  unless shell_out("uname -W").stdout.to_i > 0
49
49
  # :default_interface, :default_gateway - route -n get 0
50
- so = shell_out("netstat -rn |grep default")
51
- so.stdout.lines.each do |line|
52
- items = line.split(" ")
53
- if items[0] == "default"
54
- network[:default_gateway] = items[1]
55
- network[:default_interface] = items[5]
56
- end
57
- end
50
+ default_line = shell_out("netstat -rn")
51
+ .stdout
52
+ .each_line
53
+ .detect { |l| l.start_with?("default") }
54
+ .split
55
+ network[:default_gateway] = default_line[1]
56
+ network[:default_interface] = default_line[5]
58
57
  end
59
58
 
60
- # Splits the ifconfig output to 1 line per interface
61
- if_so = shell_out("ifconfig -a")
62
- if_so.stdout.gsub(/\n(\w+\d+)/, '___\1').split("___").each do |intraface|
63
- splat = intraface.split(":")
64
- interface = splat[0]
65
- line = splat[1..-1][0]
66
- iface[interface] = Mash.new
67
- iface[interface][:state] = (line.include?("<UP,") ? "up" : "down")
68
-
69
- intraface.lines.each do |lin|
70
- case lin
59
+ # Splits the ifconfig output into arrays of interface strings
60
+ shell_out("ifconfig -a").stdout.split(/\n(?=\w)/).each do |int_lines|
61
+ int_name, int_data = int_lines.split(":", 2)
62
+
63
+ ifaces[int_name] = Mash.new
64
+ ifaces[int_name][:addresses] ||= Mash.new
65
+ ifaces[int_name][:state] = (int_data.include?("<UP,") ? "up" : "down")
66
+
67
+ int_data.each_line do |line|
68
+ case line
71
69
  when /flags=\S+<(\S+)>/
72
- iface[interface][:flags] = $1.split(",")
73
- iface[interface][:metric] = $1 if lin =~ /metric\s(\S+)/
70
+ ifaces[int_name][:flags] = $1.split(",")
71
+ ifaces[int_name][:metric] = $1 if line =~ /metric\s(\S+)/
74
72
  else
75
73
  # We have key value pairs.
76
- if lin =~ %r{inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/(\d{1,2}))?}
77
- tmp_addr, tmp_prefix = $1, $3
74
+ if line =~ %r{inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(/(\d{1,2}))?}
75
+ tmp_addr = $1
76
+ tmp_prefix = $3
78
77
  if tmp_prefix.nil?
79
- netmask = hex_to_dec_netmask($1) if lin =~ /netmask\s0x(\S+)\s/
78
+ netmask = hex_to_dec_netmask($1) if line =~ /netmask\s0x(\S+)\s/
80
79
  unless netmask
81
80
  tmp_prefix ||= "32"
82
81
  netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
@@ -85,57 +84,51 @@ Ohai.plugin(:Network) do
85
84
  netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
86
85
  end
87
86
 
88
- iface[interface][:addresses] ||= Mash.new
89
- iface[interface][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
90
- iface[interface][:addresses][tmp_addr][:netmask] = netmask
87
+ ifaces[int_name][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
88
+ ifaces[int_name][:addresses][tmp_addr][:netmask] = netmask
91
89
 
92
- if lin =~ /broadcast\s(\S+)\s/
93
- iface[interface][:addresses][tmp_addr][:broadcast] = $1
90
+ if line =~ /broadcast\s(\S+)\s/
91
+ ifaces[int_name][:addresses][tmp_addr][:broadcast] = $1
94
92
  end
95
- elsif lin =~ %r{inet6 ([a-f0-9\:]+)%?([\d]*)/?(\d*)?}
96
- # TODO do we have more properties on inet6 in aix? broadcast
97
- iface[interface][:addresses] ||= Mash.new
98
- iface[interface][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
93
+ elsif line =~ %r{inet6 ([a-f0-9\:]+)%?(\d*)/?(\d*)?}
94
+ # TODO: do we have more properties on inet6 in aix? broadcast
95
+ ifaces[int_name][:addresses] ||= Mash.new
96
+ ifaces[int_name][:addresses][$1] = { "family" => "inet6", "zone_index" => $2, "prefixlen" => $3 }
99
97
  else
100
- # load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
101
- properties = lin.split
102
- n = properties.length / 2 - 1
103
- (0..n).each do |i|
104
- iface[interface][properties[i * 2]] = properties[(i * 2 + 1)]
98
+ # add all key value data into the interface mash
99
+ # for example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
100
+ # has keys tcp_sendspace, tcp_recvspace, and rfc1323
101
+ line.split.each_slice(2) do |key, value|
102
+ ifaces[int_name][key] = value
105
103
  end
106
104
  end
107
105
  end
108
106
  end
109
107
 
110
108
  # Query macaddress
111
- e_so = shell_out("entstat -d #{interface} | grep \"Hardware Address\"")
112
- iface[interface][:addresses] ||= Mash.new
113
- e_so.stdout.lines.each do |l|
114
- if l =~ /Hardware Address: (\S+)/
115
- iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" }
116
- macaddress $1.upcase unless shell_out("uname -W").stdout.to_i > 0
117
- end
109
+ shell_out("entstat -d #{int_name}").stdout =~ /Hardware Address: (\S+)/
110
+ if $1
111
+ ifaces[int_name][:addresses][$1.upcase] = { "family" => "lladdr" }
112
+ macaddress $1.upcase unless shell_out("uname -W").stdout.to_i > 0
118
113
  end
119
114
  end # ifconfig stdout
120
115
 
121
116
  # Query routes information
122
117
  %w{inet inet6}.each do |family|
123
- so_n = shell_out("netstat -nrf #{family}")
124
- so_n.stdout.lines.each do |line|
118
+ shell_out("netstat -nrf #{family}").stdout.each_line do |line|
125
119
  if line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/
126
120
  interface = $6
127
- iface[interface][:routes] = [] unless iface[interface][:routes]
128
- iface[interface][:routes] << Mash.new( destination: $1, family: family,
129
- via: $2, flags: $3)
121
+ ifaces[interface][:routes] ||= []
122
+ ifaces[interface][:routes] << Mash.new( destination: $1, family: family,
123
+ via: $2, flags: $3)
130
124
  end
131
125
  end
132
126
  end
133
127
 
134
128
  # List the arp entries in system.
135
- so = shell_out("arp -an")
136
129
  count = 0
137
- so.stdout.lines.each do |line|
138
- network[:arp] ||= Mash.new
130
+ network[:arp] ||= Mash.new
131
+ shell_out("arp -an").stdout.each_line do |line|
139
132
  if line =~ /\s*(\S+) \((\S+)\) at ([a-fA-F0-9\:]+) \[(\w+)\] stored in bucket/
140
133
  network[:arp][count] ||= Mash.new
141
134
  network[:arp][count][:remote_host] = $1
@@ -144,6 +137,6 @@ Ohai.plugin(:Network) do
144
137
  count += 1
145
138
  end
146
139
  end
147
- network["interfaces"] = iface
140
+ network["interfaces"] = ifaces
148
141
  end
149
142
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  #
2
3
  # Author:: Joshua Timberman <joshua@chef.io>
3
4
  # Author:: Isa Farnik (<isa@chef.io>)
@@ -22,8 +23,8 @@ Ohai.plugin(:Platform) do
22
23
  depends "kernel"
23
24
 
24
25
  collect_data(:aix) do
25
- platform kernel[:name]
26
+ platform "aix"
27
+ platform_family "aix"
26
28
  platform_version [kernel[:version], kernel[:release]].join(".")
27
- platform_family platform
28
29
  end
29
30
  end