diff --git a/REST_API_v1/Incidents/PUT_Incidents_Ack/ack_incident.py b/REST_API_v1/Incidents/PUT_Incidents_Ack/ack_incident.py index fa1222b..a3af19c 100755 --- a/REST_API_v1/Incidents/PUT_Incidents_Ack/ack_incident.py +++ b/REST_API_v1/Incidents/PUT_Incidents_Ack/ack_incident.py @@ -14,7 +14,7 @@ def ack_incident(): 'Content-type': 'application/json', } r = requests.put( - 'https://{0}.pagerduty.com/api/v1/incidents/{0}/acknowledge'.format(SUBDOMAIN, INCIDENT_ID), + 'https://{0}.pagerduty.com/api/v1/incidents/{1}/acknowledge?requester_id={2}'.format(SUBDOMAIN, INCIDENT_ID, REQUESTER_ID), headers=headers, ) print r.status_code diff --git a/REST_API_v1/Incidents/PUT_Incidents_Reassign/reassign_incident.py b/REST_API_v1/Incidents/PUT_Incidents_Reassign/reassign_incident.py index bfc7817..fcdf663 100755 --- a/REST_API_v1/Incidents/PUT_Incidents_Reassign/reassign_incident.py +++ b/REST_API_v1/Incidents/PUT_Incidents_Reassign/reassign_incident.py @@ -14,7 +14,7 @@ def reassign_incident(): 'Content-type': 'application/json', } r = requests.put( - 'https://{0}.pagerduty.com/api/v1/incidents/{0}/reassign'.format(SUBDOMAIN, INCIDENT_ID), + 'https://{0}.pagerduty.com/api/v1/incidents/{1}/reassign'.format(SUBDOMAIN, INCIDENT_ID), headers=headers, ) print r.status_code diff --git a/REST_API_v1/MaintenanceWindows/POST_MaintenanceWindow/create_maintenance_window.py b/REST_API_v1/MaintenanceWindows/POST_MaintenanceWindow/create_maintenance_window.py index 3b30f16..324d549 100755 --- a/REST_API_v1/MaintenanceWindows/POST_MaintenanceWindow/create_maintenance_window.py +++ b/REST_API_v1/MaintenanceWindows/POST_MaintenanceWindow/create_maintenance_window.py @@ -1,19 +1,31 @@ #!/usr/bin/env python import requests +import datetime +import json SUBDOMAIN='pdt-dank' API_ACCESS_KEY='HjEs6A6KozribnKqm1tX' +SERVICE_IDS=['XYZ0ABC'] - -def get_maintenance_window_by_id(): +def create_maintenance_window(minutes=5): +"""Create a maintenance window starting now""" headers = { 'Authorization': 'Token token={0}'.format(API_ACCESS_KEY), 'Content-type': 'application/json', } - r = requests.get( - 'https://{0}.pagerduty.com/api/v1/maintenance_windows/{1}'.format(SUBDOMAIN, MAINTENANCE_WINDOW_ID), + payload = { + "maintenance_window": { + 'start_time': datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%SZ"), + 'end_time': (datetime.datetime.utcnow() + datetime.timedelta(minutes=minutes)).strftime("%Y-%m-%d %H:%M:%SZ"), + "description": "Description goes here", + "service_ids": PD_SERVICE_IDS, + } + } + r = requests.post( + 'https://{0}.pagerduty.com/api/v1/maintenance_windows'.format(SUBDOMAIN), headers=headers, + data=json.dumps(payload) ) print r.status_code print r.text