Skip to content

Instantly share code, notes, and snippets.

@jbarber
Created September 24, 2019 15:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbarber/60841fef019f37755a5e85170abaabbe to your computer and use it in GitHub Desktop.
Save jbarber/60841fef019f37755a5e85170abaabbe to your computer and use it in GitHub Desktop.
Extract all the PagerDuty incidents for analysis
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