File tree Expand file tree Collapse file tree 4 files changed +161
-0
lines changed
Expand file tree Collapse file tree 4 files changed +161
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import json
3+ import requests
4+
5+
6+ SUBDOMAIN = "" # Enter your subdomain here
7+ API_ACCESS_KEY = "" # Enter your subdomain's API access key here
8+
9+
10+ def ack_incident ():
11+ """Acknowledges a triggered incident using the customer's API access key and incident key."""
12+
13+ headers = {
14+ 'Accept' : 'application/vnd.pagerduty+json;version=2' ,
15+ 'Authorization' : 'Token token={0}' .format (API_ACCESS_KEY ),
16+ 'Content-type' : 'application/json'
17+ }
18+
19+ payload = json .dumps ({
20+ "service_key" : "" , # Enter the service key here
21+ "incident_key" : "" , # Enter the incident key here
22+ "event_type" : "acknowledge" ,
23+ "description" : "Andrew now working on the problem." , # Enter your own description
24+ "details" : {
25+ "work started" : "2010-06-10 05:43"
26+ }
27+ })
28+
29+ r = requests .post ('https://events.pagerduty.com/generic/2010-04-15/create_event.json' ,
30+ headers = headers ,
31+ data = payload ,
32+ )
33+
34+ print r .status_code
35+ print r .text
36+
37+
38+ if __name__ == '__main__' :
39+ ack_incident ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import json
3+ import requests
4+
5+
6+ SUBDOMAIN = "" # Enter your subdomain here
7+ API_ACCESS_KEY = "" # Enter your subdomain's API access key here
8+
9+
10+ def resolve_incident ():
11+ """Resolves a PagerDuty incident using customer's API access key and incident key."""
12+
13+ headers = {
14+ 'Accept' : 'application/vnd.pagerduty+json;version=2' ,
15+ 'Authorization' : 'Token token={0}' .format (API_ACCESS_KEY ),
16+ 'Content-type' : 'application/json' ,
17+ }
18+
19+ payload = json .dumps ({
20+ "service_key" : "" , # Enter service key here
21+ "incident_key" : "" , # Enter incident key here
22+ "event_type" : "resolve" ,
23+ "description" : "Andrew fixed the problem." , # Enter personalized description
24+ "details" : {
25+ "fixed at" : "2010-06-10 06:00"
26+ }
27+ })
28+
29+ r = requests .post ('https://events.pagerduty.com/generic/2010-04-15/create_event.json' ,
30+ headers = headers ,
31+ data = payload ,
32+ )
33+
34+ print r .status_code
35+ print r .text
36+
37+
38+ if __name__ == '__main__' :
39+ resolve_incident ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import json
3+ import requests
4+
5+
6+ SUBDOMAIN = "" # Enter your subdomain here
7+ API_ACCESS_KEY = "" # Enter your subdomain's API access key here
8+
9+
10+ def trigger_incident ():
11+ """Triggers an incident with a previously generated incident key."""
12+
13+ headers = {
14+ 'Accept' : 'application/vnd.pagerduty+json;version=2' ,
15+ 'Authorization' : 'Token token={0}' .format (API_ACCESS_KEY ),
16+ 'Content-type' : 'application/json' ,
17+ }
18+
19+ payload = json .dumps ({
20+ "service_key" : "" , # Enter service key here
21+ "incident_key" : "srv01/HTTP" ,
22+ "event_type" : "trigger" ,
23+ "description" : "FAILURE for production/HTTP on machine srv01.acme.com" ,
24+ "client" : "Sample Monitoring Service" ,
25+ "client_url" : "https://monitoring.service.com" ,
26+ "details" : {
27+ "ping time" : "1500ms" ,
28+ "load avg" : 0.75
29+ }
30+ })
31+
32+ r = requests .post ('https://events.pagerduty.com/generic/2010-04-15/create_event.json' ,
33+ headers = headers ,
34+ data = payload ,
35+ )
36+
37+ print r .status_code
38+ print r .text
39+
40+
41+ if __name__ == '__main__' :
42+ trigger_incident ()
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+ import json
3+ import requests
4+
5+
6+ SUBDOMAIN = "" # Enter your subdomain here
7+ API_ACCESS_KEY = "" # Enter your subdomain's API access key here
8+
9+
10+ def trigger_incident ():
11+ """Triggers a PagerDuty incident without a previously generated incident key."""
12+
13+ headers = {
14+ 'Accept' : 'application/vnd.pagerduty+json;version=2' ,
15+ 'Authorization' : 'Token token={0}' .format (API_ACCESS_KEY ),
16+ 'Content-type' : 'application/json' ,
17+ }
18+
19+ payload = json .dumps ({
20+ "service_key" : "" , # Enter service key here
21+ "event_type" : "trigger" ,
22+ "description" : "FAILURE for production/HTTP on machine srv01.acme.com" ,
23+ "client" : "Sample Monitoring Service" ,
24+ "client_url" : "https://monitoring.service.com" ,
25+ "details" : {
26+ "ping time" : "1500ms" ,
27+ "load avg" : 0.75
28+ }
29+ })
30+
31+ r = requests .post ('https://events.pagerduty.com/generic/2010-04-15/create_event.json' ,
32+ headers = headers ,
33+ data = payload ,
34+ )
35+
36+ print r .status_code
37+ print r .text
38+
39+
40+ if __name__ == '__main__' :
41+ trigger_incident ()
You can’t perform that action at this time.
0 commit comments