ohai 6.24.2 → 7.0.0.rc.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/lib/ohai.rb +1 -1
  2. data/lib/ohai/application.rb +5 -12
  3. data/lib/ohai/common/dmi.rb +126 -0
  4. data/lib/ohai/config.rb +9 -9
  5. data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
  6. data/lib/ohai/dsl/plugin.rb +186 -0
  7. data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
  8. data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
  9. data/lib/ohai/exception.rb +11 -2
  10. data/lib/ohai/hints.rb +48 -0
  11. data/lib/ohai/loader.rb +205 -0
  12. data/lib/ohai/mixin/command.rb +14 -18
  13. data/lib/ohai/mixin/constant_helper.rb +53 -0
  14. data/lib/ohai/mixin/gce_metadata.rb +0 -2
  15. data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
  16. data/lib/ohai/mixin/os.rb +59 -0
  17. data/lib/ohai/mixin/seconds_to_human.rb +48 -0
  18. data/lib/ohai/plugins/aix/cpu.rb +26 -22
  19. data/lib/ohai/plugins/aix/filesystem.rb +47 -48
  20. data/lib/ohai/plugins/aix/kernel.rb +11 -7
  21. data/lib/ohai/plugins/aix/memory.rb +8 -4
  22. data/lib/ohai/plugins/aix/network.rb +73 -82
  23. data/lib/ohai/plugins/aix/platform.rb +9 -6
  24. data/lib/ohai/plugins/aix/uptime.rb +14 -12
  25. data/lib/ohai/plugins/azure.rb +33 -11
  26. data/lib/ohai/plugins/c.rb +103 -78
  27. data/lib/ohai/plugins/chef.rb +20 -8
  28. data/lib/ohai/plugins/cloud.rb +234 -230
  29. data/lib/ohai/plugins/command.rb +6 -2
  30. data/lib/ohai/plugins/darwin/cpu.rb +10 -4
  31. data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
  32. data/lib/ohai/plugins/darwin/network.rb +157 -154
  33. data/lib/ohai/plugins/darwin/platform.rb +18 -16
  34. data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
  35. data/lib/ohai/plugins/dmi.rb +102 -102
  36. data/lib/ohai/plugins/ec2.rb +30 -28
  37. data/lib/ohai/plugins/erlang.rb +19 -16
  38. data/lib/ohai/plugins/eucalyptus.rb +37 -36
  39. data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
  40. data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
  41. data/lib/ohai/plugins/freebsd/memory.rb +35 -25
  42. data/lib/ohai/plugins/freebsd/network.rb +94 -89
  43. data/lib/ohai/plugins/freebsd/platform.rb +10 -4
  44. data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
  45. data/lib/ohai/plugins/gce.rb +30 -36
  46. data/lib/ohai/plugins/groovy.rb +14 -11
  47. data/lib/ohai/plugins/hostname.rb +132 -10
  48. data/lib/ohai/plugins/ip_scopes.rb +31 -16
  49. data/lib/ohai/plugins/java.rb +45 -21
  50. data/lib/ohai/plugins/kernel.rb +186 -19
  51. data/lib/ohai/plugins/keys.rb +6 -2
  52. data/lib/ohai/plugins/languages.rb +6 -2
  53. data/lib/ohai/plugins/linode.rb +38 -30
  54. data/lib/ohai/plugins/linux/block_device.rb +19 -15
  55. data/lib/ohai/plugins/linux/cpu.rb +42 -38
  56. data/lib/ohai/plugins/linux/filesystem.rb +70 -130
  57. data/lib/ohai/plugins/linux/lsb.rb +35 -35
  58. data/lib/ohai/plugins/linux/memory.rb +65 -61
  59. data/lib/ohai/plugins/linux/network.rb +343 -362
  60. data/lib/ohai/plugins/linux/platform.rb +90 -88
  61. data/lib/ohai/plugins/linux/virtualization.rb +95 -90
  62. data/lib/ohai/plugins/lua.rb +14 -10
  63. data/lib/ohai/plugins/mono.rb +17 -13
  64. data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
  65. data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
  66. data/lib/ohai/plugins/netbsd/memory.rb +59 -59
  67. data/lib/ohai/plugins/netbsd/network.rb +92 -88
  68. data/lib/ohai/plugins/netbsd/platform.rb +10 -3
  69. data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
  70. data/lib/ohai/plugins/network.rb +131 -130
  71. data/lib/ohai/plugins/network_listeners.rb +26 -22
  72. data/lib/ohai/plugins/nodejs.rb +14 -10
  73. data/lib/ohai/plugins/ohai.rb +11 -6
  74. data/lib/ohai/plugins/ohai_time.rb +6 -2
  75. data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
  76. data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
  77. data/lib/ohai/plugins/openbsd/memory.rb +59 -59
  78. data/lib/ohai/plugins/openbsd/network.rb +92 -88
  79. data/lib/ohai/plugins/openbsd/platform.rb +10 -4
  80. data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
  81. data/lib/ohai/plugins/openstack.rb +23 -21
  82. data/lib/ohai/plugins/os.rb +8 -32
  83. data/lib/ohai/plugins/passwd.rb +27 -22
  84. data/lib/ohai/plugins/perl.rb +21 -16
  85. data/lib/ohai/plugins/php.rb +15 -12
  86. data/lib/ohai/plugins/platform.rb +9 -9
  87. data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
  88. data/lib/ohai/plugins/python.rb +16 -12
  89. data/lib/ohai/plugins/rackspace.rb +82 -77
  90. data/lib/ohai/plugins/root_group.rb +13 -9
  91. data/lib/ohai/plugins/ruby.rb +50 -48
  92. data/lib/ohai/plugins/sigar/cpu.rb +21 -17
  93. data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
  94. data/lib/ohai/plugins/sigar/memory.rb +17 -14
  95. data/lib/ohai/plugins/sigar/network.rb +133 -67
  96. data/lib/ohai/plugins/sigar/network_route.rb +33 -28
  97. data/lib/ohai/plugins/sigar/platform.rb +10 -6
  98. data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
  99. data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
  100. data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
  101. data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
  102. data/lib/ohai/plugins/solaris2/network.rb +91 -86
  103. data/lib/ohai/plugins/solaris2/platform.rb +40 -36
  104. data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
  105. data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
  106. data/lib/ohai/plugins/ssh_host_key.rb +49 -45
  107. data/lib/ohai/plugins/uptime.rb +87 -25
  108. data/lib/ohai/plugins/virtualization.rb +59 -55
  109. data/lib/ohai/plugins/windows/cpu.rb +44 -40
  110. data/lib/ohai/plugins/windows/filesystem.rb +28 -22
  111. data/lib/ohai/plugins/windows/network.rb +88 -79
  112. data/lib/ohai/plugins/windows/platform.rb +10 -3
  113. data/lib/ohai/provides_map.rb +184 -0
  114. data/lib/ohai/runner.rb +109 -0
  115. data/lib/ohai/system.rb +103 -184
  116. data/lib/ohai/version.rb +4 -3
  117. data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
  118. data/spec/data/plugins/___lib___libc.so.6.output +135 -0
  119. data/spec/data/plugins/cc.output +135 -0
  120. data/spec/data/plugins/cl.output +135 -0
  121. data/spec/data/plugins/devenv.com.output +135 -0
  122. data/spec/data/plugins/env.output +71 -0
  123. data/spec/data/plugins/erl.output +144 -0
  124. data/spec/data/plugins/gcc.output +135 -0
  125. data/spec/data/plugins/groovy.output +159 -0
  126. data/spec/data/plugins/java.output +143 -0
  127. data/spec/data/plugins/lua.output +143 -0
  128. data/spec/data/plugins/messages.rb +8 -0
  129. data/spec/data/plugins/node.output +143 -0
  130. data/spec/data/plugins/perl.output +143 -0
  131. data/spec/data/plugins/php.output +143 -0
  132. data/spec/data/plugins/python.output +143 -0
  133. data/spec/data/plugins/uname.output +71 -0
  134. data/spec/data/plugins/v6message.rb +2 -0
  135. data/spec/data/plugins/v7message.rb +7 -0
  136. data/spec/data/plugins/what.output +135 -0
  137. data/spec/data/plugins/xlc.output +135 -0
  138. data/spec/spec_helper.rb +52 -18
  139. data/spec/support/integration_helper.rb +44 -0
  140. data/spec/unit/dsl/plugin_spec.rb +298 -0
  141. data/spec/unit/hints_spec.rb +65 -0
  142. data/spec/unit/loader_spec.rb +226 -0
  143. data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
  144. data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
  145. data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
  146. data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
  147. data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
  148. data/spec/unit/plugins/aix/network_spec.rb +66 -45
  149. data/spec/unit/plugins/aix/platform_spec.rb +11 -10
  150. data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
  151. data/spec/unit/plugins/azure_spec.rb +20 -21
  152. data/spec/unit/plugins/c_spec.rb +88 -87
  153. data/spec/unit/plugins/chef_spec.rb +5 -6
  154. data/spec/unit/plugins/cloud_spec.rb +81 -82
  155. data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
  156. data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
  157. data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
  158. data/spec/unit/plugins/darwin/network_spec.rb +375 -378
  159. data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
  160. data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
  161. data/spec/unit/plugins/dmi_spec.rb +7 -12
  162. data/spec/unit/plugins/ec2_spec.rb +70 -59
  163. data/spec/unit/plugins/erlang_spec.rb +18 -20
  164. data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
  165. data/spec/unit/plugins/fail_spec.rb +276 -23
  166. data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
  167. data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
  168. data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
  169. data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
  170. data/spec/unit/plugins/gce_spec.rb +19 -25
  171. data/spec/unit/plugins/groovy_spec.rb +10 -16
  172. data/spec/unit/plugins/hostname_spec.rb +45 -20
  173. data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
  174. data/spec/unit/plugins/java_spec.rb +145 -99
  175. data/spec/unit/plugins/kernel_spec.rb +51 -15
  176. data/spec/unit/plugins/linode_spec.rb +31 -29
  177. data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
  178. data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
  179. data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
  180. data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
  181. data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
  182. data/spec/unit/plugins/linux/network_spec.rb +196 -238
  183. data/spec/unit/plugins/linux/platform_spec.rb +186 -205
  184. data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
  185. data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
  186. data/spec/unit/plugins/lua_spec.rb +12 -15
  187. data/spec/unit/plugins/mono_spec.rb +10 -15
  188. data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
  189. data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
  190. data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
  191. data/spec/unit/plugins/network_spec.rb +358 -235
  192. data/spec/unit/plugins/nodejs_spec.rb +13 -15
  193. data/spec/unit/plugins/ohai_spec.rb +3 -4
  194. data/spec/unit/plugins/ohai_time_spec.rb +8 -9
  195. data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
  196. data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
  197. data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
  198. data/spec/unit/plugins/openstack_spec.rb +214 -0
  199. data/spec/unit/plugins/os_spec.rb +13 -16
  200. data/spec/unit/plugins/passwd_spec.rb +12 -13
  201. data/spec/unit/plugins/perl_spec.rb +20 -44
  202. data/spec/unit/plugins/php_spec.rb +20 -15
  203. data/spec/unit/plugins/platform_spec.rb +24 -29
  204. data/spec/unit/plugins/python_spec.rb +13 -17
  205. data/spec/unit/plugins/rackspace_spec.rb +90 -57
  206. data/spec/unit/plugins/root_group_spec.rb +17 -19
  207. data/spec/unit/plugins/ruby_spec.rb +15 -16
  208. data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
  209. data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
  210. data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
  211. data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
  212. data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
  213. data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
  214. data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
  215. data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
  216. data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
  217. data/spec/unit/provides_map_spec.rb +208 -0
  218. data/spec/unit/runner_spec.rb +488 -0
  219. data/spec/unit/system_spec.rb +639 -104
  220. metadata +151 -87
  221. checksums.yaml +0 -7
  222. data/lib/ohai/mixin/from_file.rb +0 -36
  223. data/lib/ohai/plugins/aix/ps.rb +0 -23
  224. data/lib/ohai/plugins/darwin/kernel.rb +0 -37
  225. data/lib/ohai/plugins/darwin/ps.rb +0 -23
  226. data/lib/ohai/plugins/darwin/uptime.rb +0 -32
  227. data/lib/ohai/plugins/dmi_common.rb +0 -121
  228. data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
  229. data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
  230. data/lib/ohai/plugins/freebsd/ps.rb +0 -24
  231. data/lib/ohai/plugins/hpux/cpu.rb +0 -19
  232. data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
  233. data/lib/ohai/plugins/hpux/hostname.rb +0 -19
  234. data/lib/ohai/plugins/hpux/memory.rb +0 -19
  235. data/lib/ohai/plugins/hpux/network.rb +0 -19
  236. data/lib/ohai/plugins/hpux/platform.rb +0 -19
  237. data/lib/ohai/plugins/hpux/ps.rb +0 -23
  238. data/lib/ohai/plugins/hpux/uptime.rb +0 -19
  239. data/lib/ohai/plugins/linux/hostname.rb +0 -40
  240. data/lib/ohai/plugins/linux/ps.rb +0 -23
  241. data/lib/ohai/plugins/linux/uptime.rb +0 -28
  242. data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
  243. data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
  244. data/lib/ohai/plugins/netbsd/ps.rb +0 -24
  245. data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
  246. data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
  247. data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
  248. data/lib/ohai/plugins/openbsd/ps.rb +0 -24
  249. data/lib/ohai/plugins/sigar/hostname.rb +0 -28
  250. data/lib/ohai/plugins/sigar/uptime.rb +0 -27
  251. data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
  252. data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
  253. data/lib/ohai/plugins/solaris2/ps.rb +0 -23
  254. data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
  255. data/lib/ohai/plugins/windows/hostname.rb +0 -33
  256. data/lib/ohai/plugins/windows/kernel.rb +0 -58
  257. data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
  258. data/lib/ohai/plugins/windows/uptime.rb +0 -23
  259. data/spec/unit/mixin/from_file_spec.rb +0 -53
@@ -16,19 +16,23 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "languages/nodejs"
19
+ Ohai.plugin(:Nodejs) do
20
+ provides "languages/nodejs"
20
21
 
21
- require_plugin "languages"
22
+ depends "languages"
22
23
 
23
- output = nil
24
+ collect_data do
25
+ output = nil
24
26
 
25
- nodejs = Mash.new
27
+ nodejs = Mash.new
26
28
 
27
- status, stdout, stderr = run_command(:no_status_check => true, :command => "node -v")
28
- if status == 0
29
- output = stdout.split
30
- if output.length >= 1
31
- nodejs[:version] = output[0][1..output[0].length]
29
+ so = shell_out("node -v")
30
+ if so.exitstatus == 0
31
+ output = so.stdout.split
32
+ if output.length >= 1
33
+ nodejs[:version] = output[0][1..output[0].length]
34
+ end
35
+ languages[:nodejs] = nodejs if nodejs[:version]
36
+ end
32
37
  end
33
- languages[:nodejs] = nodejs if nodejs[:version]
34
38
  end
@@ -16,10 +16,15 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "ohai"
20
- provides "ohai"
19
+ Ohai.plugin(:Ohai) do
20
+ provides "chef_packages/ohai"
21
21
 
22
- self[:chef_packages] = Mash.new unless self[:chef_packages]
23
- self[:chef_packages][:ohai] = Mash.new
24
- self[:chef_packages][:ohai][:version] = Ohai::VERSION
25
- self[:chef_packages][:ohai][:ohai_root] = Ohai::OHAI_ROOT
22
+ collect_data do
23
+ require 'ohai'
24
+
25
+ chef_packages Mash.new unless chef_packages
26
+ chef_packages[:ohai] = Mash.new
27
+ chef_packages[:ohai][:version] = Ohai::VERSION
28
+ chef_packages[:ohai][:ohai_root] = Ohai::OHAI_ROOT
29
+ end
30
+ end
@@ -16,6 +16,10 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "ohai_time"
19
+ Ohai.plugin(:OhaiTime) do
20
+ provides "ohai_time"
20
21
 
21
- ohai_time Time.now.to_f
22
+ collect_data do
23
+ ohai_time Time.now.to_f
24
+ end
25
+ end
@@ -16,23 +16,28 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides 'cpu'
19
+ Ohai.plugin(:CPU) do
20
+ provides 'cpu'
20
21
 
21
- cpuinfo = Mash.new
22
+ collect_data(:openbsd) do
23
+ cpuinfo = Mash.new
22
24
 
23
- # OpenBSD provides most cpu information via sysctl, the only thing we need to
24
- # to scrape from dmesg.boot is the cpu feature list.
25
- # cpu0: FPU,V86,DE,PSE,TSC,MSR,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,PAT,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,TM,SBF,EST,TM2
25
+ # OpenBSD provides most cpu information via sysctl, the only thing we need to
26
+ # to scrape from dmesg.boot is the cpu feature list.
27
+ # cpu0: FPU,V86,DE,PSE,TSC,MSR,MCE,CX8,SEP,MTRR,PGE,MCA,CMOV,PAT,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,TM,SBF,EST,TM2
26
28
 
27
- File.open("/var/run/dmesg.boot").each do |line|
28
- case line
29
- when /cpu\d+:\s+([A-Z]+$|[A-Z]+,.*$)/
30
- cpuinfo["flags"] = $1.downcase.split(',')
31
- end
32
- end
29
+ File.open("/var/run/dmesg.boot").each do |line|
30
+ case line
31
+ when /cpu\d+:\s+([A-Z]+$|[A-Z]+,.*$)/
32
+ cpuinfo["flags"] = $1.downcase.split(',')
33
+ end
34
+ end
33
35
 
34
- cpuinfo[:model_name] = from("sysctl -n hw.model")
35
- cpuinfo[:total] = from("sysctl -n hw.ncpu")
36
- cpuinfo[:mhz] = from("sysctl -n hw.cpuspeed")
36
+ [["hw.model", :model_name], ["hw.ncpu", :total], ["hw.cpuspeed", :mhz]].each do |param, node|
37
+ so = shell_out("sysctl -n #{param}")
38
+ cpuinfo[node] = so.stdout.split($/)[0]
39
+ end
37
40
 
38
- cpu cpuinfo
41
+ cpu cpuinfo
42
+ end
43
+ end
@@ -16,42 +16,42 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "filesystem"
19
+ Ohai.plugin(:Filesystem) do
20
+ provides "filesystem"
20
21
 
21
- fs = Mash.new
22
+ collect_data(:openbsd) do
23
+ fs = Mash.new
22
24
 
23
- # Grab filesystem data from df
24
- popen4("df") do |pid, stdin, stdout, stderr|
25
- stdin.close
26
- stdout.each do |line|
27
- case line
28
- when /^Filesystem/
29
- next
30
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
31
- filesystem = $1
32
- fs[filesystem] = Mash.new
33
- fs[filesystem]['kb_size'] = $2
34
- fs[filesystem]['kb_used'] = $3
35
- fs[filesystem]['kb_available'] = $4
36
- fs[filesystem]['percent_used'] = $5
37
- fs[filesystem]['mount'] = $6
25
+ # Grab filesystem data from df
26
+ so = shell_out("df")
27
+ so.stdout.lines do |line|
28
+ case line
29
+ when /^Filesystem/
30
+ next
31
+ when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
32
+ filesystem = $1
33
+ fs[filesystem] = Mash.new
34
+ fs[filesystem]['kb_size'] = $2
35
+ fs[filesystem]['kb_used'] = $3
36
+ fs[filesystem]['kb_available'] = $4
37
+ fs[filesystem]['percent_used'] = $5
38
+ fs[filesystem]['mount'] = $6
39
+ end
38
40
  end
39
- end
40
- end
41
41
 
42
- # Grab mount information from mount
43
- popen4("mount -l") do |pid, stdin, stdout, stderr|
44
- stdin.close
45
- stdout.each do |line|
46
- if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
47
- filesystem = $1
48
- fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
49
- fs[filesystem]['mount'] = $2
50
- fs[filesystem]['fs_type'] = $3
51
- fs[filesystem]['mount-options'] = $4.split(/,\s*/)
42
+ # Grab mount information from mount
43
+ so = shell_out("mount -l")
44
+ so.stdout.lines do |line|
45
+ if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/
46
+ filesystem = $1
47
+ fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
48
+ fs[filesystem]['mount'] = $2
49
+ fs[filesystem]['fs_type'] = $3
50
+ fs[filesystem]['mount-options'] = $4.split(/,\s*/)
51
+ end
52
52
  end
53
+
54
+ # Set the filesystem data
55
+ filesystem fs
53
56
  end
54
57
  end
55
-
56
- # Set the filesystem data
57
- filesystem fs
@@ -16,54 +16,55 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "memory"
19
+ Ohai.plugin(:Memory) do
20
+ provides "memory", "memory/swap"
20
21
 
21
- memory Mash.new
22
- memory[:swap] = Mash.new
22
+ collect_data(:openbsd) do
23
+ memory Mash.new
24
+ memory[:swap] = Mash.new
23
25
 
24
- # $ vmstat -s
25
- # 4096 bytes per page
26
- # 514011 pages managed
27
- # 224519 pages free
28
- # 209339 pages active
29
- # 4647 pages inactive
30
- # 0 pages being paged out
31
- # 5 pages wired
32
- # 0 pages zeroed
33
- # 4 pages reserved for pagedaemon
34
- # 6 pages reserved for kernel
35
- # 262205 swap pages
36
- # 0 swap pages in use
37
- # 0 total anon's in system
38
- # 0 free anon's
39
- # 1192991609 page faults
40
- # 1369579301 traps
41
- # 814549706 interrupts
42
- # 771702498 cpu context switches
43
- # 208810590 fpu context switches
44
- # 492361360 software interrupts
45
- # 1161998825 syscalls
46
- # 0 pagein operations
47
- # 0 swap ins
48
- # 0 swap outs
49
- # 768352 forks
50
- # 16 forks where vmspace is shared
51
- # 1763 kernel map entries
52
- # 0 number of times the pagedaemon woke up
53
- # 0 revolutions of the clock hand
54
- # 0 pages freed by pagedaemon
55
- # 0 pages scanned by pagedaemon
56
- # 0 pages reactivated by pagedaemon
57
- # 0 busy pages found by pagedaemon
58
- # 1096393776 total name lookups
59
- # cache hits (37% pos + 2% neg) system 1% per-directory
60
- # deletions 0%, falsehits 6%, toolong 26%
61
- # 0 select collisions
26
+ # $ vmstat -s
27
+ # 4096 bytes per page
28
+ # 514011 pages managed
29
+ # 224519 pages free
30
+ # 209339 pages active
31
+ # 4647 pages inactive
32
+ # 0 pages being paged out
33
+ # 5 pages wired
34
+ # 0 pages zeroed
35
+ # 4 pages reserved for pagedaemon
36
+ # 6 pages reserved for kernel
37
+ # 262205 swap pages
38
+ # 0 swap pages in use
39
+ # 0 total anon's in system
40
+ # 0 free anon's
41
+ # 1192991609 page faults
42
+ # 1369579301 traps
43
+ # 814549706 interrupts
44
+ # 771702498 cpu context switches
45
+ # 208810590 fpu context switches
46
+ # 492361360 software interrupts
47
+ # 1161998825 syscalls
48
+ # 0 pagein operations
49
+ # 0 swap ins
50
+ # 0 swap outs
51
+ # 768352 forks
52
+ # 16 forks where vmspace is shared
53
+ # 1763 kernel map entries
54
+ # 0 number of times the pagedaemon woke up
55
+ # 0 revolutions of the clock hand
56
+ # 0 pages freed by pagedaemon
57
+ # 0 pages scanned by pagedaemon
58
+ # 0 pages reactivated by pagedaemon
59
+ # 0 busy pages found by pagedaemon
60
+ # 1096393776 total name lookups
61
+ # cache hits (37% pos + 2% neg) system 1% per-directory
62
+ # deletions 0%, falsehits 6%, toolong 26%
63
+ # 0 select collisions
62
64
 
63
- popen4("vmstat -s") do |pid, stdin, stdout, stderr|
64
- stdin.close
65
- stdout.each do |line|
66
- case line
65
+ so = shell_out("vmstat -s")
66
+ so.stdout.lines do |line|
67
+ case line
67
68
  when /(\d+) bytes per page/
68
69
  memory[:page_size] = $1
69
70
  when /(\d+) pages managed/
@@ -78,21 +79,20 @@ popen4("vmstat -s") do |pid, stdin, stdout, stderr|
78
79
  when /(\d+) pages wired/
79
80
  memory[:wired] = memory[:page_size].to_i * $1.to_i
80
81
  end
81
- end
82
- end
82
+ end
83
83
 
84
- popen4("swapctl -l") do |pid, stdin, stdout, stderr|
85
- stdin.close
86
- stdout.each do |line|
87
- # Device 1024-blocks Used Avail Capacity Priority
88
- # swap_device 1048824 0 1048824 0% 0
89
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
90
- mdev = $1
91
- memory[:swap][mdev] = Mash.new
92
- memory[:swap][mdev][:total] = $2
93
- memory[:swap][mdev][:used] = $3
94
- memory[:swap][mdev][:free] = $4
95
- memory[:swap][mdev][:percent_free] = $5
84
+ so = shell_out("swapctl -l")
85
+ so.stdout.lines do |line|
86
+ # Device 1024-blocks Used Avail Capacity Priority
87
+ # swap_device 1048824 0 1048824 0% 0
88
+ if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
89
+ mdev = $1
90
+ memory[:swap][mdev] = Mash.new
91
+ memory[:swap][mdev][:total] = $2
92
+ memory[:swap][mdev][:used] = $3
93
+ memory[:swap][mdev][:free] = $4
94
+ memory[:swap][mdev][:percent_free] = $5
95
+ end
96
96
  end
97
97
  end
98
98
  end
@@ -16,105 +16,109 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- provides "network", "counters/network"
19
+ Ohai.plugin(:Network) do
20
+ provides "network", "network/interfaces"
21
+ provides "counters/network", "counters/network/interfaces"
20
22
 
21
- from("route -n get default").split("\n").each do |line|
22
- if line =~ /(\w+): ([\w\.]+)/
23
- case $1
24
- when "gateway"
25
- network[:default_gateway] = $2
26
- when "interface"
27
- network[:default_interface] = $2
28
- end
29
- end
30
- end
23
+ collect_data(:openbsd) do
24
+ network Mash.new unless network
25
+ network[:interfaces] = Mash.new unless network[:interfaces]
26
+ counters Mash.new unless counters
27
+ counters[:network] = Mash.new unless counters[:network]
31
28
 
32
- iface = Mash.new
33
- popen4("/sbin/ifconfig -a") do |pid, stdin, stdout, stderr|
34
- stdin.close
35
- cint = nil
36
- stdout.each do |line|
37
- if line =~ /^([0-9a-zA-Z\.]+):\s+/
38
- cint = $1
39
- iface[cint] = Mash.new
40
- if cint =~ /^(\w+)(\d+.*)/
41
- iface[cint][:type] = $1
42
- iface[cint][:number] = $2
29
+ so = shell_out("route -n get default")
30
+ so.stdout.lines do |line|
31
+ if line =~ /(\w+): ([\w\.]+)/
32
+ case $1
33
+ when "gateway"
34
+ network[:default_gateway] = $2
35
+ when "interface"
36
+ network[:default_interface] = $2
37
+ end
43
38
  end
44
39
  end
45
- # call the family lladdr to match linux for consistency
46
- if line =~ /\s+lladdr (.+?)\s/
47
- iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
48
- iface[cint][:addresses][$1] = { "family" => "lladdr" }
49
- end
50
- if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/
51
- iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
52
- # convert the netmask to decimal for consistency
53
- netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}"
54
- if $3.empty?
55
- iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask }
56
- else
57
- # found a broadcast address
58
- iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 }
40
+
41
+ iface = Mash.new
42
+ so = shell_out( "#{ Ohai.abs_path( "/sbin/ifconfig" ) } -a" )
43
+ cint = nil
44
+ so.stdout.lines do |line|
45
+ if line =~ /^([0-9a-zA-Z\.]+):\s+/
46
+ cint = $1
47
+ iface[cint] = Mash.new
48
+ if cint =~ /^(\w+)(\d+.*)/
49
+ iface[cint][:type] = $1
50
+ iface[cint][:number] = $2
51
+ end
59
52
  end
60
- end
61
- if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/
62
- iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
63
- if $4.empty?
64
- iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 }
65
- else
66
- #found a zone_id / scope
67
- iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 }
53
+ # call the family lladdr to match linux for consistency
54
+ if line =~ /\s+lladdr (.+?)\s/
55
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
56
+ iface[cint][:addresses][$1] = { "family" => "lladdr" }
57
+ end
58
+ if line =~ /\s+inet ([\d.]+) netmask ([\da-fx]+)\s*\w*\s*([\d.]*)/
59
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
60
+ # convert the netmask to decimal for consistency
61
+ netmask = "#{$2[2,2].hex}.#{$2[4,2].hex}.#{$2[6,2].hex}.#{$2[8,2].hex}"
62
+ if $3.empty?
63
+ iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask }
64
+ else
65
+ # found a broadcast address
66
+ iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => netmask, "broadcast" => $3 }
67
+ end
68
+ end
69
+ if line =~ /\s+inet6 ([a-f0-9\:]+)%?(\w*)\s+prefixlen\s+(\d+)\s*\w*\s*([\da-fx]*)/
70
+ iface[cint][:addresses] = Mash.new unless iface[cint][:addresses]
71
+ if $4.empty?
72
+ iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $3 }
73
+ else
74
+ #found a zone_id / scope
75
+ iface[cint][:addresses][$1] = { "family" => "inet6", "zoneid" => $2, "prefixlen" => $3, "scopeid" => $4 }
76
+ end
77
+ end
78
+ if line =~ /flags=\d+<(.+)>/
79
+ flags = $1.split(',')
80
+ iface[cint][:flags] = flags if flags.length > 0
81
+ end
82
+ if line =~ /metric: (\d+) mtu: (\d+)/
83
+ iface[cint][:metric] = $1
84
+ iface[cint][:mtu] = $2
68
85
  end
69
86
  end
70
- if line =~ /flags=\d+<(.+)>/
71
- flags = $1.split(',')
72
- iface[cint][:flags] = flags if flags.length > 0
73
- end
74
- if line =~ /metric: (\d+) mtu: (\d+)/
75
- iface[cint][:metric] = $1
76
- iface[cint][:mtu] = $2
77
- end
78
- end
79
- end
80
87
 
81
- popen4("arp -an") do |pid, stdin, stdout, stderr|
82
- stdin.close
83
- stdout.each do |line|
84
- if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
85
- next unless iface[$3] # this should never happen
86
- iface[$3][:arp] = Mash.new unless iface[$3][:arp]
87
- iface[$3][:arp][$1] = $2.downcase
88
+ so = shell_out("arp -an")
89
+ so.stdout.lines do |line|
90
+ if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
91
+ next unless iface[$3] # this should never happen
92
+ iface[$3][:arp] = Mash.new unless iface[$3][:arp]
93
+ iface[$3][:arp][$1] = $2.downcase
94
+ end
88
95
  end
89
- end
90
- end
91
96
 
92
- network["interfaces"] = iface
97
+ network["interfaces"] = iface
93
98
 
94
- net_counters = Mash.new
95
- # From netstat(1), not sure of the implications:
96
- # Show the state of all network interfaces or a single interface
97
- # which have been auto-configured (interfaces statically configured
98
- # into a system, but not located at boot time are not shown).
99
- popen4("netstat -idn") do |pid, stdin, stdout, stderr|
100
- stdin.close
101
- stdout.each do |line|
102
- # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop
103
- # em0 1500 <Link> 00:11:25:2d:90:be 3719557 0 3369969 0 0 0
104
- # $1 $2 $3 $4 $5 $6 $7 $8
105
- if line =~ /^([\w\.\*]+)\s+\d+\s+<Link>\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/
106
- cint = $1
107
- net_counters[cint] = Mash.new unless net_counters[cint]
108
- net_counters[cint] = Mash.new unless net_counters[cint]["rx"]
109
- net_counters[cint] = Mash.new unless net_counters[cint]["tx"]
110
- net_counters[cint] = $3
111
- net_counters[cint] = $4
112
- net_counters[cint] = $5
113
- net_counters[cint] = $6
114
- net_counters[cint] = $7
115
- net_counters[cint] = $8
99
+ net_counters = Mash.new
100
+ # From netstat(1), not sure of the implications:
101
+ # Show the state of all network interfaces or a single interface
102
+ # which have been auto-configured (interfaces statically configured
103
+ # into a system, but not located at boot time are not shown).
104
+ so = shell_out("netstat -idn")
105
+ so.stdout.lines do |line|
106
+ # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll Drop
107
+ # em0 1500 <Link> 00:11:25:2d:90:be 3719557 0 3369969 0 0 0
108
+ # $1 $2 $3 $4 $5 $6 $7 $8
109
+ if line =~ /^([\w\.\*]+)\s+\d+\s+<Link>\s+([\w:]*)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/
110
+ net_counters[$1] = Mash.new unless net_counters[$1]
111
+ net_counters[$1]["rx"] = Mash.new unless net_counters[$1]["rx"]
112
+ net_counters[$1]["tx"] = Mash.new unless net_counters[$1]["tx"]
113
+ net_counters[$1]["rx"]["packets"] = $3
114
+ net_counters[$1]["rx"]["errors"] = $4
115
+ net_counters[$1]["tx"]["packets"] = $5
116
+ net_counters[$1]["tx"]["errors"] = $6
117
+ net_counters[$1]["tx"]["collisions"] = $7
118
+ net_counters[$1]["tx"]["dropped"] = $8
119
+ end
116
120
  end
121
+
122
+ counters[:network][:interfaces] = net_counters
117
123
  end
118
124
  end
119
-
120
- counters[:network][:interfaces] = net_counters