Skip to content

Commit df18d9f

Browse files
authored
Merge pull request #1 from notpeter/master
Fix long standing issues with Python Examples.
2 parents df3e2a9 + 5e8eaab commit df18d9f

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

REST_API_v1/Incidents/PUT_Incidents_Ack/ack_incident.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def ack_incident():
1414
'Content-type': 'application/json',
1515
}
1616
r = requests.put(
17-
'https://{0}.pagerduty.com/api/v1/incidents/{0}/acknowledge'.format(SUBDOMAIN, INCIDENT_ID),
17+
'https://{0}.pagerduty.com/api/v1/incidents/{1}/acknowledge?requester_id={2}'.format(SUBDOMAIN, INCIDENT_ID, REQUESTER_ID),
1818
headers=headers,
1919
)
2020
print r.status_code

REST_API_v1/Incidents/PUT_Incidents_Reassign/reassign_incident.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def reassign_incident():
1414
'Content-type': 'application/json',
1515
}
1616
r = requests.put(
17-
'https://{0}.pagerduty.com/api/v1/incidents/{0}/reassign'.format(SUBDOMAIN, INCIDENT_ID),
17+
'https://{0}.pagerduty.com/api/v1/incidents/{1}/reassign'.format(SUBDOMAIN, INCIDENT_ID),
1818
headers=headers,
1919
)
2020
print r.status_code

REST_API_v1/MaintenanceWindows/POST_MaintenanceWindow/create_maintenance_window.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
#!/usr/bin/env python
22
import requests
3+
import datetime
4+
import json
35

46

57
SUBDOMAIN='pdt-dank'
68
API_ACCESS_KEY='HjEs6A6KozribnKqm1tX'
9+
SERVICE_IDS=['XYZ0ABC']
710

8-
9-
def get_maintenance_window_by_id():
11+
def create_maintenance_window(minutes=5):
12+
"""Create a maintenance window starting now"""
1013
headers = {
1114
'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
1215
'Content-type': 'application/json',
1316
}
14-
r = requests.get(
15-
'https://{0}.pagerduty.com/api/v1/maintenance_windows/{1}'.format(SUBDOMAIN, MAINTENANCE_WINDOW_ID),
17+
payload = {
18+
"maintenance_window": {
19+
'start_time': datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%SZ"),
20+
'end_time': (datetime.datetime.utcnow() + datetime.timedelta(minutes=minutes)).strftime("%Y-%m-%d %H:%M:%SZ"),
21+
"description": "Description goes here",
22+
"service_ids": PD_SERVICE_IDS,
23+
}
24+
}
25+
r = requests.post(
26+
'https://{0}.pagerduty.com/api/v1/maintenance_windows'.format(SUBDOMAIN),
1627
headers=headers,
28+
data=json.dumps(payload)
1729
)
1830
print r.status_code
1931
print r.text

0 commit comments

Comments
 (0)