Reputation: 367
Does anyone have a way to export all historical incidents from PagerDuty? I can't seem to make it work by using any of the options in here:
https://developer.pagerduty.com/api-reference/9d0b4b12e36f9-list-incidents
So I've been trying to do it in python using https://pagerduty.github.io/pdpyras/
My simple script looks like this:
import os
from pdpyras import APISession
api_key = os.environ['PD_API_KEY']
session = APISession(api_key, default_from="fake.email.com")
for incident in session.iter_all('incidents'):
print(incident)
This only exports about the last month worth of incidents. I can't seem to find a parameter to pass into this which will allow me to export ALL incidents.
Upvotes: 1
Views: 1499
Reputation: 1083
You need to make multiple calls using the since
and until
parameters to request incidents for a specific time range. The default time range is 1 month, and the maximum time range is 6 months.
The maximum number of incidents that it will return for a given time range is 10,000, if I remember correctly. This means that you will need to submit requests for separate time ranges that end up covering the entire 6 months that are available such that each time span for which you submit a request does not result in more than 10k incidents.
I do not personally use pdpyras
, but it appears that you should be able to pass params={'since': '...', 'until': '...'}
to iter_all
to achieve this.
If you use either a date or a datetime object in your code for the since
/until
values, then you can use .isoformat()
on those objects to produce a value that PagerDuty will accept.
Upvotes: 1