Created
October 19, 2022 21:12
-
-
Save dnozay/cee142b7987e785fe5fa3e85de24ec8a to your computer and use it in GitHub Desktop.
Very small script to list my pagerduty incidents using pdpyras
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
#!/usr/bin/env python | |
# Very small script to list my pagerduty incidents, | |
# useful to give a quick report about my oncall shift. | |
# | |
# https://github.com/PagerDuty/pdpyras | |
import os | |
import pdpyras | |
import dateutil.parser | |
import pytz | |
API_KEY = os.getenv('PAGERDUTY_TOKEN') | |
timezone = pytz.timezone('US/Pacific') | |
session = pdpyras.APISession(API_KEY) | |
# https://developer.pagerduty.com/api-reference/9d0b4b12e36f9-list-incidents | |
PARAMETERS = { | |
'since': '2022-10-04T10:00:00-08:00', | |
'until': '2022-10-18T10:00:00-08:00', | |
'limit': 200, | |
'team_ids': [ | |
'ABCDEF', # my pagerduty team... | |
], | |
} | |
my_incidents = [] | |
for incident in session.list_all('incidents', params=PARAMETERS): | |
my_incidents.append(incident) | |
total = len(my_incidents) | |
for i, incident in enumerate(my_incidents): | |
created = dateutil.parser.parse(incident['created_at']).astimezone(timezone) | |
print(f"{created} {i+1}/{total} {incident['summary']}") | |
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
requests | |
pdpyras >= 2.0.0 | |
python-dateutil | |
pytz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment