Last active
July 23, 2020 18:06
-
-
Save stmcallister/cdb8f9c753bfa77c35916113ca819023 to your computer and use it in GitHub Desktop.
Python script for creating an Event and then retrieving the Incident in PagerDuty
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
import pdpyras | |
import time | |
from pdpyras import APISession | |
# API Token and Session for REST API | |
api_token = 'your_api_token' | |
rest_session = APISession(api_token) | |
# Routing Key and Session for Events API | |
routing_key = 'your_routing_key' | |
events_session = pdpyras.EventsAPISession(routing_key) | |
# Trigger Event with Events API. Get dedup_key | |
dedup_key = events_session.trigger("Server is on fire", 'dusty.old.server.net') | |
print(dedup_key) | |
# Pause for 3 seconds, because it makes a bit of time for the data in both APIs to sync | |
time.sleep(3) | |
# Use dedup_key to get incident from REST API by passing it as the value of the incident_key param | |
response = rest_session.get('incidents', params={'incident_key': dedup_key}) | |
# Parse response from REST API and retrieve the values of the incident by name, such as 'incident_number', etc | |
incidents = response.json()['incidents'] | |
print(incidents[0]['incident_number']) | |
print(incidents[0]['id']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment