Reputation: 4326
I am able to get the current uptime of a given set of nodes using the Puppet Facts REST Endpoint like this:
curl -X GET https://puppet:8081/pdb/query/v4/facts --data-urlencode 'query=["=", "name", "uptime"]' -k -H "X-Authentication: xxxxxxxxxxxxxxxxxx"
That provides a response that looks like this
{"certname":"xyz","environment":"production","name":"uptime","value":"107 days"}
But, it doesn't tell me the previous uptime, and so I don't have a way of calculating the downtime of this Node. Is there a way to use Puppet facts to see historical data over time such that I could see over the course of a given timeframe that a Node had x seconds of total uptime and y seconds of total downtime?
Upvotes: 0
Views: 253
Reputation: 520
No, is the short answer. Facts on the server are primarily there to provide Puppet with the information it needs to compile a catalog, it's not designed to give historical data, just a "this is what the server looks like right now".
The command you're looking for on linux is probably last reboot
.
If you want to extract data from a machine remotely using Puppet it would be much more appropriate to use Puppet tasks, if you have Puppet Enterprise, if not the same functionality is available using Puppet Bolt tasks.
Just create a tasks directory in your module and drop a script in it to do what you want. Or use an existing one https://github.com/puppetlabs/puppetlabs-reboot look in the tasks directory here. On Puppet enterprise you'll be able to see those tasks on the console.
You'll need to install Bolt, you could use the same module above. This is a good guide to getting started with Puppet Bolt. https://www.youtube.com/watch?v=9Z7nYlspUJw
Upvotes: 1