facter 4.0.31 → 4.0.36

Sign up to get free protection for your applications and to get access to all the features.
Files changed (271) hide show
  1. checksums.yaml +4 -4
  2. data/lib/facter/custom_facts/util/directory_loader.rb +13 -1
  3. data/lib/facter/fact_groups.conf +140 -1
  4. data/lib/facter/facts/aix/disks.rb +17 -2
  5. data/lib/facter/facts/aix/networking/scope6.rb +3 -1
  6. data/lib/facter/facts/aix/scope6_interfaces.rb +0 -2
  7. data/lib/facter/facts/aix/serialnumber.rb +20 -0
  8. data/lib/facter/facts/aix/ssh.rb +3 -1
  9. data/lib/facter/facts/aix/sshalgorithmkey.rb +17 -0
  10. data/lib/facter/facts/aix/sshfp_algorithm.rb +20 -0
  11. data/lib/facter/facts/bsd/load_averages.rb +1 -1
  12. data/lib/facter/facts/debian/os/distro/release.rb +6 -1
  13. data/lib/facter/facts/freebsd/augeas/version.rb +19 -0
  14. data/lib/facter/facts/freebsd/dmi/bios/release_date.rb +19 -0
  15. data/lib/facter/facts/freebsd/dmi/bios/vendor.rb +19 -0
  16. data/lib/facter/facts/freebsd/dmi/bios/version.rb +19 -0
  17. data/lib/facter/facts/freebsd/dmi/manufacturer.rb +17 -0
  18. data/lib/facter/facts/freebsd/dmi/product/name.rb +19 -0
  19. data/lib/facter/facts/freebsd/dmi/product/serial_number.rb +19 -0
  20. data/lib/facter/facts/freebsd/dmi/product/uuid.rb +19 -0
  21. data/lib/facter/facts/freebsd/facterversion.rb +14 -0
  22. data/lib/facter/facts/freebsd/identity/gid.rb +16 -0
  23. data/lib/facter/facts/{solaris/solaris_zones/current.rb → freebsd/identity/group.rb} +6 -6
  24. data/lib/facter/facts/freebsd/identity/privileged.rb +16 -0
  25. data/lib/facter/facts/freebsd/identity/uid.rb +16 -0
  26. data/lib/facter/facts/freebsd/identity/user.rb +17 -0
  27. data/lib/facter/facts/freebsd/kernel.rb +14 -0
  28. data/lib/facter/facts/freebsd/kernelrelease.rb +14 -0
  29. data/lib/facter/facts/freebsd/memory/swap/available.rb +21 -0
  30. data/lib/facter/facts/freebsd/memory/swap/available_bytes.rb +20 -0
  31. data/lib/facter/facts/freebsd/memory/swap/capacity.rb +18 -0
  32. data/lib/facter/facts/freebsd/memory/swap/encrypted.rb +19 -0
  33. data/lib/facter/facts/freebsd/memory/swap/total.rb +21 -0
  34. data/lib/facter/facts/freebsd/memory/swap/total_bytes.rb +20 -0
  35. data/lib/facter/facts/freebsd/memory/swap/used.rb +20 -0
  36. data/lib/facter/facts/freebsd/memory/swap/used_bytes.rb +18 -0
  37. data/lib/facter/facts/freebsd/memory/system/available.rb +21 -0
  38. data/lib/facter/facts/freebsd/memory/system/available_bytes.rb +20 -0
  39. data/lib/facter/facts/freebsd/memory/system/capacity.rb +18 -0
  40. data/lib/facter/facts/freebsd/memory/system/total.rb +21 -0
  41. data/lib/facter/facts/freebsd/memory/system/total_bytes.rb +20 -0
  42. data/lib/facter/facts/freebsd/memory/system/used.rb +20 -0
  43. data/lib/facter/facts/freebsd/memory/system/used_bytes.rb +18 -0
  44. data/lib/facter/facts/freebsd/mountpoints.rb +21 -0
  45. data/lib/facter/facts/freebsd/netmask6_interfaces.rb +20 -0
  46. data/lib/facter/facts/freebsd/netmask_interfaces.rb +20 -0
  47. data/lib/facter/facts/freebsd/network6_interfaces.rb +20 -0
  48. data/lib/facter/facts/freebsd/network_interfaces.rb +20 -0
  49. data/lib/facter/facts/freebsd/networking/dhcp.rb +17 -0
  50. data/lib/facter/facts/freebsd/networking/domain.rb +18 -0
  51. data/lib/facter/facts/freebsd/networking/fqdn.rb +18 -0
  52. data/lib/facter/facts/freebsd/networking/hostname.rb +18 -0
  53. data/lib/facter/facts/freebsd/networking/interfaces.rb +17 -0
  54. data/lib/facter/facts/freebsd/networking/ip.rb +18 -0
  55. data/lib/facter/facts/freebsd/networking/ip6.rb +18 -0
  56. data/lib/facter/facts/freebsd/networking/mac.rb +18 -0
  57. data/lib/facter/facts/freebsd/networking/mtu.rb +17 -0
  58. data/lib/facter/facts/freebsd/networking/netmask.rb +18 -0
  59. data/lib/facter/facts/freebsd/networking/netmask6.rb +18 -0
  60. data/lib/facter/facts/freebsd/networking/network.rb +18 -0
  61. data/lib/facter/facts/freebsd/networking/network6.rb +18 -0
  62. data/lib/facter/facts/freebsd/networking/primary.rb +17 -0
  63. data/lib/facter/facts/freebsd/networking/scope6.rb +17 -0
  64. data/lib/facter/facts/freebsd/os/architecture.rb +18 -0
  65. data/lib/facter/facts/freebsd/os/hardware.rb +18 -0
  66. data/lib/facter/facts/freebsd/os/name.rb +18 -0
  67. data/lib/facter/facts/{bsd/bsd_example_fact.rb → freebsd/path.rb} +5 -4
  68. data/lib/facter/facts/freebsd/processors/isa.rb +17 -0
  69. data/lib/facter/facts/freebsd/puppet_version.rb +15 -0
  70. data/lib/facter/facts/freebsd/ruby/platform.rb +18 -0
  71. data/lib/facter/facts/freebsd/ruby/sitedir.rb +18 -0
  72. data/lib/facter/facts/freebsd/ruby/version.rb +18 -0
  73. data/lib/facter/facts/freebsd/ssh.rb +26 -0
  74. data/lib/facter/facts/freebsd/sshalgorithmkey.rb +17 -0
  75. data/lib/facter/facts/freebsd/sshfp_algorithm.rb +20 -0
  76. data/lib/facter/facts/freebsd/system_uptime/days.rb +18 -0
  77. data/lib/facter/facts/freebsd/system_uptime/hours.rb +18 -0
  78. data/lib/facter/facts/freebsd/system_uptime/seconds.rb +18 -0
  79. data/lib/facter/facts/freebsd/system_uptime/uptime.rb +18 -0
  80. data/lib/facter/facts/freebsd/timezone.rb +15 -0
  81. data/lib/facter/facts/freebsd/zfs_featurenumbers.rb +14 -0
  82. data/lib/facter/facts/freebsd/zfs_version.rb +14 -0
  83. data/lib/facter/facts/freebsd/zpool_featureflags.rb +14 -0
  84. data/lib/facter/facts/freebsd/zpool_featurenumbers.rb +14 -0
  85. data/lib/facter/facts/freebsd/zpool_version.rb +14 -0
  86. data/lib/facter/facts/linux/disks.rb +20 -1
  87. data/lib/facter/facts/linux/dmi/board/asset_tag.rb +19 -0
  88. data/lib/facter/facts/linux/ec2_metadata.rb +5 -3
  89. data/lib/facter/facts/linux/ec2_userdata.rb +5 -3
  90. data/lib/facter/facts/linux/gce.rb +16 -0
  91. data/lib/facter/facts/linux/is_virtual.rb +1 -3
  92. data/lib/facter/facts/linux/mountpoints.rb +1 -1
  93. data/lib/facter/facts/linux/networking/scope6.rb +3 -1
  94. data/lib/facter/facts/linux/partitions.rb +1 -1
  95. data/lib/facter/facts/linux/processors/speed.rb +17 -0
  96. data/lib/facter/facts/linux/scope6_interfaces.rb +1 -2
  97. data/lib/facter/facts/linux/ssh.rb +19 -9
  98. data/lib/facter/facts/linux/sshfp_algorithm.rb +1 -1
  99. data/lib/facter/facts/linux/system_uptime/days.rb +7 -1
  100. data/lib/facter/facts/linux/system_uptime/hours.rb +7 -1
  101. data/lib/facter/facts/linux/system_uptime/seconds.rb +7 -1
  102. data/lib/facter/facts/linux/system_uptime/uptime.rb +7 -1
  103. data/lib/facter/facts/linux/virtual.rb +17 -0
  104. data/lib/facter/facts/linux/xen.rb +28 -0
  105. data/lib/facter/facts/macosx/dhcp_servers.rb +2 -2
  106. data/lib/facter/facts/macosx/interfaces.rb +1 -1
  107. data/lib/facter/facts/macosx/ipaddress6_interfaces.rb +1 -1
  108. data/lib/facter/facts/macosx/ipaddress_interfaces.rb +1 -1
  109. data/lib/facter/facts/macosx/macaddress_interfaces.rb +1 -1
  110. data/lib/facter/facts/macosx/mtu_interfaces.rb +1 -1
  111. data/lib/facter/facts/macosx/netmask6_interfaces.rb +1 -1
  112. data/lib/facter/facts/macosx/netmask_interfaces.rb +1 -1
  113. data/lib/facter/facts/macosx/network6_interfaces.rb +1 -1
  114. data/lib/facter/facts/macosx/network_interfaces.rb +1 -1
  115. data/lib/facter/facts/macosx/networking/dhcp.rb +1 -1
  116. data/lib/facter/facts/macosx/networking/interfaces.rb +1 -1
  117. data/lib/facter/facts/macosx/networking/ip.rb +1 -1
  118. data/lib/facter/facts/macosx/networking/ip6.rb +1 -1
  119. data/lib/facter/facts/macosx/networking/mac.rb +1 -1
  120. data/lib/facter/facts/macosx/networking/mtu.rb +1 -1
  121. data/lib/facter/facts/macosx/networking/netmask.rb +1 -1
  122. data/lib/facter/facts/macosx/networking/netmask6.rb +1 -1
  123. data/lib/facter/facts/macosx/networking/network.rb +1 -1
  124. data/lib/facter/facts/macosx/networking/network6.rb +1 -1
  125. data/lib/facter/facts/macosx/networking/primary.rb +1 -1
  126. data/lib/facter/facts/macosx/networking/scope6.rb +4 -2
  127. data/lib/facter/facts/macosx/scope6_interfaces.rb +1 -3
  128. data/lib/facter/facts/macosx/ssh.rb +19 -11
  129. data/lib/facter/facts/macosx/sshfp_algorithm.rb +1 -1
  130. data/lib/facter/facts/macosx/virtual.rb +1 -1
  131. data/lib/facter/facts/solaris/current_zone.rb +16 -0
  132. data/lib/facter/facts/solaris/disks.rb +33 -0
  133. data/lib/facter/facts/solaris/dmi/bios/release_date.rb +24 -0
  134. data/lib/facter/facts/solaris/dmi/bios/vendor.rb +24 -0
  135. data/lib/facter/facts/solaris/dmi/bios/version.rb +24 -0
  136. data/lib/facter/facts/solaris/dmi/chassis/asset_tag.rb +24 -0
  137. data/lib/facter/facts/solaris/dmi/chassis/type.rb +24 -0
  138. data/lib/facter/facts/solaris/dmi/manufacturer.rb +25 -0
  139. data/lib/facter/facts/solaris/dmi/product/name.rb +27 -0
  140. data/lib/facter/facts/solaris/dmi/product/serial_number.rb +27 -0
  141. data/lib/facter/facts/solaris/dmi/product/uuid.rb +24 -0
  142. data/lib/facter/facts/solaris/hypervisors/ldom.rb +24 -0
  143. data/lib/facter/facts/solaris/hypervisors/zone.rb +39 -0
  144. data/lib/facter/facts/solaris/is_virtual.rb +64 -0
  145. data/lib/facter/facts/solaris/kernelmajversion.rb +1 -1
  146. data/lib/facter/facts/solaris/ldom.rb +35 -0
  147. data/lib/facter/facts/solaris/load_averages.rb +14 -0
  148. data/lib/facter/facts/solaris/memory/swap/available.rb +22 -0
  149. data/lib/facter/facts/solaris/memory/swap/available_bytes.rb +22 -0
  150. data/lib/facter/facts/solaris/memory/swap/capacity.rb +20 -0
  151. data/lib/facter/facts/solaris/memory/swap/total.rb +22 -0
  152. data/lib/facter/facts/solaris/memory/swap/total_bytes.rb +22 -0
  153. data/lib/facter/facts/solaris/memory/swap/used.rb +21 -0
  154. data/lib/facter/facts/solaris/memory/swap/used_bytes.rb +19 -0
  155. data/lib/facter/facts/solaris/memory/system/available.rb +22 -0
  156. data/lib/facter/facts/solaris/memory/system/available_bytes.rb +22 -0
  157. data/lib/facter/facts/solaris/memory/system/capacity.rb +20 -0
  158. data/lib/facter/facts/solaris/memory/system/total.rb +22 -0
  159. data/lib/facter/facts/solaris/memory/system/total_bytes.rb +22 -0
  160. data/lib/facter/facts/solaris/memory/system/used.rb +21 -0
  161. data/lib/facter/facts/solaris/memory/system/used_bytes.rb +19 -0
  162. data/lib/facter/facts/solaris/mountpoints.rb +1 -1
  163. data/lib/facter/facts/solaris/os/release.rb +3 -3
  164. data/lib/facter/facts/solaris/ssh.rb +19 -9
  165. data/lib/facter/facts/solaris/sshalgorithmkey.rb +17 -0
  166. data/lib/facter/facts/solaris/sshfp_algorithm.rb +20 -0
  167. data/lib/facter/facts/solaris/virtual.rb +60 -0
  168. data/lib/facter/facts/solaris/zfs_featurenumbers.rb +1 -1
  169. data/lib/facter/facts/solaris/zfs_version.rb +1 -1
  170. data/lib/facter/facts/solaris/zones.rb +60 -0
  171. data/lib/facter/facts/solaris/zpool_featureflags.rb +1 -1
  172. data/lib/facter/facts/solaris/zpool_featurenumbers.rb +1 -1
  173. data/lib/facter/facts/solaris/zpool_version.rb +1 -1
  174. data/lib/facter/facts/windows/dhcp_servers.rb +2 -2
  175. data/lib/facter/facts/windows/ec2_metadata.rb +5 -3
  176. data/lib/facter/facts/windows/ec2_userdata.rb +5 -3
  177. data/lib/facter/facts/windows/gce.rb +16 -0
  178. data/lib/facter/facts/windows/interfaces.rb +1 -1
  179. data/lib/facter/facts/windows/ipaddress6_interfaces.rb +1 -1
  180. data/lib/facter/facts/windows/ipaddress_interfaces.rb +1 -1
  181. data/lib/facter/facts/windows/macaddress_interfaces.rb +1 -1
  182. data/lib/facter/facts/windows/mtu_interfaces.rb +1 -1
  183. data/lib/facter/facts/windows/netmask6_interfaces.rb +1 -1
  184. data/lib/facter/facts/windows/netmask_interfaces.rb +1 -1
  185. data/lib/facter/facts/windows/network6_interfaces.rb +1 -1
  186. data/lib/facter/facts/windows/network_interfaces.rb +1 -1
  187. data/lib/facter/facts/windows/networking/dhcp.rb +1 -1
  188. data/lib/facter/facts/windows/networking/domain.rb +1 -1
  189. data/lib/facter/facts/windows/networking/fqdn.rb +1 -1
  190. data/lib/facter/facts/windows/networking/interfaces.rb +1 -1
  191. data/lib/facter/facts/windows/networking/ip.rb +1 -1
  192. data/lib/facter/facts/windows/networking/ip6.rb +1 -1
  193. data/lib/facter/facts/windows/networking/mac.rb +1 -1
  194. data/lib/facter/facts/windows/networking/mtu.rb +1 -1
  195. data/lib/facter/facts/windows/networking/netmask.rb +1 -1
  196. data/lib/facter/facts/windows/networking/netmask6.rb +1 -1
  197. data/lib/facter/facts/windows/networking/network.rb +1 -1
  198. data/lib/facter/facts/windows/networking/network6.rb +1 -1
  199. data/lib/facter/facts/windows/networking/primary.rb +1 -1
  200. data/lib/facter/facts/windows/networking/scope6.rb +4 -2
  201. data/lib/facter/facts/windows/scope6_interfaces.rb +1 -1
  202. data/lib/facter/facts/windows/sshalgorithmkey.rb +22 -0
  203. data/lib/facter/facts/windows/sshfp_algorithm.rb +25 -0
  204. data/lib/facter/facts_utils/facts_utils.rb +2 -0
  205. data/lib/facter/framework/cli/cli.rb +16 -4
  206. data/lib/facter/framework/config/fact_groups.rb +13 -0
  207. data/lib/facter/framework/core/fact/internal/core_fact.rb +2 -0
  208. data/lib/facter/framework/core/fact/internal/internal_fact_manager.rb +10 -25
  209. data/lib/facter/framework/core/fact_filter.rb +13 -0
  210. data/lib/facter/framework/core/fact_loaders/fact_loader.rb +24 -1
  211. data/lib/facter/framework/detector/os_detector.rb +5 -1
  212. data/lib/facter/framework/formatters/legacy_fact_formatter.rb +8 -1
  213. data/lib/facter/framework/formatters/yaml_fact_formatter.rb +1 -1
  214. data/lib/facter/os_hierarchy.json +6 -7
  215. data/lib/facter/resolvers/aix/serialnumber.rb +37 -0
  216. data/lib/facter/resolvers/augeas_resolver.rb +19 -2
  217. data/lib/facter/resolvers/base_resolver.rb +1 -1
  218. data/lib/facter/resolvers/bsd/ffi/ffi_helper.rb +0 -10
  219. data/lib/facter/resolvers/dmi_resolver.rb +4 -3
  220. data/lib/facter/resolvers/ec2.rb +4 -18
  221. data/lib/facter/resolvers/filesystems_resolver.rb +1 -1
  222. data/lib/facter/resolvers/freebsd/dmi_resolver.rb +38 -0
  223. data/lib/facter/resolvers/freebsd/ffi/ffi_helper.rb +19 -0
  224. data/lib/facter/resolvers/freebsd/swap_memory_resolver.rb +39 -0
  225. data/lib/facter/resolvers/freebsd/system_memory_resolver.rb +41 -0
  226. data/lib/facter/resolvers/gce.rb +54 -0
  227. data/lib/facter/resolvers/linux/docker_uptime.rb +45 -0
  228. data/lib/facter/resolvers/{load_averages_resolver.rb → linux/load_averages.rb} +0 -1
  229. data/lib/facter/resolvers/load_averages.rb +26 -0
  230. data/lib/facter/resolvers/lspci.rb +2 -0
  231. data/lib/facter/resolvers/memory_resolver.rb +8 -1
  232. data/lib/facter/resolvers/mountpoints_resolver.rb +42 -44
  233. data/lib/facter/resolvers/networking_linux_resolver.rb +16 -1
  234. data/lib/facter/resolvers/networking_resolver.rb +106 -0
  235. data/lib/facter/resolvers/os_release_resolver.rb +1 -1
  236. data/lib/facter/resolvers/processors_resolver.rb +24 -2
  237. data/lib/facter/resolvers/redhat_release_resolver.rb +4 -3
  238. data/lib/facter/resolvers/solaris/disks.rb +51 -0
  239. data/lib/facter/resolvers/solaris/dmi.rb +57 -0
  240. data/lib/facter/resolvers/solaris/dmi_sparc.rb +47 -0
  241. data/lib/facter/resolvers/solaris/ffi/ffi.rb +5 -0
  242. data/lib/facter/resolvers/solaris/{filesystems_resolver.rb → filesystems.rb} +0 -0
  243. data/lib/facter/resolvers/solaris/{ipaddress_resolver.rb → ipaddress.rb} +0 -0
  244. data/lib/facter/resolvers/solaris/ldom.rb +70 -0
  245. data/lib/facter/resolvers/solaris/memory.rb +93 -0
  246. data/lib/facter/resolvers/solaris/{networking_resolver.rb → networking.rb} +2 -6
  247. data/lib/facter/resolvers/solaris/os_release.rb +44 -0
  248. data/lib/facter/resolvers/solaris/zone.rb +51 -0
  249. data/lib/facter/resolvers/solaris/zone_name.rb +31 -0
  250. data/lib/facter/resolvers/uptime_resolver.rb +1 -27
  251. data/lib/facter/resolvers/utils/ffi/load_averages.rb +27 -0
  252. data/lib/facter/resolvers/utils/http.rb +68 -0
  253. data/lib/facter/resolvers/utils/networking.rb +2 -0
  254. data/lib/facter/resolvers/utils/uptime_helper.rb +32 -0
  255. data/lib/facter/resolvers/windows/ffi/ffi.rb +1 -1
  256. data/lib/facter/resolvers/windows/networking_resolver.rb +100 -100
  257. data/lib/facter/resolvers/xen.rb +28 -0
  258. data/lib/facter/resolvers/zfs.rb +32 -0
  259. data/lib/facter/resolvers/zpool.rb +34 -0
  260. data/lib/facter/version.rb +1 -1
  261. metadata +144 -18
  262. data/lib/facter/facts/freebsd/solaris_zones/current.rb +0 -15
  263. data/lib/facter/facts/freebsd/solaris_zones/zone.rb +0 -15
  264. data/lib/facter/facts/solaris/solaris_zones/zone.rb +0 -62
  265. data/lib/facter/resolvers/bsd/load_averages_resolver.rb +0 -26
  266. data/lib/facter/resolvers/macosx/networking_resolver.rb +0 -108
  267. data/lib/facter/resolvers/solaris/solaris_os_release_resolver.rb +0 -42
  268. data/lib/facter/resolvers/solaris/solaris_zone_name.rb +0 -28
  269. data/lib/facter/resolvers/solaris/zfs_resolver.rb +0 -34
  270. data/lib/facter/resolvers/solaris/zone_resolver.rb +0 -48
  271. data/lib/facter/resolvers/solaris/zpool_resolver.rb +0 -36
@@ -7,6 +7,8 @@ module Facter
7
7
  class FactFilter
8
8
  def filter_facts!(searched_facts)
9
9
  filter_legacy_facts!(searched_facts)
10
+ filter_blocked_legacy_facts!(searched_facts)
11
+
10
12
  searched_facts.each do |fact|
11
13
  fact.value = if fact.filter_tokens.any? && fact.value.respond_to?(:dig)
12
14
  fact.value.dig(*fact.filter_tokens)
@@ -18,6 +20,17 @@ module Facter
18
20
 
19
21
  private
20
22
 
23
+ # This will filter out the legacy facts that should be blocked. Because some legacy facts are just aliases
24
+ # to the core ones, even if they are blocked, facter will resolved them but they won't be displayed.
25
+
26
+ def filter_blocked_legacy_facts!(facts)
27
+ blocked_facts = Options[:blocked_facts] || []
28
+
29
+ facts.reject! do |fact|
30
+ blocked_facts.select { |blocked_fact| fact.name.match(/^#{blocked_fact}/) && fact.type == :legacy }.any?
31
+ end
32
+ end
33
+
21
34
  def filter_legacy_facts!(resolved_facts)
22
35
  return unless !Options[:show_legacy] && Options[:user_query].empty?
23
36
 
@@ -64,11 +64,34 @@ module Facter
64
64
  def block_facts(facts, options)
65
65
  blocked_facts = options[:blocked_facts] || []
66
66
 
67
+ reject_list_core, reject_list_legacy = construct_reject_lists(blocked_facts, facts)
68
+
67
69
  facts = facts.reject do |fact|
68
- blocked_facts.select { |blocked_fact| fact.name.match(/^#{blocked_fact}/) }.any?
70
+ reject_list_core.include?(fact) || reject_list_core.find do |fact_to_block|
71
+ fact_to_block.klass == fact.klass
72
+ end || reject_list_legacy.include?(fact)
69
73
  end
70
74
 
71
75
  facts
72
76
  end
77
+
78
+ def construct_reject_lists(blocked_facts, facts)
79
+ reject_list_core = []
80
+ reject_list_legacy = []
81
+
82
+ blocked_facts.each do |blocked|
83
+ facts.each do |fact|
84
+ next unless fact.name =~ /^#{blocked}/
85
+
86
+ if fact.type == :core
87
+ reject_list_core << fact
88
+ else
89
+ reject_list_legacy << fact
90
+ end
91
+ end
92
+ end
93
+
94
+ [reject_list_core, reject_list_legacy]
95
+ end
73
96
  end
74
97
  end
@@ -44,7 +44,11 @@ class OsDetector
44
44
  hierarchy = @os_hierarchy.construct_hierarchy(identifier)
45
45
  if hierarchy.empty?
46
46
  @log.debug("Could not detect hierarchy using os identifier: #{identifier} , trying with family")
47
- hierarchy = @os_hierarchy.construct_hierarchy(detect_family)
47
+
48
+ detect_family.to_s.split.each do |family|
49
+ hierarchy = @os_hierarchy.construct_hierarchy(family)
50
+ return hierarchy unless hierarchy.empty?
51
+ end
48
52
  end
49
53
 
50
54
  if hierarchy.empty?
@@ -26,7 +26,8 @@ module Facter
26
26
  pretty_json = hash_to_facter_format(fact_collection)
27
27
 
28
28
  pretty_json = remove_enclosing_accolades(pretty_json)
29
- remove_comma_and_quotation(pretty_json)
29
+ pretty_json = remove_comma_and_quotation(pretty_json)
30
+ handle_newlines(pretty_json)
30
31
  end
31
32
 
32
33
  def format_for_multiple_user_queries(user_queries, resolved_facts)
@@ -38,6 +39,7 @@ module Facter
38
39
  pretty_json = hash_to_facter_format(facts_to_display)
39
40
  pretty_json = remove_enclosing_accolades(pretty_json)
40
41
  pretty_json = remove_comma_and_quotation(pretty_json)
42
+ pretty_json = handle_newlines(pretty_json)
41
43
 
42
44
  @log.debug('Remove quotes from value if value is a string')
43
45
  pretty_json.gsub(/^(\S*) => \"(.*)\"/, '\1 => \2')
@@ -84,6 +86,11 @@ module Facter
84
86
  pretty_fact_json.gsub(/^},/, '}')
85
87
  end
86
88
 
89
+ def handle_newlines(pretty_fact_json)
90
+ @log.debug('Convert newline characters to actual newlines')
91
+ pretty_fact_json.gsub('\n', "\n")
92
+ end
93
+
87
94
  def remove_comma_and_quotation(output)
88
95
  # quotation marks that come after \ are not removed
89
96
  @log.debug('Remove unnecessary comma and quotation marks on root facts')
@@ -56,7 +56,7 @@ module Facter
56
56
  return false if value[/^[0-9]+$/]
57
57
  return true if value =~ /y|Y|yes|Yes|YES|n|N|no|No|NO|True|TRUE|False|FALSE|on|On|ON|off|Off|OFF|:/
58
58
  return false if value[/[a-zA-Z]/]
59
- return false if value[/[0-9]+\.[0-9]+\./]
59
+ return false if value[/[0-9]+\.[0-9]+/]
60
60
 
61
61
  true
62
62
  end
@@ -12,7 +12,9 @@
12
12
  "Rhel": [
13
13
  "Fedora",
14
14
  "Amzn",
15
- "Centos"
15
+ "Centos",
16
+ "Ol",
17
+ "Scientific"
16
18
  ]
17
19
  },
18
20
  {
@@ -23,14 +25,11 @@
23
25
  ]
24
26
  },
25
27
  {
26
- "Solaris": [
27
- {
28
- "Bsd": [
29
- "Freebsd"
30
- ]
31
- }
28
+ "Bsd": [
29
+ "Freebsd"
32
30
  ]
33
31
  },
32
+ "Solaris",
34
33
  "Macosx",
35
34
  "Windows",
36
35
  "Aix"
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Aix
6
+ class Serialnumber < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { read_serialnumber(fact_name) }
15
+ end
16
+
17
+ def read_serialnumber(fact_name)
18
+ odmquery = Facter::ODMQuery.new
19
+ odmquery
20
+ .equals('name', 'sys0')
21
+ .equals('attribute', 'systemid')
22
+ result = odmquery.execute
23
+
24
+ result.each_line do |line|
25
+ if line.include?('value')
26
+ @fact_list[:serialnumber] = line.split('=')[1].strip.delete('\"')[6..-1]
27
+ break
28
+ end
29
+ end
30
+
31
+ @fact_list[fact_name]
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -14,10 +14,27 @@ module Facter
14
14
  end
15
15
 
16
16
  def read_augeas_version(fact_name)
17
- output = Facter::Core::Execution.execute('augparse --version 2>&1', logger: log)
18
- @fact_list[:augeas_version] = Regexp.last_match(1) if output =~ /^augparse (\d+\.\d+\.\d+)/
17
+ @fact_list[:augeas_version] = read_augeas_from_cli
18
+ @fact_list[:augeas_version] ||= read_augeas_from_gem
19
+
19
20
  @fact_list[fact_name]
20
21
  end
22
+
23
+ def read_augeas_from_cli
24
+ output = Facter::Core::Execution.execute('augparse --version 2>&1', logger: log)
25
+ Regexp.last_match(1) if output =~ /^augparse (\d+\.\d+\.\d+)/
26
+ end
27
+
28
+ def read_augeas_from_gem
29
+ require 'augeas'
30
+
31
+ if Gem.loaded_specs['augeas']
32
+ ::Augeas.create { |aug| aug.get('/augeas/version') }
33
+ else
34
+ # it is used for legacy augeas <= 0.5.0 (ruby-augeas gem)
35
+ ::Augeas.open { |aug| aug.get('/augeas/version') }
36
+ end
37
+ end
21
38
  end
22
39
  end
23
40
  end
@@ -20,7 +20,7 @@ module Facter
20
20
  subscribe_to_manager
21
21
  post_resolve(fact_name)
22
22
  end
23
- rescue LoadError => e
23
+ rescue LoadError, NameError => e
24
24
  log.debug("resolving fact #{fact_name}, but #{e}")
25
25
  @fact_list[fact_name] = nil
26
26
  end
@@ -9,19 +9,9 @@ module Facter
9
9
  extend FFI::Library
10
10
 
11
11
  ffi_lib 'c'
12
- attach_function :getloadavg, %i[pointer int], :int
13
12
  attach_function :sysctl, %i[pointer uint pointer pointer pointer size_t], :int
14
13
  end
15
14
 
16
- def self.read_load_averages
17
- raw_loadavg = FFI::MemoryPointer.new(:double, 3)
18
-
19
- res = Libc.getloadavg(raw_loadavg, 3)
20
- return unless res == 3
21
-
22
- raw_loadavg.read_array_of_double(res)
23
- end
24
-
25
15
  def self.sysctl(type, oids)
26
16
  name = FFI::MemoryPointer.new(:uint, oids.size)
27
17
  name.write_array_of_uint(oids)
@@ -12,6 +12,7 @@ module Facter
12
12
  # :bios_vendor
13
13
  # :bios_date
14
14
  # :bios_version
15
+ # :board_asset_tag
15
16
  # :board_vendor
16
17
  # :board_serial
17
18
  # :board_name
@@ -29,9 +30,9 @@ module Facter
29
30
  end
30
31
 
31
32
  def read_facts(fact_name)
32
- files = %w[bios_date bios_vendor bios_version board_vendor board_name board_serial
33
- chassis_asset_tag chassis_type sys_vendor product_name product_serial
34
- product_uuid]
33
+ files = %w[bios_date bios_vendor bios_version board_asset_tag board_vendor board_name
34
+ board_serial chassis_asset_tag chassis_type sys_vendor product_name
35
+ product_serial product_uuid]
35
36
  return unless File.directory?('/sys/class/dmi')
36
37
 
37
38
  file_content = Util::FileHelper.safe_read("/sys/class/dmi/id/#{fact_name}", nil)
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'net/http'
4
-
5
3
  module Facter
6
4
  module Resolvers
7
5
  class Ec2 < BaseResolver
@@ -9,13 +7,13 @@ module Facter
9
7
  @fact_list ||= {}
10
8
  EC2_METADATA_ROOT_URL = 'http://169.254.169.254/latest/meta-data/'
11
9
  EC2_USERDATA_ROOT_URL = 'http://169.254.169.254/latest/user-data/'
12
- EC2_CONNECTION_TIMEOUT = 0.6
13
10
  EC2_SESSION_TIMEOUT = 5
14
11
 
15
12
  class << self
16
13
  private
17
14
 
18
15
  def post_resolve(fact_name)
16
+ log.debug('Querying Ec2 metadata')
19
17
  @fact_list.fetch(fact_name) { read_facts(fact_name) }
20
18
  end
21
19
 
@@ -31,7 +29,7 @@ module Facter
31
29
  metadata.each_line do |line|
32
30
  next if line.empty?
33
31
 
34
- http_path_component = build_path_compoent(line)
32
+ http_path_component = build_path_component(line)
35
33
  next if http_path_component == 'security-credentials/'
36
34
 
37
35
  if http_path_component.end_with?('/')
@@ -46,25 +44,13 @@ module Facter
46
44
  end
47
45
  end
48
46
 
49
- def build_path_compoent(line)
47
+ def build_path_component(line)
50
48
  array_match = /^(\d+)=.*$/.match(line)
51
49
  array_match ? "#{array_match[1]}/" : line.strip
52
50
  end
53
51
 
54
52
  def get_data_from(url)
55
- parsed_url = URI.parse(url)
56
- http = Net::HTTP.new(parsed_url.host)
57
- http.read_timeout = determine_session_timeout
58
- http.open_timeout = EC2_CONNECTION_TIMEOUT
59
- resp = http.get(parsed_url.path)
60
- response_code_valid?(resp.code) ? resp.body : ''
61
- rescue StandardError => e
62
- log.debug("Trying to connect to #{url} but got: #{e.message}")
63
- ''
64
- end
65
-
66
- def response_code_valid?(http_code)
67
- http_code.to_i.equal?(200)
53
+ Utils::Http.get_request(url, {}, { session: determine_session_timeout })
68
54
  end
69
55
 
70
56
  def determine_session_timeout
@@ -22,7 +22,7 @@ module Facter
22
22
  filesystems = []
23
23
  output.each do |line|
24
24
  tokens = line.split(' ')
25
- filesystems << tokens if tokens.size == 1
25
+ filesystems << tokens if tokens.size == 1 && tokens.first != 'fuseblk'
26
26
  end
27
27
  @fact_list[:systems] = filesystems.sort.join(',')
28
28
  @fact_list[fact_name]
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Freebsd
6
+ class DmiBios < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+
10
+ class << self
11
+ #:model
12
+
13
+ private
14
+
15
+ def post_resolve(fact_name)
16
+ @fact_list.fetch(fact_name) { read_facts(fact_name) }
17
+ end
18
+
19
+ def read_facts(fact_name)
20
+ require_relative 'ffi/ffi_helper'
21
+
22
+ @fact_list[:bios_date] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.bios.reldate')
23
+ @fact_list[:bios_vendor] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.bios.vendor')
24
+ @fact_list[:bios_version] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.bios.version')
25
+
26
+ @fact_list[:product_name] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.system.product')
27
+ @fact_list[:product_serial] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.system.serial')
28
+ @fact_list[:product_uuid] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.system.uuid')
29
+
30
+ @fact_list[:sys_vendor] = Facter::Freebsd::FfiHelper.kenv(:get, 'smbios.system.maker')
31
+
32
+ @fact_list[fact_name]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -8,10 +8,29 @@ module Facter
8
8
  module Libc
9
9
  extend FFI::Library
10
10
 
11
+ KENV_GET = 0
12
+
13
+ KENV_MVALLEN = 128
14
+
11
15
  ffi_lib 'c'
16
+ attach_function :kenv, %i[int string pointer int], :int
12
17
  attach_function :sysctlbyname, %i[string pointer pointer pointer size_t], :int
13
18
  end
14
19
 
20
+ def self.kenv(action, name, value = nil)
21
+ case action
22
+ when :get
23
+ len = Libc::KENV_MVALLEN + 1
24
+ value = FFI::MemoryPointer.new(:char, len)
25
+ res = Libc.kenv(Libc::KENV_GET, name, value, len)
26
+ return nil if res.negative?
27
+
28
+ value.read_string(res).chomp("\0")
29
+ else
30
+ raise "Action #{action} not supported"
31
+ end
32
+ end
33
+
15
34
  def self.sysctl_by_name(type, name)
16
35
  oldp = FFI::Pointer::NULL
17
36
  oldlenp = FFI::MemoryPointer.new(:size_t)
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Freebsd
6
+ class SwapMemory < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+ class << self
10
+ private
11
+
12
+ def post_resolve(fact_name)
13
+ @fact_list.fetch(fact_name) { read_swap_memory(fact_name) }
14
+ end
15
+
16
+ def read_swap_memory(fact_name) # rubocop:disable Metrics/AbcSize
17
+ output = Facter::Core::Execution.execute('swapinfo -k', logger: log)
18
+ data = output.split("\n")[1..-1].map { |line| line.split(/\s+/) }
19
+
20
+ unless data.empty?
21
+ @fact_list[:total_bytes] = kilobytes_to_bytes(data.map { |line| line[1].to_i }.inject(:+))
22
+ @fact_list[:used_bytes] = kilobytes_to_bytes(data.map { |line| line[2].to_i }.inject(:+))
23
+ @fact_list[:available_bytes] = kilobytes_to_bytes(data.map { |line| line[3].to_i }.inject(:+))
24
+ @fact_list[:capacity] = FilesystemHelper.compute_capacity(@fact_list[:used_bytes],
25
+ @fact_list[:total_bytes])
26
+ @fact_list[:encrypted] = data.map { |line| line[0].end_with?('.eli') }.all?
27
+ end
28
+
29
+ @fact_list[fact_name]
30
+ end
31
+
32
+ def kilobytes_to_bytes(quantity)
33
+ (quantity.to_f * 1024).to_i
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Freebsd
6
+ class SystemMemory < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+ class << self
10
+ private
11
+
12
+ def post_resolve(fact_name)
13
+ @fact_list.fetch(fact_name) { calculate_system_memory(fact_name) }
14
+ end
15
+
16
+ def calculate_system_memory(fact_name)
17
+ read_total_memory_in_bytes
18
+ read_available_memory_in_bytes
19
+
20
+ @fact_list[:used_bytes] = @fact_list[:total_bytes] - @fact_list[:available_bytes]
21
+ @fact_list[:capacity] = FilesystemHelper.compute_capacity(@fact_list[:used_bytes], @fact_list[:total_bytes])
22
+
23
+ @fact_list[fact_name]
24
+ end
25
+
26
+ def read_available_memory_in_bytes
27
+ output = Facter::Core::Execution.execute('vmstat -H --libxo json', logger: log)
28
+ data = JSON.parse(output)
29
+ @fact_list[:available_bytes] = data['memory']['free-memory'] * 1024
30
+ end
31
+
32
+ def read_total_memory_in_bytes
33
+ require_relative 'ffi/ffi_helper'
34
+
35
+ @fact_list[:total_bytes] = Facter::Freebsd::FfiHelper.sysctl_by_name(:long, 'hw.physmem')
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end