Difference between revisions of "Pager Duty API Python"
Jump to navigation
Jump to search
(Created page with "https://community.pagerduty.com/forum/t/resolving-an-incident-using-pagerduty-events-v2-or-incident-api/1880 ``` def resolve_incident(self, device_id, message): url = "htt...") |
|||
Line 1: | Line 1: | ||
+ | https://github.com/PagerDuty/pdpyras | ||
+ | |||
+ | |||
https://community.pagerduty.com/forum/t/resolving-an-incident-using-pagerduty-events-v2-or-incident-api/1880 | https://community.pagerduty.com/forum/t/resolving-an-incident-using-pagerduty-events-v2-or-incident-api/1880 | ||
``` | ``` | ||
Line 25: | Line 28: | ||
print(r.text) | print(r.text) | ||
return False | return False | ||
+ | ``` | ||
+ | |||
+ | |||
+ | ``` | ||
+ | session.rput( | ||
+ | "incidents", | ||
+ | json=[ | ||
+ | {'id':'PABC123','type':'incident_reference', 'status':'resolved'}, | ||
+ | {'id':'PDEF456','type':'incident_reference', 'status':'resolved'}, | ||
+ | ], | ||
+ | ) | ||
``` | ``` |
Revision as of 19:07, 7 March 2022
https://github.com/PagerDuty/pdpyras
def resolve_incident(self, device_id, message): url = "https://events.pagerduty.com/v2/enqueue" print(url) headers = { "Accept": "application/vnd.pagerduty+json;version=2", "Authorization": "Token token={}".format(self.pagerDuty_api_key), "From": "xys@assa.com", "Content-Type": "application/json" } payload = { "routing_key": self.pagerDuty_integration_key, "dedup_key": device_id, "event_action": "acknowledge" } r = requests.post(url, data=json.dumps(payload), headers=headers) if r.status_code == 200: print(r.json) return True else: print(r.status_code) print(r.text) return False
session.rput( "incidents", json=[ {'id':'PABC123','type':'incident_reference', 'status':'resolved'}, {'id':'PDEF456','type':'incident_reference', 'status':'resolved'}, ], )