Skip to content

Instantly share code, notes, and snippets.

@ipcrm
Last active December 2, 2017 00:27
Show Gist options
  • Save ipcrm/164298c98eafeabb862d5eea3da24239 to your computer and use it in GitHub Desktop.
Save ipcrm/164298c98eafeabb862d5eea3da24239 to your computer and use it in GitHub Desktop.
Ruby: Query PDB Report Data
require 'puppetdb'
client = PuppetDB::Client.new({:server => 'http://localhost:8080'})
response = client.request( '', 'reports[certname,logs]{ latest_report? = true and facts { name = "role" and value = "test" } }')
response.data.each do |c|
c["logs"]["data"].each do |l|
printf "%-30s %s\n" % [ c["certname"].rstrip(), l["message"].split(/[\[,\]]/)[1] ] if l["message"].include?('Echo')
end
end
@ipcrm
Copy link
Author

ipcrm commented Dec 2, 2017

example output

server2012r2b.pdx.puppet.vm    teamx: 0.9.0
centos7a.pdx.puppet.vm         teamx: 0.9.0
server2012r2a.pdx.puppet.vm    teamx: 0.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment