Ask Your Question
0

How can i query the puppetmaster REST api to find a list of active nodes ?

asked 2013-03-27 16:28:49 -0500

paulmiles01 gravatar image

Without using puppetdb, how can i query the puppetmaster REST api to find a list of active nodes ?

ie. I'd like to run a similar command to this except only show results for active nodes

curl -k -H "Accept: pson" 'https://puppet:8140/production/factssearch/search?facts.operatingsystem=Amazon&facts.attrole=glu'

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-10-05 01:54:07 -0500

Dziki_Jam gravatar image

updated 2016-10-05 01:59:18 -0500

curl -X GET http://localhost:8080/pdb/query/v4/nodes --data-urlencode "query=[\">\", \"facts_timestamp\", \"$(date -d '-1 day' -Isec)\"]" This query will output list of nodes that was active withing 1 day. You can save it to a variable and parse certificates with bash, for example. The query gets all the information from puppetdb, so you need to replace http://localhost:8080 with your puppetdb address.

Example output:

"deactivated" : null,
  "latest_report_hash" : "299b9ba73597835b0218b068267053e065224a7a",
  "facts_environment" : "production",
  "report_environment" : "production",
  "catalog_environment" : "production",
  "facts_timestamp" : "2016-10-05T06:21:45.721Z",
  "expired" : null,
  "report_timestamp" : "2016-10-05T06:23:56.316Z",
 "certname" : "node1.examplom",
  "catalog_timestamp" : "2016-10-05T06:21:47.500Z",
  "latest_report_status" : "changed"
edit flag offensive delete link more
0

answered 2013-03-27 16:39:14 -0500

Ancillas gravatar image

If you're using Puppet 2.7+, you can use the certificate_statuses endpoint.

/{environment}/certificatestatuses/nokey

See the doc. here.

You'll need a signed certificate to make the request, and you'll need to allow that cert to use 'find' and 'search' on the certificate_statuses endpoint in auth.conf.

edit flag offensive delete link more

Comments

Many thanks for your suggestion. Unfortunately it doesn't tell me if a host is alive or not. ie. [root@glu-i-e8602ba2 ~]# curl -k -H "Accept: pson" https://puppet:8140/production/certificate_status/glu-i-8cb0ffc6.local (https://puppet:8140/production/certificatestatus/glu-i-8cb0ffc6.local) {"state":"signed","dnsalt_names":[],"fingerprints":{"SHA256":"A6:D4:BB:A8:7D:0A

paulmiles01 gravatar imagepaulmiles01 ( 2013-03-27 16:46:36 -0500 )edit

What do you mean by "alive"? Currently doing a puppet run? Nodes with a signed cert? Nodes that have successfully synced within a period of time? Nodes whose last puppet ...(more)

Ancillas gravatar imageAncillas ( 2013-03-27 16:55:08 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-03-27 16:28:49 -0500

Seen: 2,434 times

Last updated: Oct 05 '16