Created
September 24, 2019 15:41
-
-
Save jbarber/60841fef019f37755a5e85170abaabbe to your computer and use it in GitHub Desktop.
Extract all the PagerDuty incidents for analysis
This file contains 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 'httparty' | |
require 'uri' | |
require 'csv' | |
def get_incidents | |
limit = 100 | |
url = "https://api.pagerduty.com/incidents?statuses%5B%5D=resolved&time_zone=UTC&limit=#{limit}&offset=" | |
incidents = [] | |
offset = 0 | |
loop do | |
response = HTTParty.get( | |
(url + offset.to_s), | |
headers: { | |
'Accept' => 'application/vnd.pagerduty+json;version=2', | |
'Authorization' => 'Token token=APISECRET', | |
} | |
) | |
raise response.body unless response.success? | |
incidents = incidents + response.parsed_response['incidents'] | |
offset += limit | |
response['more'] || break | |
end | |
incidents | |
end | |
incidents = get_incidents | |
output = CSV.generate do |csv| | |
incidents.each do |incident| | |
csv << [ | |
incident['incident_number'], | |
incident['created_at'], | |
incident['title'], | |
] | |
end | |
end | |
puts output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment