Created
March 30, 2015 17:02
-
-
Save reidmv/b094ec4ecffd0a6e8df4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/puppet/bin/ruby | |
require 'net/http' | |
require 'json' | |
events_query = URI.encode_www_form( | |
'query' => '["=","latest-report?",true]', | |
'summarize-by' => 'certname', | |
'count-by' => 'certname' | |
) | |
events_uri = URI::HTTP.build( | |
:host => 'localhost', | |
:port => 8080, | |
:path => '/v3/event-counts', | |
:query => events_query | |
) | |
nodes_uri = URI::HTTP.build( | |
:host => 'localhost', | |
:port => 8080, | |
:path => '/v3/nodes', | |
) | |
nodes_data = JSON.parse(Net::HTTP.get(nodes_uri)) | |
events_data = JSON.parse(Net::HTTP.get(events_uri)) | |
nodes = nodes_data.map { |element| element['name'] } | |
nodes.each do |node| | |
events = events_data.select { |item| item['subject']['title'] == node } | |
if events.empty? | |
puts "#{node}: Unchanged" | |
else | |
msgs = [] | |
failures = events.first['failures'] | |
changes = events.first['successes'] | |
noops = events.first['noops'] | |
skips = events.first['skips'] | |
msgs << "Failures: #{failures}" unless failures == 0 | |
msgs << "Changes: #{changes}" unless changes == 0 | |
msgs << "No-ops: #{noops}" unless noops == 0 | |
msgs << "Skips: #{skips}" unless skips == 0 | |
puts "#{node}: #{msgs.join(', ')}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment