I know I can use knife to get the last time a node checked in but how would I get this information inside of a recipe?
I can run a shell command to run knife in a recipe but just wondering if there is a more elegant solution. Is this a property stored in the node object that is exposed inside a recipe?
I see a lot of folks online using the ohai_time attribute, but it looks like that just logs the last time chef-client ran not the last successful checkin. chef-client is running locally every 30 mins, will ohai_time still be updated if chef-client runs, but it isn't able to contact the server to do a successful checkin? If so then it doesn't make sense to use it.
There's not a super great way to do this. The hacky-but-works way would be something like this:
res = search(:nodes, "name:#{node.name}", filter_keys: {ohai_time: %w{ohai_time}}).find {|n| n.name == node.name }
last_ohai_time = res && res['ohai_time']
That will return nil
if the node has never checked in, you might want to use a different value depending on your code.