ohai 8.26.1 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +3 -4
  3. data/Rakefile +14 -0
  4. data/lib/ohai/application.rb +1 -0
  5. data/lib/ohai/config.rb +2 -88
  6. data/lib/ohai/dsl/plugin.rb +0 -4
  7. data/lib/ohai/exception.rb +0 -1
  8. data/lib/ohai/loader.rb +11 -2
  9. data/lib/ohai/log.rb +3 -1
  10. data/lib/ohai/mixin/command.rb +1 -318
  11. data/lib/ohai/mixin/do_metadata.rb +47 -0
  12. data/lib/ohai/mixin/ec2_metadata.rb +2 -29
  13. data/lib/ohai/mixin/gce_metadata.rb +0 -37
  14. data/lib/ohai/mixin/http_helper.rb +56 -0
  15. data/lib/ohai/mixin/network_constants.rb +0 -5
  16. data/lib/ohai/plugins/cloud.rb +144 -157
  17. data/lib/ohai/plugins/darwin/filesystem.rb +68 -22
  18. data/lib/ohai/plugins/digital_ocean.rb +24 -42
  19. data/lib/ohai/plugins/dmi.rb +81 -77
  20. data/lib/ohai/plugins/ec2.rb +33 -60
  21. data/lib/ohai/plugins/gce.rb +3 -1
  22. data/lib/ohai/plugins/hostname.rb +1 -16
  23. data/lib/ohai/plugins/linux/filesystem.rb +130 -81
  24. data/lib/ohai/plugins/linux/mdadm.rb +3 -45
  25. data/lib/ohai/plugins/linux/network.rb +1 -26
  26. data/lib/ohai/plugins/linux/platform.rb +4 -2
  27. data/lib/ohai/plugins/linux/virtualization.rb +1 -5
  28. data/lib/ohai/plugins/scala.rb +1 -13
  29. data/lib/ohai/plugins/solaris2/network.rb +1 -2
  30. data/lib/ohai/plugins/uptime.rb +0 -9
  31. data/lib/ohai/plugins/windows/cpu.rb +2 -1
  32. data/lib/ohai/plugins/windows/network.rb +1 -1
  33. data/lib/ohai/runner.rb +0 -5
  34. data/lib/ohai/system.rb +38 -8
  35. data/lib/ohai/version.rb +2 -2
  36. data/ohai.gemspec +1 -1
  37. data/spec/functional/application_spec.rb +0 -40
  38. data/spec/functional/plugins/powershell_spec.rb +1 -1
  39. data/spec/functional/plugins/root_group_spec.rb +1 -1
  40. data/spec/functional/plugins/windows/uptime_spec.rb +1 -1
  41. data/spec/ohai_spec.rb +1 -1
  42. data/spec/support/integration_helper.rb +17 -0
  43. data/spec/support/platform_helpers.rb +17 -0
  44. data/spec/unit/application_spec.rb +0 -1
  45. data/spec/unit/config_spec.rb +0 -111
  46. data/spec/unit/dsl/plugin_spec.rb +1 -1
  47. data/spec/unit/hints_spec.rb +1 -1
  48. data/spec/unit/loader_spec.rb +26 -1
  49. data/spec/unit/mixin/command_spec.rb +1 -69
  50. data/spec/unit/mixin/ec2_metadata_spec.rb +1 -1
  51. data/spec/unit/mixin/softlayer_metadata_spec.rb +1 -1
  52. data/spec/unit/plugin_config_spec.rb +0 -1
  53. data/spec/unit/plugins/abort_spec.rb +1 -1
  54. data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
  55. data/spec/unit/plugins/aix/filesystem_spec.rb +2 -1
  56. data/spec/unit/plugins/aix/hostname_spec.rb +1 -1
  57. data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
  58. data/spec/unit/plugins/aix/memory_spec.rb +1 -1
  59. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  60. data/spec/unit/plugins/aix/os_spec.rb +1 -1
  61. data/spec/unit/plugins/aix/platform_spec.rb +1 -1
  62. data/spec/unit/plugins/aix/uptime_spec.rb +1 -1
  63. data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
  64. data/spec/unit/plugins/azure_spec.rb +1 -1
  65. data/spec/unit/plugins/bsd/filesystem_spec.rb +1 -1
  66. data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
  67. data/spec/unit/plugins/c_spec.rb +1 -1
  68. data/spec/unit/plugins/chef_spec.rb +1 -2
  69. data/spec/unit/plugins/cloud_spec.rb +210 -50
  70. data/spec/unit/plugins/darwin/cpu_spec.rb +1 -1
  71. data/spec/unit/plugins/darwin/filesystem_spec.rb +62 -13
  72. data/spec/unit/plugins/darwin/hardware_spec.rb +2 -2
  73. data/spec/unit/plugins/darwin/hostname_spec.rb +1 -1
  74. data/spec/unit/plugins/darwin/kernel_spec.rb +1 -1
  75. data/spec/unit/plugins/darwin/memory_spec.rb +1 -1
  76. data/spec/unit/plugins/darwin/network_spec.rb +1 -1
  77. data/spec/unit/plugins/darwin/platform_spec.rb +1 -1
  78. data/spec/unit/plugins/darwin/system_profiler_spec.rb +2 -9
  79. data/spec/unit/plugins/darwin/virtualization_spec.rb +1 -1
  80. data/spec/unit/plugins/digital_ocean_spec.rb +39 -110
  81. data/spec/unit/plugins/dmi_spec.rb +1 -1
  82. data/spec/unit/plugins/ec2_spec.rb +10 -62
  83. data/spec/unit/plugins/elixir_spec.rb +1 -1
  84. data/spec/unit/plugins/erlang_spec.rb +1 -1
  85. data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
  86. data/spec/unit/plugins/fail_spec.rb +1 -1
  87. data/spec/unit/plugins/freebsd/cpu_spec.rb +1 -1
  88. data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
  89. data/spec/unit/plugins/freebsd/kernel_spec.rb +1 -1
  90. data/spec/unit/plugins/freebsd/os_spec.rb +1 -1
  91. data/spec/unit/plugins/freebsd/platform_spec.rb +1 -1
  92. data/spec/unit/plugins/gce_spec.rb +1 -1
  93. data/spec/unit/plugins/go_spec.rb +1 -1
  94. data/spec/unit/plugins/groovy_spec.rb +1 -1
  95. data/spec/unit/plugins/haskell_spec.rb +1 -1
  96. data/spec/unit/plugins/hostname_spec.rb +16 -41
  97. data/spec/unit/plugins/init_package_spec.rb +1 -1
  98. data/spec/unit/plugins/ip_scopes_spec.rb +18 -6
  99. data/spec/unit/plugins/java_spec.rb +1 -1
  100. data/spec/unit/plugins/joyent_spec.rb +17 -1
  101. data/spec/unit/plugins/kernel_spec.rb +1 -1
  102. data/spec/unit/plugins/linode_spec.rb +1 -1
  103. data/spec/unit/plugins/linux/block_device_spec.rb +1 -1
  104. data/spec/unit/plugins/linux/cpu_spec.rb +1 -2
  105. data/spec/unit/plugins/linux/filesystem_spec.rb +207 -201
  106. data/spec/unit/plugins/linux/fips_spec.rb +1 -1
  107. data/spec/unit/plugins/linux/hostname_spec.rb +1 -1
  108. data/spec/unit/plugins/linux/hostnamectl_spec.rb +1 -1
  109. data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
  110. data/spec/unit/plugins/linux/lsb_spec.rb +1 -1
  111. data/spec/unit/plugins/linux/machineid_spec.rb +1 -1
  112. data/spec/unit/plugins/linux/mdadm_spec.rb +2 -68
  113. data/spec/unit/plugins/linux/memory_spec.rb +1 -1
  114. data/spec/unit/plugins/linux/network_spec.rb +3 -44
  115. data/spec/unit/plugins/linux/platform_spec.rb +4 -4
  116. data/spec/unit/plugins/linux/sessions_spec.rb +1 -1
  117. data/spec/unit/plugins/linux/uptime_spec.rb +1 -1
  118. data/spec/unit/plugins/linux/virtualization_spec.rb +1 -28
  119. data/spec/unit/plugins/lua_spec.rb +1 -1
  120. data/spec/unit/plugins/mono_spec.rb +1 -1
  121. data/spec/unit/plugins/netbsd/hostname_spec.rb +1 -1
  122. data/spec/unit/plugins/netbsd/kernel_spec.rb +1 -1
  123. data/spec/unit/plugins/netbsd/platform_spec.rb +1 -1
  124. data/spec/unit/plugins/network_spec.rb +1 -1
  125. data/spec/unit/plugins/nodejs_spec.rb +1 -1
  126. data/spec/unit/plugins/ohai_spec.rb +1 -1
  127. data/spec/unit/plugins/ohai_time_spec.rb +1 -1
  128. data/spec/unit/plugins/openbsd/hostname_spec.rb +1 -1
  129. data/spec/unit/plugins/openbsd/kernel_spec.rb +1 -1
  130. data/spec/unit/plugins/openbsd/platform_spec.rb +1 -1
  131. data/spec/unit/plugins/openstack_spec.rb +2 -3
  132. data/spec/unit/plugins/os_spec.rb +1 -1
  133. data/spec/unit/plugins/packages_spec.rb +1 -1
  134. data/spec/unit/plugins/passwd_spec.rb +17 -1
  135. data/spec/unit/plugins/perl_spec.rb +1 -1
  136. data/spec/unit/plugins/php_spec.rb +1 -1
  137. data/spec/unit/plugins/platform_spec.rb +1 -1
  138. data/spec/unit/plugins/powershell_spec.rb +1 -1
  139. data/spec/unit/plugins/python_spec.rb +1 -1
  140. data/spec/unit/plugins/rackspace_spec.rb +1 -2
  141. data/spec/unit/plugins/root_group_spec.rb +2 -2
  142. data/spec/unit/plugins/ruby_spec.rb +1 -1
  143. data/spec/unit/plugins/rust_spec.rb +1 -1
  144. data/spec/unit/plugins/scala_spec.rb +3 -37
  145. data/spec/unit/plugins/shard_spec.rb +1 -1
  146. data/spec/unit/plugins/shells_spec.rb +1 -1
  147. data/spec/unit/plugins/softlayer_spec.rb +1 -1
  148. data/spec/unit/plugins/solaris2/cpu_spec.rb +1 -1
  149. data/spec/unit/plugins/solaris2/dmi_spec.rb +1 -1
  150. data/spec/unit/plugins/solaris2/hostname_spec.rb +1 -1
  151. data/spec/unit/plugins/solaris2/kernel_spec.rb +1 -1
  152. data/spec/unit/plugins/solaris2/memory_spec.rb +1 -1
  153. data/spec/unit/plugins/solaris2/network_spec.rb +7 -4
  154. data/spec/unit/plugins/solaris2/platform_spec.rb +1 -1
  155. data/spec/unit/plugins/solaris2/virtualization_spec.rb +1 -1
  156. data/spec/unit/plugins/solaris2/zpools_spec.rb +1 -1
  157. data/spec/unit/plugins/ssh_host_keys_spec.rb +1 -1
  158. data/spec/unit/plugins/sysconf_spec.rb +1 -1
  159. data/spec/unit/plugins/timezone_spec.rb +1 -1
  160. data/spec/unit/plugins/virtualbox_spec.rb +1 -1
  161. data/spec/unit/plugins/vmware_spec.rb +2 -1
  162. data/spec/unit/plugins/windows/cpu_spec.rb +9 -2
  163. data/spec/unit/plugins/windows/fips_spec.rb +1 -1
  164. data/spec/unit/plugins/windows/memory_spec.rb +1 -1
  165. data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
  166. data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
  167. data/spec/unit/provides_map_spec.rb +1 -1
  168. data/spec/unit/runner_spec.rb +1 -1
  169. data/spec/unit/system_spec.rb +68 -76
  170. data/spec/unit/util/file_helper_spec.rb +1 -1
  171. data/spec/unit/util/ip_helper_spec.rb +1 -1
  172. metadata +6 -20
  173. data/lib/ohai/plugins/cloud_v2.rb +0 -315
  174. data/lib/ohai/plugins/darwin/filesystem2.rb +0 -107
  175. data/lib/ohai/plugins/linux/filesystem2.rb +0 -223
  176. data/lib/ohai/plugins/linux/lspci.rb +0 -76
  177. data/lib/ohai/plugins/network_listeners.rb +0 -60
  178. data/lib/ohai/plugins/sigar/cpu.rb +0 -44
  179. data/lib/ohai/plugins/sigar/filesystem.rb +0 -50
  180. data/lib/ohai/plugins/sigar/memory.rb +0 -39
  181. data/lib/ohai/plugins/sigar/network.rb +0 -168
  182. data/lib/ohai/plugins/sigar/network_route.rb +0 -64
  183. data/lib/ohai/plugins/sigar/platform.rb +0 -30
  184. data/spec/unit/plugins/cloud_v2_spec.rb +0 -389
  185. data/spec/unit/plugins/darwin/filesystem2_spec.rb +0 -139
  186. data/spec/unit/plugins/linux/filesystem2_spec.rb +0 -437
  187. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  188. data/spec/unit/plugins/sigar/network_route_spec.rb +0 -148
@@ -1,76 +0,0 @@
1
- #
2
- # Author:: Joerg Herzinger <joerg.herzinger@oiml.at>
3
- # Author:: Phil Dibowitz <phil@ipom.com>
4
- # Copyright:: Copyright (c) 2011 GLOBAL 2000/Friends of the Earth Austria
5
- # Copyright:: Copyright (c) 2017 Facebook, Inc.
6
- # License:: Apache License, Version 2.0
7
- #
8
- # Licensed under the Apache License, Version 2.0 (the "License");
9
- # you may not use this file except in compliance with the License.
10
- # You may obtain a copy of the License at
11
- #
12
- # http://www.apache.org/licenses/LICENSE-2.0
13
- #
14
- # Unless required by applicable law or agreed to in writing, software
15
- # distributed under the License is distributed on an "AS IS" BASIS,
16
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- # See the License for the specific language governing permissions and
18
- # limitations under the License.
19
-
20
- Ohai.plugin(:Lspci) do
21
- depends "platform"
22
- provides "pci"
23
-
24
- collect_data(:linux) do
25
- devices = Mash.new
26
- lspci = shell_out("lspci -vnnmk")
27
-
28
- h = /[0-9a-fA-F]/ #any hex digit
29
- hh = /#{h}#{h}/ #any 2 hex digits
30
- hhhh = /#{h}#{h}#{h}#{h}/ #any 4 hex digits
31
-
32
- d_id = String.new #This identifies our pci devices
33
-
34
- def standard_form(devices, d_id, hhhh, tag, line)
35
- tmp = line.scan(/(.*)\s\[(#{hhhh})\]/)[0]
36
- devices[d_id]["#{tag}_name"] = tmp[0]
37
- devices[d_id]["#{tag}_id"] = tmp[1]
38
- end
39
-
40
- def standard_array(devices, d_id, tag, line)
41
- if !devices[d_id][tag].kind_of?(Array)
42
- devices[d_id][tag] = [line]
43
- else
44
- devices[d_id][tag].push(line)
45
- end
46
- end
47
-
48
- lspci.stdout.split("\n").each do |line|
49
- dev = line.scan(/^(.*):\s(.*)$/)[0]
50
- next if dev.nil?
51
- case dev[0]
52
- when "Device" # There are two different Device tags
53
- if tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/)
54
- # We have a device id
55
- d_id = tmp[0] # From now on we will need this id
56
- devices[d_id] = Mash.new
57
- else
58
- standard_form(devices, d_id, hhhh, "device", dev[1])
59
- end
60
- when "Class"
61
- standard_form(devices, d_id, hhhh, "class", dev[1])
62
- when "Vendor"
63
- standard_form(devices, d_id, hhhh, "vendor", dev[1])
64
- when "Driver"
65
- standard_array(devices, d_id, "driver", dev[1])
66
- when "Module"
67
- standard_array(devices, d_id, "module", dev[1])
68
- when "SDevice"
69
- standard_form(devices, d_id, hhhh, "sdevice", dev[1])
70
- else
71
- end
72
- end
73
-
74
- pci devices
75
- end
76
- end
@@ -1,60 +0,0 @@
1
- #
2
- # Author:: Doug MacEachern <dougm@vmware.com>
3
- # Copyright:: Copyright (c) 2009 VMware, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- Ohai.plugin(:NetworkListeners) do
20
- provides "network/listeners"
21
-
22
- depends "network", "counters/network"
23
-
24
- collect_data do
25
- begin
26
- require "sigar"
27
- flags = Sigar::NETCONN_TCP | Sigar::NETCONN_SERVER
28
-
29
- network Mash.new unless network
30
- listeners = Mash.new
31
-
32
- sigar = Sigar.new
33
- sigar.net_connection_list(flags).each do |conn|
34
- port = conn.local_port
35
- addr = conn.local_address.to_s
36
- if addr == "0.0.0.0" || addr == "::"
37
- addr = "*"
38
- end
39
- listeners[port] = Mash.new
40
- listeners[port][:address] = addr
41
- begin
42
- pid = sigar.proc_port(conn.type, port)
43
- # workaround for a failure of proc_state to throw
44
- # after the first 0 has been supplied to it
45
- #
46
- # no longer required when hyperic/sigar#48 is fixed
47
- throw ArgumentError.new("No such process") if pid == 0
48
- listeners[port][:pid] = pid
49
- listeners[port][:name] = sigar.proc_state(pid).name
50
- rescue
51
- end
52
- end
53
-
54
- network[:listeners] = Mash.new
55
- network[:listeners][:tcp] = listeners
56
- rescue LoadError
57
- Ohai::Log.debug("Could not load sigar gem. Skipping NetworkListeners plugin")
58
- end
59
- end
60
- end
@@ -1,44 +0,0 @@
1
- #
2
- # Author:: Doug MacEachern <dougm@vmware.com>
3
- # Copyright:: Copyright (c) 2010 VMware, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- Ohai.plugin(:CPU) do
20
- provides "cpu"
21
-
22
- collect_data(:hpux, :default) do
23
- require "sigar"
24
-
25
- sigar = Sigar.new
26
-
27
- cpuinfo = Mash.new
28
- ix = 0
29
-
30
- sigar.cpu_info_list.each do |info|
31
- current_cpu = ix.to_s
32
- ix += 1
33
- cpuinfo[current_cpu] = Mash.new
34
- cpuinfo[current_cpu]["vendor_id"] = info.vendor
35
- cpuinfo[current_cpu]["model"] = info.model
36
- cpuinfo[current_cpu]["mhz"] = info.mhz.to_s
37
- cpuinfo[current_cpu]["cache_size"] = info.cache_size.to_s
38
- cpuinfo[:total] = info.total_cores
39
- cpuinfo[:real] = info.total_sockets
40
- end
41
-
42
- cpu cpuinfo
43
- end
44
- end
@@ -1,50 +0,0 @@
1
- #
2
- # Author:: Doug MacEachern <dougm@vmware.com>
3
- # Copyright:: Copyright (c) 2010 VMware, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- Ohai.plugin(:Filesystem) do
20
- provides "filesystem"
21
-
22
- collect_data(:hpux, :default) do
23
- require "sigar"
24
- sigar = Sigar.new
25
-
26
- fs = Mash.new
27
-
28
- sigar.file_system_list.each do |fsys|
29
- filesystem = fsys.dev_name
30
- fs[filesystem] = Mash.new
31
- fs[filesystem][:mount] = fsys.dir_name
32
- fs[filesystem][:fs_type] = fsys.sys_type_name
33
- fs[filesystem][:mount_options] = fsys.options
34
- begin
35
- usage = sigar.file_system_usage(fsys.dir_name)
36
- fs[filesystem][:kb_size] = (usage.total / 1024).to_s
37
- fs[filesystem][:kb_used] = ((usage.total - usage.free) / 1024).to_s
38
- fs[filesystem][:kb_available] = (usage.free / 1024).to_s
39
- fs[filesystem][:percent_used] = (usage.use_percent * 100).to_s + "%"
40
- rescue SystemExit => e
41
- raise
42
- rescue Exception => e
43
- #e.g. floppy or cdrom drive
44
- end
45
- end
46
-
47
- # Set the filesystem data
48
- filesystem fs
49
- end
50
- end
@@ -1,39 +0,0 @@
1
- #
2
- # Author:: Doug MacEachern <dougm@vmware.com>
3
- # Copyright:: Copyright (c) 2010 VMware, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- Ohai.plugin(:Memory) do
20
- provides "memory"
21
-
22
- collect_data(:hpux, :default) do
23
- require "sigar"
24
- sigar = Sigar.new
25
-
26
- memory Mash.new
27
- memory[:swap] = Mash.new
28
-
29
- mem = sigar.mem
30
- swap = sigar.swap
31
-
32
- memory[:total] = (mem.total / 1024).to_s + "kB"
33
- memory[:free] = (mem.free / 1024).to_s + "kB"
34
- memory[:used] = (mem.used / 1024).to_s + "kB"
35
- memory[:swap][:total] = (swap.total / 1024).to_s + "kB"
36
- memory[:swap][:free] = (swap.free / 1024).to_s + "kB"
37
- memory[:swap][:used] = (swap.used / 1024).to_s + "kB"
38
- end
39
- end
@@ -1,168 +0,0 @@
1
- #
2
- # Author:: Matthew Kent (<mkent@magoazul.com>)
3
- # Copyright:: Copyright (c) 2009 Matthew Kent
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "ohai/mixin/network_constants"
20
-
21
- Ohai.plugin(:Network) do
22
- include Ohai::Mixin::NetworkConstants
23
-
24
- provides "network", "network/interfaces"
25
- provides "counters/network", "counters/network/interfaces"
26
-
27
- def sigar_encaps_lookup(encap)
28
- return "Loopback" if encap.eql?("Local Loopback")
29
- return "PPP" if encap.eql?("Point-to-Point Protocol")
30
- return "SLIP" if encap.eql?("Serial Line IP")
31
- return "VJSLIP" if encap.eql?("VJ Serial Line IP")
32
- return "IPIP" if encap.eql?("IPIP Tunnel")
33
- return "6to4" if encap.eql?("IPv6-in-IPv4")
34
- encap
35
- end
36
-
37
- def fetch_interfaces(sigar)
38
- iface = Mash.new
39
- net_counters = Mash.new
40
-
41
- sigar.net_interface_list.each do |cint|
42
- iface[cint] = Mash.new
43
-
44
- if cint =~ /^(\w+)(\d+.*)/
45
- iface[cint][:type] = $1
46
- iface[cint][:number] = $2
47
- end
48
-
49
- ifconfig = sigar.net_interface_config(cint)
50
- iface[cint][:encapsulation] = sigar_encaps_lookup(ifconfig.type)
51
-
52
- iface[cint][:addresses] = Mash.new
53
- # Backwards compat: loopback has no hwaddr
54
- if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0
55
- iface[cint][:addresses][ifconfig.hwaddr] = { "family" => "lladdr" }
56
- end
57
- if ifconfig.address != "0.0.0.0"
58
- iface[cint][:addresses][ifconfig.address] = { "family" => "inet" }
59
- # Backwards compat: no broadcast on tunnel or loopback dev
60
- if ((ifconfig.flags & Sigar::IFF_POINTOPOINT) == 0) &&
61
- ((ifconfig.flags & Sigar::IFF_LOOPBACK) == 0)
62
- iface[cint][:addresses][ifconfig.address]["broadcast"] = ifconfig.broadcast
63
- end
64
- iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask
65
- end
66
-
67
- if ifconfig.prefix6_length != 0
68
- iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" }
69
- iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s
70
- iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6)
71
- end
72
-
73
- iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(" ")
74
- iface[cint][:mtu] = ifconfig.mtu.to_s
75
- iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s
76
-
77
- net_counters[cint] = Mash.new unless net_counters[cint]
78
- if !cint.include?(":")
79
- ifstat = sigar.net_interface_stat(cint)
80
- net_counters[cint][:rx] = { "packets" => ifstat.rx_packets.to_s, "errors" => ifstat.rx_errors.to_s,
81
- "drop" => ifstat.rx_dropped.to_s, "overrun" => ifstat.rx_overruns.to_s,
82
- "frame" => ifstat.rx_frame.to_s, "bytes" => ifstat.rx_bytes.to_s }
83
- net_counters[cint][:tx] = { "packets" => ifstat.tx_packets.to_s, "errors" => ifstat.tx_errors.to_s,
84
- "drop" => ifstat.tx_dropped.to_s, "overrun" => ifstat.tx_overruns.to_s,
85
- "carrier" => ifstat.tx_carrier.to_s, "collisions" => ifstat.tx_collisions.to_s,
86
- "bytes" => ifstat.tx_bytes.to_s }
87
- end
88
- end
89
-
90
- begin
91
- sigar.arp_list.each do |arp|
92
- next unless iface[arp.ifname] # this should never happen
93
- iface[arp.ifname][:arp] = Mash.new unless iface[arp.ifname][:arp]
94
- iface[arp.ifname][:arp][arp.address] = arp.hwaddr
95
- end
96
- rescue
97
- #64-bit AIX for example requires 64-bit caller
98
- end
99
-
100
- [iface, net_counters]
101
- end
102
-
103
- # sigar-only, from network_route plugin
104
- def flags(flags)
105
- f = ""
106
- if (flags & Sigar::RTF_UP) != 0
107
- f += "U"
108
- end
109
- if (flags & Sigar::RTF_GATEWAY) != 0
110
- f += "G"
111
- end
112
- if (flags & Sigar::RTF_HOST) != 0
113
- f += "H"
114
- end
115
- f
116
- end
117
-
118
- collect_data(:hpux) do
119
- require "sigar"
120
- sigar = Sigar.new
121
-
122
- network Mash.new unless network
123
- network[:interfaces] = Mash.new unless network[:interfaces]
124
- counters Mash.new unless counters
125
- counters[:network] = Mash.new unless counters[:network]
126
-
127
- ninfo = sigar.net_info
128
- network[:default_interface] = ninfo.default_gateway_interface
129
- network[:default_gateway] = ninfo.default_gateway
130
-
131
- iface, net_counters = fetch_interfaces(sigar)
132
- counters[:network][:interfaces] = net_counters
133
- network["interfaces"] = iface
134
- end
135
-
136
- collect_data(:default) do
137
- require "sigar"
138
- sigar = Sigar.new
139
-
140
- network Mash.new unless network
141
- network[:interfaces] = Mash.new unless network[:interfaces]
142
- counters Mash.new unless counters
143
- counters[:network] = Mash.new unless counters[:network]
144
-
145
- ninfo = sigar.net_info
146
- network[:default_interface] = ninfo.default_gateway_interface
147
- network[:default_gateway] = ninfo.default_gateway
148
-
149
- iface, net_counters = fetch_interfaces(sigar)
150
- counters[:network][:interfaces] = net_counters
151
- network[:interfaces] = iface
152
-
153
- sigar.net_route_list.each do |route|
154
- next unless network[:interfaces][route.ifname] # this
155
- # should never happen
156
- network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
157
- route_data = {}
158
- Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
159
- if m == :flags
160
- route_data[m] = flags(route.send(m))
161
- else
162
- route_data[m] = route.send(m)
163
- end
164
- end
165
- network[:interfaces][route.ifname][:route][route.destination] = route_data
166
- end
167
- end
168
- end
@@ -1,64 +0,0 @@
1
- #
2
- # Author:: Toomas Pelberg (<toomas.pelberg@playtech.com>)
3
- # Copyright:: Copyright (c) 2011-2016 Chef Software, Inc.
4
- # License:: Apache License, Version 2.0
5
- #
6
- # Licensed under the Apache License, Version 2.0 (the "License");
7
- # you may not use this file except in compliance with the License.
8
- # You may obtain a copy of the License at
9
- #
10
- # http://www.apache.org/licenses/LICENSE-2.0
11
- #
12
- # Unless required by applicable law or agreed to in writing, software
13
- # distributed under the License is distributed on an "AS IS" BASIS,
14
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
- # See the License for the specific language governing permissions and
16
- # limitations under the License.
17
- #
18
-
19
- require "ohai/mixin/network_constants"
20
-
21
- Ohai.plugin(:NetworkRoutes) do
22
- begin
23
- require "sigar"
24
-
25
- include Ohai::Mixin::NetworkConstants
26
-
27
- provides "network/interfaces/adapters/route"
28
- depends "network/interfaces"
29
-
30
- def flags(flags)
31
- f = ""
32
- if (flags & Sigar::RTF_UP) != 0
33
- f += "U"
34
- end
35
- if (flags & Sigar::RTF_GATEWAY) != 0
36
- f += "G"
37
- end
38
- if (flags & Sigar::RTF_HOST) != 0
39
- f += "H"
40
- end
41
- f
42
- end
43
-
44
- collect_data(:default) do
45
- sigar = Sigar.new
46
-
47
- sigar.net_route_list.each do |route|
48
- next unless network[:interfaces][route.ifname] # this should never happen
49
- network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
50
- route_data = {}
51
- Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
52
- if m == :flags
53
- route_data[m] = flags(route.send(m))
54
- else
55
- route_data[m] = route.send(m)
56
- end
57
- end
58
- network[:interfaces][route.ifname][:route][route.destination] = route_data
59
- end
60
- end
61
- rescue LoadError
62
- Ohai::Log.debug("Could not load sigar gem. Skipping NetworkRoutes plugin")
63
- end
64
- end