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,87 +16,153 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- #http://github.com/mdkent/ohai/commit/92f51aa18b6add9682510a87dcf94835ea72b04d
19
+ require 'ohai/mixin/network_constants'
20
20
 
21
- require "sigar"
21
+ Ohai.plugin(:Network) do
22
+ include Ohai::Mixin::NetworkConstants
22
23
 
23
- sigar = Sigar.new
24
+ provides "network", "network/interfaces"
25
+ provides "counters/network", "counters/network/interfaces"
24
26
 
25
- provides "network", "counters/network"
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
26
36
 
27
- ninfo = sigar.net_info
37
+ def fetch_interfaces(sigar)
38
+ iface = Mash.new
39
+ net_counters = Mash.new
28
40
 
29
- network[:default_interface] = ninfo.default_gateway_interface
41
+ sigar.net_interface_list.each do |cint|
42
+ iface[cint] = Mash.new
30
43
 
31
- network[:default_gateway] = ninfo.default_gateway
44
+ if cint =~ /^(\w+)(\d+.*)/
45
+ iface[cint][:type] = $1
46
+ iface[cint][:number] = $2
47
+ end
32
48
 
33
- def encaps_lookup(encap)
34
- return "Loopback" if encap.eql?("Local Loopback")
35
- return "PPP" if encap.eql?("Point-to-Point Protocol")
36
- return "SLIP" if encap.eql?("Serial Line IP")
37
- return "VJSLIP" if encap.eql?("VJ Serial Line IP")
38
- return "IPIP" if encap.eql?("IPIP Tunnel")
39
- return "6to4" if encap.eql?("IPv6-in-IPv4")
40
- encap
41
- end
49
+ ifconfig = sigar.net_interface_config(cint)
50
+ iface[cint][:encapsulation] = sigar_encaps_lookup(ifconfig.type)
42
51
 
43
- iface = Mash.new
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
44
66
 
45
- net_counters = Mash.new
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
46
72
 
47
- sigar.net_interface_list.each do |cint|
48
- iface[cint] = Mash.new
49
- if cint =~ /^(\w+)(\d+.*)/
50
- iface[cint][:type] = $1
51
- iface[cint][:number] = $2
52
- end
53
- ifconfig = sigar.net_interface_config(cint)
54
- iface[cint][:encapsulation] = encaps_lookup(ifconfig.type)
55
- iface[cint][:addresses] = Mash.new
56
- # Backwards compat: loopback has no hwaddr
57
- if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0
58
- iface[cint][:addresses][ifconfig.hwaddr] = { "family" => "lladdr" }
59
- end
60
- if ifconfig.address != "0.0.0.0"
61
- iface[cint][:addresses][ifconfig.address] = { "family" => "inet" }
62
- # Backwards compat: no broadcast on tunnel or loopback dev
63
- if (((ifconfig.flags & Sigar::IFF_POINTOPOINT) == 0) &&
64
- ((ifconfig.flags & Sigar::IFF_LOOPBACK) == 0))
65
- iface[cint][:addresses][ifconfig.address]["broadcast"] = ifconfig.broadcast
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
66
88
  end
67
- iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask
68
- end
69
- iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(' ')
70
- iface[cint][:mtu] = ifconfig.mtu.to_s
71
- iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s
72
- if ifconfig.prefix6_length != 0
73
- iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" }
74
- iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s
75
- iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6)
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]
76
101
  end
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 }
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
87
116
  end
88
- end
89
117
 
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
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
95
134
  end
96
- rescue
97
- #64-bit AIX for example requires 64-bit caller
98
- end
99
135
 
100
- counters[:network][:interfaces] = net_counters
136
+ collect_data(:default) do
137
+ require "sigar"
138
+ sigar = Sigar.new
101
139
 
102
- network["interfaces"] = iface
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
@@ -16,39 +16,44 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "sigar"
20
- require_plugin "network"
19
+ require 'ohai/mixin/network_constants'
21
20
 
22
- provides "network"
21
+ Ohai.plugin(:NetworkRoutes) do
22
+ include Ohai::Mixin::NetworkConstants
23
23
 
24
- def flags(flags)
25
- f = ""
26
- if (flags & Sigar::RTF_UP) != 0
27
- f += "U"
28
- end
29
- if (flags & Sigar::RTF_GATEWAY) != 0
30
- f += "G"
31
- end
32
- if (flags & Sigar::RTF_HOST) != 0
33
- f += "H"
24
+ provides "network/interfaces/adapters/route"
25
+ depends "network/interfaces"
26
+
27
+ def flags(flags)
28
+ f = ""
29
+ if (flags & Sigar::RTF_UP) != 0
30
+ f += "U"
31
+ end
32
+ if (flags & Sigar::RTF_GATEWAY) != 0
33
+ f += "G"
34
+ end
35
+ if (flags & Sigar::RTF_HOST) != 0
36
+ f += "H"
37
+ end
38
+ f
34
39
  end
35
- f
36
- end
37
40
 
38
- # From sigar: include/sigar.h sigar_net_route_t
39
- SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname]
41
+ collect_data(:default) do
42
+ require "sigar"
43
+ sigar = Sigar.new
40
44
 
41
- sigar=Sigar.new
42
- sigar.net_route_list.each do |route|
43
- next unless network[:interfaces][route.ifname] # this should never happen
44
- network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
45
- route_data={}
46
- SIGAR_ROUTE_METHODS.each do |m|
47
- if(m == :flags)
48
- route_data[m]=flags(route.send(m))
49
- else
50
- route_data[m]=route.send(m)
45
+ sigar.net_route_list.each do |route|
46
+ next unless network[:interfaces][route.ifname] # this should never happen
47
+ network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route]
48
+ route_data={}
49
+ Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m|
50
+ if(m == :flags)
51
+ route_data[m]=flags(route.send(m))
52
+ else
53
+ route_data[m]=route.send(m)
54
+ end
55
+ end
56
+ network[:interfaces][route.ifname][:route][route.destination] = route_data
51
57
  end
52
58
  end
53
- network[:interfaces][route.ifname][:route][route.destination] = route_data
54
59
  end
@@ -16,11 +16,15 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require "sigar"
19
+ Ohai.plugin(:Platform) do
20
+ provides "platform", "platform_version", "platform_family"
20
21
 
21
- provides "platform", "platform_version"
22
+ collect_data(:hpux) do
23
+ require "sigar"
24
+ sys = Sigar.new.sys_info
22
25
 
23
- sys = Sigar.new.sys_info
24
-
25
- platform sys.name.downcase
26
- platform_version sys.version
26
+ platform sys.name.downcase
27
+ platform_version sys.version
28
+ platform_family platform
29
+ end
30
+ end
@@ -1,33 +1,41 @@
1
- #$ psrinfo -v
2
- #Status of virtual processor 0 as of: 01/11/2009 23:31:55
3
- # on-line since 05/29/2008 15:05:28.
4
- # The i386 processor operates at 2660 MHz,
5
- # and has an i387 compatible floating point processor.
6
- #Status of virtual processor 1 as of: 01/11/2009 23:31:55
7
- # on-line since 05/29/2008 15:05:30.
8
- # The i386 processor operates at 2660 MHz,
9
- # and has an i387 compatible floating point processor.
10
- #Status of virtual processor 2 as of: 01/11/2009 23:31:55
11
- # on-line since 05/29/2008 15:05:30.
12
- # The i386 processor operates at 2660 MHz,
13
- # and has an i387 compatible floating point processor.
14
- #Status of virtual processor 3 as of: 01/11/2009 23:31:55
15
- # on-line since 05/29/2008 15:05:30.
16
- # The i386 processor operates at 2660 MHz,
17
- # and has an i387 compatible floating point processor.
18
- #Status of virtual processor 4 as of: 01/11/2009 23:31:55
19
- # on-line since 05/29/2008 15:05:30.
20
- # The i386 processor operates at 2660 MHz,
21
- # and has an i387 compatible floating point processor.
22
- #Status of virtual processor 5 as of: 01/11/2009 23:31:55
23
- # on-line since 05/29/2008 15:05:30.
24
- # The i386 processor operates at 2660 MHz,
25
- # and has an i387 compatible floating point processor.
26
- #Status of virtual processor 6 as of: 01/11/2009 23:31:55
27
- # on-line since 05/29/2008 15:05:30.
28
- # The i386 processor operates at 2660 MHz,
29
- # and has an i387 compatible floating point processor.
30
- #Status of virtual processor 7 as of: 01/11/2009 23:31:55
31
- # on-line since 05/29/2008 15:05:30.
32
- # The i386 processor operates at 2660 MHz,
33
- # and has an i387 compatible floating point processor.
1
+ #
2
+ # License:: Apache License, Version 2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ Ohai.plugin(:CPU) do
18
+ provides "cpu"
19
+
20
+ collect_data(:solaris2) do
21
+ cpu Mash.new
22
+ cpu[:total] = shell_out("psrinfo | wc -l").stdout.to_i
23
+ cpu[:real] = shell_out("psrinfo -p").stdout.to_i
24
+
25
+ processor_info = shell_out("psrinfo -v -p | grep Hz").stdout
26
+ processors = processor_info.split(/^ [^\s]/)
27
+ processors.each_with_index do |processor, i|
28
+ cpu_info, model_name = processor.split("\n ")
29
+ cpu_info = cpu_info.tr("()","").split
30
+
31
+ index = i.to_s
32
+ cpu[index] = Mash.new
33
+ cpu[index]['vendor_id'] = cpu_info[1]
34
+ cpu[index]['family'] = cpu_info[4]
35
+ cpu[index]['model'] = cpu_info[6]
36
+ cpu[index]['stepping'] = cpu_info[8]
37
+ cpu[index]['model_name'] = model_name.strip
38
+ cpu[index]['mhz'] = cpu_info[10]
39
+ end
40
+ end
41
+ end
@@ -16,161 +16,161 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
- require_plugin "dmi"
19
+ Ohai.plugin(:DMI) do
20
20
 
21
- # if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios
22
- # note that a single key just means dmidecode exited with its version
23
- if (dmi.class.to_s == 'Mash') and (dmi.keys.length > 1)
24
- Ohai::Log.debug('skipping smbios output, since DMI information has already been provided')
25
- return
26
- end
27
-
28
- dmi Mash.new
29
-
30
- # bad Solaris shows strings defined by system instead of SMB IDs
31
- # this is what the *real* IDs are:
32
- # pulled from http://src.opensolaris.org/source/xref/nwam/nwam1/usr/src/uts/common/sys/smbios.h
33
- smb_to_id = {
34
- 'SMB_TYPE_BIOS' => 0, # BIOS information (R)
35
- 'SMB_TYPE_SYSTEM' => 1, # system information (R)
36
- 'SMB_TYPE_BASEBOARD' => 2, # base board
37
- 'SMB_TYPE_CHASSIS' => 3, # system enclosure or chassis (R)
38
- 'SMB_TYPE_PROCESSOR' => 4, # processor (R)
39
- 'SMB_TYPE_MEMCTL' => 5, # memory controller (O)
40
- 'SMB_TYPE_MEMMOD' => 6, # memory module (O)
41
- 'SMB_TYPE_CACHE' => 7, # processor cache (R)
42
- 'SMB_TYPE_PORT' => 8, # port connector
43
- 'SMB_TYPE_SLOT' => 9, # upgradeable system slot (R)
44
- 'SMB_TYPE_OBDEVS' => 10, # on-board devices
45
- 'SMB_TYPE_OEMSTR' => 11, # OEM string table
46
- 'SMB_TYPE_SYSCONFSTR' => 12, # system configuration string table
47
- 'SMB_TYPE_LANG' => 13, # BIOS language information
48
- 'SMB_TYPE_GROUP' => 14, # group associations
49
- 'SMB_TYPE_EVENTLOG' => 15, # system event log
50
- 'SMB_TYPE_MEMARRAY' => 16, # physical memory array (R)
51
- 'SMB_TYPE_MEMDEVICE' => 17, # memory device (R)
52
- 'SMB_TYPE_MEMERR32' => 18, # 32-bit memory error information
53
- 'SMB_TYPE_MEMARRAYMAP' => 19, # memory array mapped address (R)
54
- 'SMB_TYPE_MEMDEVICEMAP' => 20, # memory device mapped address (R)
55
- 'SMB_TYPE_POINTDEV' => 21, # built-in pointing device
56
- 'SMB_TYPE_BATTERY' => 22, # portable battery
57
- 'SMB_TYPE_RESET' => 23, # system reset settings
58
- 'SMB_TYPE_SECURITY' => 24, # hardware security settings
59
- 'SMB_TYPE_POWERCTL' => 25, # system power controls
60
- 'SMB_TYPE_VPROBE' => 26, # voltage probe
61
- 'SMB_TYPE_COOLDEV' => 27, # cooling device
62
- 'SMB_TYPE_TPROBE' => 28, # temperature probe
63
- 'SMB_TYPE_IPROBE' => 29, # current probe
64
- 'SMB_TYPE_OOBRA' => 30, # out-of-band remote access facility
65
- 'SMB_TYPE_BIS' => 31, # boot integrity services
66
- 'SMB_TYPE_BOOT' => 32, # system boot status (R)
67
- 'SMB_TYPE_MEMERR64' => 33, # 64-bit memory error information
68
- 'SMB_TYPE_MGMTDEV' => 34, # management device
69
- 'SMB_TYPE_MGMTDEVCP' => 35, # management device component
70
- 'SMB_TYPE_MGMTDEVDATA' => 36, # management device threshold data
71
- 'SMB_TYPE_MEMCHAN' => 37, # memory channel
72
- 'SMB_TYPE_IPMIDEV' => 38, # IPMI device information
73
- 'SMB_TYPE_POWERSUP' => 39, # system power supply
74
- 'SMB_TYPE_INACTIVE' => 126, # inactive table entry
75
- 'SMB_TYPE_EOT' => 127, # end of table
76
- 'SMB_TYPE_OEM_LO' => 128, # start of OEM-specific type range
77
- 'SUN_OEM_EXT_PROCESSOR' => 132, # processor extended info
78
- 'SUN_OEM_PCIEXRC' => 138, # PCIE RootComplex/RootPort info
79
- 'SUN_OEM_EXT_MEMARRAY' => 144, # phys memory array extended info
80
- 'SUN_OEM_EXT_MEMDEVICE' => 145, # memory device extended info
81
- 'SMB_TYPE_OEM_HI' => 256, # end of OEM-specific type range
82
- }
83
-
84
- # all output lines should fall within one of these patterns
85
- header_type_line = /^ID\s+SIZE\s+TYPE/
86
- header_information_line = /^(\d+)\s+(\d+)\s+(\S+)\s+\(([^\)]+)\)/
87
- blank_line = /^\s*$/
88
- data_key_value_line = /^ ([^:]+): (.*)/
89
- data_key_only_line = /^ (\S.*)(:\s*)?$/
90
- extended_data_line = /^\t(\S+) \((.+)\)/
91
-
92
- dmi_record = nil
93
- field = nil
94
-
95
- popen4("smbios") do |pid, stdin, stdout, stderr|
96
- stdin.close
97
-
98
- # ==== EXAMPLE: ====
99
- # ID SIZE TYPE
100
- # 0 40 SMB_TYPE_BIOS (BIOS information)
101
- #
102
- # Vendor: HP
103
- # Version String: 2.16
104
- # ... similar lines trimmed
105
- # Characteristics: 0x7fc9da80
106
- # SMB_BIOSFL_PCI (PCI is supported)
107
- # ... similar lines trimmed
108
- # note the second level of indentation is via a *tab*
109
- stdout.each do |raw_line|
110
- next if header_type_line.match(raw_line)
111
- next if blank_line.match(raw_line)
112
-
113
- # remove/replace any characters that don't fall inside permissible ASCII range, or whitespace
114
- line = raw_line.gsub(/[^\x20-\x7E\n\t\r]/, '.')
115
- if (line != raw_line)
116
- Ohai::Log.debug("converted characters from line:\n#{raw_line}")
21
+ collect_data(:solaris2) do
22
+ # if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios
23
+ # note that a single key just means dmidecode exited with its version
24
+ if (dmi.class.to_s == 'Mash') and (dmi.keys.length > 1)
25
+ Ohai::Log.debug('skipping smbios output, since DMI information has already been provided')
26
+ return
117
27
  end
118
28
 
119
- if header_information = header_information_line.match(line)
120
- dmi_record = {}
29
+ dmi Mash.new
121
30
 
122
- # look up SMB ID
123
- if smb_to_id.has_key?(header_information[3])
124
- dmi_record[:type] = DMI.id_lookup(smb_to_id[header_information[3]])
31
+ # bad Solaris shows strings defined by system instead of SMB IDs
32
+ # this is what the *real* IDs are:
33
+ # pulled from http://src.opensolaris.org/source/xref/nwam/nwam1/usr/src/uts/common/sys/smbios.h
34
+ smb_to_id = {
35
+ 'SMB_TYPE_BIOS' => 0, # BIOS information (R)
36
+ 'SMB_TYPE_SYSTEM' => 1, # system information (R)
37
+ 'SMB_TYPE_BASEBOARD' => 2, # base board
38
+ 'SMB_TYPE_CHASSIS' => 3, # system enclosure or chassis (R)
39
+ 'SMB_TYPE_PROCESSOR' => 4, # processor (R)
40
+ 'SMB_TYPE_MEMCTL' => 5, # memory controller (O)
41
+ 'SMB_TYPE_MEMMOD' => 6, # memory module (O)
42
+ 'SMB_TYPE_CACHE' => 7, # processor cache (R)
43
+ 'SMB_TYPE_PORT' => 8, # port connector
44
+ 'SMB_TYPE_SLOT' => 9, # upgradeable system slot (R)
45
+ 'SMB_TYPE_OBDEVS' => 10, # on-board devices
46
+ 'SMB_TYPE_OEMSTR' => 11, # OEM string table
47
+ 'SMB_TYPE_SYSCONFSTR' => 12, # system configuration string table
48
+ 'SMB_TYPE_LANG' => 13, # BIOS language information
49
+ 'SMB_TYPE_GROUP' => 14, # group associations
50
+ 'SMB_TYPE_EVENTLOG' => 15, # system event log
51
+ 'SMB_TYPE_MEMARRAY' => 16, # physical memory array (R)
52
+ 'SMB_TYPE_MEMDEVICE' => 17, # memory device (R)
53
+ 'SMB_TYPE_MEMERR32' => 18, # 32-bit memory error information
54
+ 'SMB_TYPE_MEMARRAYMAP' => 19, # memory array mapped address (R)
55
+ 'SMB_TYPE_MEMDEVICEMAP' => 20, # memory device mapped address (R)
56
+ 'SMB_TYPE_POINTDEV' => 21, # built-in pointing device
57
+ 'SMB_TYPE_BATTERY' => 22, # portable battery
58
+ 'SMB_TYPE_RESET' => 23, # system reset settings
59
+ 'SMB_TYPE_SECURITY' => 24, # hardware security settings
60
+ 'SMB_TYPE_POWERCTL' => 25, # system power controls
61
+ 'SMB_TYPE_VPROBE' => 26, # voltage probe
62
+ 'SMB_TYPE_COOLDEV' => 27, # cooling device
63
+ 'SMB_TYPE_TPROBE' => 28, # temperature probe
64
+ 'SMB_TYPE_IPROBE' => 29, # current probe
65
+ 'SMB_TYPE_OOBRA' => 30, # out-of-band remote access facility
66
+ 'SMB_TYPE_BIS' => 31, # boot integrity services
67
+ 'SMB_TYPE_BOOT' => 32, # system boot status (R)
68
+ 'SMB_TYPE_MEMERR64' => 33, # 64-bit memory error information
69
+ 'SMB_TYPE_MGMTDEV' => 34, # management device
70
+ 'SMB_TYPE_MGMTDEVCP' => 35, # management device component
71
+ 'SMB_TYPE_MGMTDEVDATA' => 36, # management device threshold data
72
+ 'SMB_TYPE_MEMCHAN' => 37, # memory channel
73
+ 'SMB_TYPE_IPMIDEV' => 38, # IPMI device information
74
+ 'SMB_TYPE_POWERSUP' => 39, # system power supply
75
+ 'SMB_TYPE_INACTIVE' => 126, # inactive table entry
76
+ 'SMB_TYPE_EOT' => 127, # end of table
77
+ 'SMB_TYPE_OEM_LO' => 128, # start of OEM-specific type range
78
+ 'SUN_OEM_EXT_PROCESSOR' => 132, # processor extended info
79
+ 'SUN_OEM_PCIEXRC' => 138, # PCIE RootComplex/RootPort info
80
+ 'SUN_OEM_EXT_MEMARRAY' => 144, # phys memory array extended info
81
+ 'SUN_OEM_EXT_MEMDEVICE' => 145, # memory device extended info
82
+ 'SMB_TYPE_OEM_HI' => 256, # end of OEM-specific type range
83
+ }
125
84
 
126
- else
127
- dmi_record[:type] = header_information[3].downcase
128
- Ohai::Log.debug("unrecognized header type; falling back to #{dmi_record[:type]}")
129
- end
85
+ # all output lines should fall within one of these patterns
86
+ header_type_line = /^ID\s+SIZE\s+TYPE/
87
+ header_information_line = /^(\d+)\s+(\d+)\s+(\S+)\s+\(([^\)]+)\)/
88
+ blank_line = /^\s*$/
89
+ data_key_value_line = /^ ([^:]+): (.*)/
90
+ data_key_only_line = /^ (\S.*)(:\s*)?$/
91
+ extended_data_line = /^\t(\S+) \((.+)\)/
130
92
 
131
- dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
132
- dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records)
133
- dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length
134
- dmi[dmi_record[:type]][:all_records].push(Mash.new)
135
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = header_information[1]
136
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = header_information[2]
137
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = header_information[4]
138
- field = nil
139
-
140
- elsif data = data_key_value_line.match(line)
141
- if dmi_record == nil
142
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
143
- next
144
- end
145
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
146
- field = data[1]
147
-
148
- elsif data = data_key_only_line.match(line)
149
- if dmi_record == nil
150
- Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
151
- next
152
- end
153
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = ''
154
- field = data[1]
155
-
156
- elsif extended_data = extended_data_line.match(line)
157
- if dmi_record == nil
158
- Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}")
159
- next
160
- end
161
- if field == nil
162
- Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}")
163
- next
93
+ dmi_record = nil
94
+ field = nil
95
+
96
+ so = shell_out("smbios")
97
+ # ==== EXAMPLE: ====
98
+ # ID SIZE TYPE
99
+ # 0 40 SMB_TYPE_BIOS (BIOS information)
100
+ #
101
+ # Vendor: HP
102
+ # Version String: 2.16
103
+ # ... similar lines trimmed
104
+ # Characteristics: 0x7fc9da80
105
+ # SMB_BIOSFL_PCI (PCI is supported)
106
+ # ... similar lines trimmed
107
+ # note the second level of indentation is via a *tab*
108
+ so.stdout.lines do |raw_line|
109
+ next if header_type_line.match(raw_line)
110
+ next if blank_line.match(raw_line)
111
+
112
+ # remove/replace any characters that don't fall inside permissible ASCII range, or whitespace
113
+ line = raw_line.gsub(/[^\x20-\x7E\n\t\r]/, '.')
114
+ if (line != raw_line)
115
+ Ohai::Log.debug("converted characters from line:\n#{raw_line}")
164
116
  end
165
- # overwrite "raw" value with a new Mash
166
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == 'Mash'
167
- dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2]
168
117
 
169
- else
170
- Ohai::Log.debug("unrecognized output line; discarding:\n#{line}")
118
+ if header_information = header_information_line.match(line)
119
+ dmi_record = {}
120
+
121
+ # look up SMB ID
122
+ if smb_to_id.has_key?(header_information[3])
123
+ dmi_record[:type] = DMI.id_lookup(smb_to_id[header_information[3]])
171
124
 
125
+ else
126
+ dmi_record[:type] = header_information[3].downcase
127
+ Ohai::Log.debug("unrecognized header type; falling back to #{dmi_record[:type]}")
128
+ end
129
+
130
+ dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type])
131
+ dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records)
132
+ dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length
133
+ dmi[dmi_record[:type]][:all_records].push(Mash.new)
134
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = header_information[1]
135
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = header_information[2]
136
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = header_information[4]
137
+ field = nil
138
+
139
+ elsif data = data_key_value_line.match(line)
140
+ if dmi_record == nil
141
+ Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
142
+ next
143
+ end
144
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2]
145
+ field = data[1]
146
+
147
+ elsif data = data_key_only_line.match(line)
148
+ if dmi_record == nil
149
+ Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}")
150
+ next
151
+ end
152
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = ''
153
+ field = data[1]
154
+
155
+ elsif extended_data = extended_data_line.match(line)
156
+ if dmi_record == nil
157
+ Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}")
158
+ next
159
+ end
160
+ if field == nil
161
+ Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}")
162
+ next
163
+ end
164
+ # overwrite "raw" value with a new Mash
165
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == 'Mash'
166
+ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2]
167
+
168
+ else
169
+ Ohai::Log.debug("unrecognized output line; discarding:\n#{line}")
170
+
171
+ end
172
172
  end
173
+
174
+ DMI.convenience_keys(dmi)
173
175
  end
174
176
  end
175
-
176
- DMI.convenience_keys(dmi)