Created
December 5, 2017 16:01
-
-
Save benhawker/8282bf7c6c1429ab3663389fd3c03b14 to your computer and use it in GitHub Desktop.
Hacky script to take a look at some Honeybadger errors
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
require 'rubygems' | |
require 'colorize' | |
token = 'INSERT_YOUR_TOKEN_HERE' | |
total_notices_count, total_logged_in_count = 0, 0 | |
project_id = 42287 | |
require 'base64' | |
require 'httparty' | |
token = Base64.encode64(token) | |
headers = { "Authorization" => "Basic #{token}", "Accept" => 'application/json' } | |
# This returns the 25 most recent faults. | |
fault_response = HTTParty.get("https://app.honeybadger.io/v2/projects/#{project_id}/faults?order=recent", headers: headers) | |
faults = JSON.parse(fault_response.body)["results"] | |
fault_ids = faults.map { |x| x["id"] } | |
puts "We are retrieving the last 25 faults." | |
puts "Retrieved #{fault_ids.count} fault ids as follows: #{fault_ids.join(', ')}." | |
puts "----------" | |
puts "These are the errors we found \n" | |
puts "----------" | |
faults.each do |fault| | |
notices_count, logged_in_count = 0, 0 | |
puts "#{fault['klass']} in #{fault['component']}/#{fault['action']} with message: #{fault['message']}." | |
puts "#{fault['notices_count']} instances of this error since #{fault['created_at']}.".colorize(:yellow) | |
notices_response = HTTParty.get("https://app.honeybadger.io/v2/projects/#{project_id}/faults/#{fault["id"]}/notices", headers: headers) | |
parsed_notices = JSON.parse(notices_response.body)['results'] | |
parsed_notices.each do |notice| | |
notices_count += 1 | |
if notice["request"].dig("session", "backend", "user_id") || notice["request"].dig("session", "backend", "user_id") | |
logged_in_count += 1 | |
end | |
end | |
puts "TOTAL NOTICES: #{notices_count} (maximum 25)".colorize(:red) | |
puts "WHERE USER IS LOGGED IN: #{logged_in_count} (maximum 25)".colorize(:red) | |
puts "------" | |
total_notices_count += notices_count | |
total_logged_in_count += total_logged_in_count | |
end | |
puts '---- Finished: TOTALS ----' | |
puts "TOTAL NOTICES: #{total_notices_count}".colorize(:blue) | |
puts "WHERE USER IS LOGGED IN: #{total_logged_in_count}".colorize(:blue) | |
puts '---- ----' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment