我试图在 Puppet 中找到一种方法来获取我的 FreeBSD 存储服务器的当前 zpool 容量数字,将它们存储在自定义事实中,并在容量达到“太高”水平时生成警报。到目前为止,我发现的与我的问题最接近的匹配是: Returning multiple custom fact with puppet Facter
这向我指出了这个解决方案:
operatingsystem = Facter.value('operatingsystem')
case operatingsystem
when "FreeBSD"
present_zpools = IO.popen('zpool list -H -o name').read.chomp
if ! present_zpools.empty?
Facter.add(:zpools) do
setcode do
zpools = IO.popen('for i in $(zpool list -H -o name); do echo $i; done').read.chomp.split("\n")
end
end
def addZpoolCapacityFact(zpool)
zpool_capacity = IO.popen('zpool get -H -o value capacity #{zpool}').read.tr('%','').chomp
Facter.add("capacity_" + zpool) do
setcode do
zpool_capacity
end
end
end
zpools = Facter.value(:zpools)
zpools.each do |zpool|
addZpoolCapacityFact(zpool)
end
end
end
但并没有完全产生我期望的结果,例如:
capacity_pool1: 10 30
capacity_pool2: 10 30
当我真的期待时:
capacity_pool1: 10
capacity_pool2: 30
我究竟做错了什么?