使用 PuppetDB 编写自定义报告
1. 查询 PuppetDB 的 facts 端点
首先,我们要创建一个函数,该函数会连接到在 puppetreport.rb 文件中配置的 PuppetDB,并查询 facts 端点以获取用户指定主机的信息。之后,我们会使用 command_line_reporter 库,确保输出对用户来说易于阅读。
操作步骤如下:
1. 在 puppetreport 目录下创建一个名为 hwdetails.rb 的新文件,并使用你喜欢的编辑器打开它。
2. 在文件中添加以下代码:
def get_hw_details
include CommandLineReporter
uri = URI.parse("#{@puppetdb}/v3/facts/")
params = {:query => '["=", "certname",' + '"' "#{@fqdn}" + '"' ']'}
uri.query = URI.encode_www_form(params)
begin
response = Net::HTTP.get_response(uri)
rescue StandardError
puts 'PuppetDB is currently unavailable'
exit
end
json = JSON.parse(response.body)
end
超级会员免费看
订阅专栏 解锁全文
2

被折叠的 条评论
为什么被折叠?



