Puppetdb Report to Csv
Query puppetdb for the last report of this node, and convert the returned json
document to csv with the help of jq
:
curl \
-s -G \
--cert /etc/puppetlabs/puppet/ssl/certs/$(hostname -f).pem \
--key /etc/puppetlabs/puppet/ssl/private_keys/$(hostname -f).pem \
--cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \
https://puppetdb:8081/pdb/query/v4 \
--data-urlencode 'query=[
"from", "reports",
["=", "certname", "'$(hostname -f)'"],
["order_by", [["end_time", "desc"]]],
["limit", 1]
]' | jq -r ' .[] |
[
.certname,
.status,
.end_time,
( .metrics.data[] | select(.name == "total") | select(.category == "time") | .value | tostring )
] | @csv'
This will result in something like this
"Foo","unchanged","2019-04-05T18:26:00.866Z","10.1234"