R.I.Pienaar
03/10/2026, 3:33 PM#!/opt/puppetlabs/puppet/bin/ruby
require "open3"
require "pp"
require "json"
Open3.popen2('/usr/bin/choria', 'req', 'choria_util', 'info', '--limit','1','--jsonl') do |stdin, stdout, status_thread|
stdin.close
stdout.each_line do |line|
msg = JSON.parse(line)
case msg["k"]
when "discovery"
if !msg["dt"]
print("Discovering nodes using the %s method .... " % msg["dm"])
STDOUT.flush
else
puts msg["count"]
puts
end
when "result"
puts "Response from %s" % msg["rr"]["sender"]
when "summaries"
puts
puts "Summaries:"
puts
pp msg["agg"] if msg["agg"]
when "stats"
puts
puts "Finished processing %d / %d hosts in %dms" % [msg["stat"]["responses"], msg["stat"]["discovered"], msg["stat"]["request_time"] / 1000000]
end
end
raise "failed" unless status_thread.value.success?
end