Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions EVENTS_API_V1/Ack/ack_incident.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

import json
import requests

SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE
INCIDENT_KEY = "" # ENTER INCIDENT KEY

def trigger_incident():
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events

payload = { # Payload is built with the least amount of fields required to trigger an incident
"service_key": SERVICE_KEY,
"event_type": "acknowledge",
"incident_key": INCIDENT_KEY,
"description": "Example alert on host1.example.com"
}

response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
data=json.dumps(payload))

if response.json()["status"] == "success":
print ('Incident Acknowledged')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
trigger_incident()
29 changes: 29 additions & 0 deletions EVENTS_API_V1/Resolve/resolve_incident.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

import json
import requests

SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE
INCIDENT_KEY = "" # ENTER INCIDENT KEY

def trigger_incident():
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events

payload = { # Payload is built with the least amount of fields required to trigger an incident
"service_key": SERVICE_KEY,
"event_type": "resolve",
"incident_key": INCIDENT_KEY,
"description": "Example alert on host1.example.com"
}

response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
data=json.dumps(payload))

if response.json()["status"] == "success":
print ('Incident Resolved')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
trigger_incident()
29 changes: 29 additions & 0 deletions EVENTS_API_V1/Trigger/trigger_with_incident_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python

import json
import requests

SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE
INCIDENT_KEY = "" # ENTER INCIDENT KEY

def trigger_incident():
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events

payload = { # Payload is built with the least amount of fields required to trigger an incident
"service_key": SERVICE_KEY,
"event_type": "trigger",
"incident_key": INCIDENT_KEY,
"description": "Example alert on host1.example.com"
}

response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
data=json.dumps(payload))

if response.json()["status"] == "success":
print ('Incident Triggered')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
trigger_incident()
27 changes: 27 additions & 0 deletions EVENTS_API_V1/Trigger/trigger_without_incident_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env python

import json
import requests

SERVICE_KEY = "" # ENTER EVENTS V1 API INTEGRATION KEY HERE

def trigger_incident():
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V1 API - documentation: https://v2.developer.pagerduty.com/docs/trigger-events

payload = { # Payload is built with the least amount of fields required to trigger an incident
"service_key": SERVICE_KEY,
"event_type": "trigger",
"description": "Example alert on host1.example.com"
}

response = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
data=json.dumps(payload))

if response.json()["status"] == "success":
print ('Incident created with with incident / alert key of ' + '"' + response.json()['incident_key'] + '"')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
trigger_incident()
50 changes: 22 additions & 28 deletions EVENTS_API_v2/ack/ack_incident.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
#!/usr/bin/env python

import json
import requests

ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE
INCIDENT_KEY = "" # ENTER INCIDENT KEY HERE

SUBDOMAIN = "" # Enter your subdomain here
API_ACCESS_KEY = "" # Enter your subdomain's API access key here

def trigger_incident():
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

def ack_incident():
"""Acknowledges a triggered incident using the customer's API access key and incident key."""

headers = {
'Accept': 'application/vnd.pagerduty+json;version=2',
'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
'Content-type': 'application/json'
header = {
"Content-Type": "application/json"
}

payload = json.dumps({
"service_key": "", # Enter the service key here
"incident_key": "", # Enter the incident key here
"event_type": "acknowledge",
"description": "Andrew now working on the problem.", # Enter your own description
"details": {
"work started": "2010-06-10 05:43"
}
})

r = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
headers=headers,
data=payload,
)

print r.status_code
print r.text
payload = { # Payload is built with the least amount of fields required to trigger an incident
"routing_key": ROUTING_KEY,
"event_action": "acknowledge",
"dedup_key": INCIDENT_KEY
}

response = requests.post('https://events.pagerduty.com/v2/enqueue',
data=json.dumps(payload),
headers=header)

if response.json()["status"] == "success":
print ('Incident Acknowledged ')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
ack_incident()
trigger_incident()
50 changes: 22 additions & 28 deletions EVENTS_API_v2/resolve/resolve_incident.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
#!/usr/bin/env python

import json
import requests

ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE
INCIDENT_KEY = "" # ENTER INCIDENT KEY HERE

SUBDOMAIN = "" # Enter your subdomain here
API_ACCESS_KEY = "" # Enter your subdomain's API access key here

def trigger_incident():
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

def resolve_incident():
"""Resolves a PagerDuty incident using customer's API access key and incident key."""

headers = {
'Accept': 'application/vnd.pagerduty+json;version=2',
'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
'Content-type': 'application/json',
header = {
"Content-Type": "application/json"
}

payload = json.dumps({
"service_key": "", # Enter service key here
"incident_key": "", # Enter incident key here
"event_type": "resolve",
"description": "Andrew fixed the problem.", # Enter personalized description
"details": {
"fixed at": "2010-06-10 06:00"
}
})

r = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
headers=headers,
data=payload,
)

print r.status_code
print r.text
payload = { # Payload is built with the least amount of fields required to trigger an incident
"routing_key": ROUTING_KEY,
"event_action": "resolve",
"dedup_key": INCIDENT_KEY
}

response = requests.post('https://events.pagerduty.com/v2/enqueue',
data=json.dumps(payload),
headers=header)

if response.json()["status"] == "success":
print ('Incident Resolved ')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
resolve_incident()
trigger_incident()
52 changes: 24 additions & 28 deletions EVENTS_API_v2/trigger/trigger_with_incident_key.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,38 @@
#!/usr/bin/env python

import json
import requests


SUBDOMAIN = "" # Enter your subdomain here
API_ACCESS_KEY = "" # Enter your subdomain's API access key here

ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE
INCIDENT_KEY = "" # ENTER INCIDENT KEY HERE

def trigger_incident():
"""Triggers an incident with a previously generated incident key."""
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

headers = {
'Accept': 'application/vnd.pagerduty+json;version=2',
'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
'Content-type': 'application/json',
header = {
"Content-Type": "application/json"
}

payload = json.dumps({
"service_key": "", # Enter service key here
"incident_key": "srv01/HTTP",
"event_type": "trigger",
"description": "FAILURE for production/HTTP on machine srv01.acme.com",
"client": "Sample Monitoring Service",
"client_url": "https://monitoring.service.com",
"details": {
"ping time": "1500ms",
"load avg": 0.75
payload = { # Payload is built with the least amount of fields required to trigger an incident
"routing_key": ROUTING_KEY,
"event_action": "trigger",
"dedup_key": INCIDENT_KEY,
"payload": {
"summary": "Example alert on host1.example.com",
"source": "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003",
"severity": "critical"
}
})

r = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
headers=headers,
data=payload,
)

print r.status_code
print r.text
}

response = requests.post('https://events.pagerduty.com/v2/enqueue',
data=json.dumps(payload),
headers=header)

if response.json()["status"] == "success":
print ('Incident Created')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
trigger_incident()
49 changes: 22 additions & 27 deletions EVENTS_API_v2/trigger/trigger_without_incident_key.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
#!/usr/bin/env python

import json
import requests


SUBDOMAIN = "" # Enter your subdomain here
API_ACCESS_KEY = "" # Enter your subdomain's API access key here

ROUTING_KEY = "" # ENTER EVENTS V2 API INTEGRATION KEY HERE

def trigger_incident():
"""Triggers a PagerDuty incident without a previously generated incident key."""
# Triggers a PagerDuty incident without a previously generated incident key
# Uses Events V2 API - documentation: https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2

headers = {
'Accept': 'application/vnd.pagerduty+json;version=2',
'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
'Content-type': 'application/json',
header = {
"Content-Type": "application/json"
}

payload = json.dumps({
"service_key": "", # Enter service key here
"event_type": "trigger",
"description": "FAILURE for production/HTTP on machine srv01.acme.com",
"client": "Sample Monitoring Service",
"client_url": "https://monitoring.service.com",
"details": {
"ping time": "1500ms",
"load avg": 0.75
payload = { # Payload is built with the least amount of fields required to trigger an incident
"routing_key": ROUTING_KEY,
"event_action": "trigger",
"payload": {
"summary": "Example alert on host1.example.com",
"source": "monitoringtool:cloudvendor:central-region-dc-01:852559987:cluster/api-stats-prod-003",
"severity": "critical"
}
})

r = requests.post('https://events.pagerduty.com/generic/2010-04-15/create_event.json',
headers=headers,
data=payload,
)

print r.status_code
print r.text
}

response = requests.post('https://events.pagerduty.com/v2/enqueue',
data=json.dumps(payload),
headers=header)

if response.json()["status"] == "success":
print ('Incident created with with dedup key (also known as incident / alert key) of ' + '"' + response.json()['dedup_key'] + '"')
else:
print response.text # print error message if not successful

if __name__ == '__main__':
trigger_incident()
Loading