Created
September 20, 2017 01:35
-
-
Save ndmanvar/6a86d09ea82328e6543823a8bc3e0ee0 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
# Token (SENTRY_AUTH_TOKEN) must have appropriate priveleges (i.e. project:write, etc.) | |
# You will get 401 Unauthorized (RestClient::Unauthorized) if auth token does not appropriate permissions. | |
# Usage: SENTRY_AUTH_TOKEN=<YOUR_SENTRY_AUTH_TOKEN> SENTRY_ORG=<YOUR_SENTRY_ORG> ruby get_events_per_key.rb | |
require 'rest-client' | |
require 'json' | |
organization_slug = ENV['SENTRY_ORG'] | |
puts "token is : #{ENV['SENTRY_AUTH_TOKEN']}" | |
res = RestClient.get("https://sentry.io/api/0/organizations/#{organization_slug}/projects/", | |
headers={ | |
"Authorization": "Bearer #{ENV['SENTRY_AUTH_TOKEN']}" | |
}) | |
projects = JSON.parse(res.body) | |
for project in projects | |
project_slug = project['slug'] | |
res = RestClient.get("https://sentry.io/api/0/projects/#{organization_slug}/#{project_slug}/keys/", | |
headers={ | |
"Authorization": "Bearer #{ENV['SENTRY_AUTH_TOKEN']}" | |
}) | |
keys = JSON.parse(res.body) | |
for key in keys | |
key_id = key['id'] | |
name = key['name'] | |
# puts "name is : #{name}" | |
# puts "https://sentry.io/api/0/projects/#{organization_slug}/#{project_slug}/keys/#{key_id}/" | |
# get usage for DSN key | |
res = RestClient.get("https://sentry.io/api/0/projects/#{organization_slug}/#{project_slug}/keys/#{key_id}/stats/?since=<BEGIN_TIME>&until=<END_TIME>&resolution=1d", | |
headers={ | |
"Authorization": "Bearer #{ENV['SENTRY_AUTH_TOKEN']}" | |
}) | |
puts res.body | |
# now just have to pull out numbers of events accepted, filtered, dropped, etc. | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment