Skip to content

Instantly share code, notes, and snippets.

@dgulinobw
Created January 11, 2017 00:28
Show Gist options
  • Save dgulinobw/cca8cc06e30fb42bb658eabd597da601 to your computer and use it in GitHub Desktop.
Save dgulinobw/cca8cc06e30fb42bb658eabd597da601 to your computer and use it in GitHub Desktop.
Lists top 10 PagerDuty incident services, and top 10 incident summaries
#!/usr/bin/env python
from __future__ import print_function
import json
import re
from easyprocess import EasyProcess
import pandas as pd
more = True
page_size = 25
offset = 0
token = "$TOKEN"
date_since = "2016-12-01"
incidents_list = []
while more:
#curl = "curl -s -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=" + token + "' 'https://api.pagerduty.com/incidents?since=" + date_since +"T00%3A00Z&statuses%5B%5D=resolved&time_zone=UTC&include%5B%5D=services&limit=" + str(page_size) + "&offset=" + str(offset) + "'"
curl = "curl -s -X GET --header 'Accept: application/vnd.pagerduty+json;version=2' --header 'Authorization: Token token=" + token + "' 'https://api.pagerduty.com/incidents?since=" + date_since +"&statuses%5B%5D=resolved&time_zone=UTC&include%5B%5D=services&limit=" + str(page_size) + "&offset=" + str(offset) + "'"
result = EasyProcess(curl).call().stdout
result = json.loads(result)
more = bool(result['more'])
incidents = result['incidents']
for i in incidents:
summary_parsed = " ".join(i['summary'].split(" ")[1:])
summary_parsed = re.sub('((1[0-2]|0?[1-9]):([0-5][0-9])([AaPp][Mm]))', '$TIME', summary_parsed)
summary_parsed = re.sub('https://scoutapp.com/a/..........', '$LINK', summary_parsed)
incidents_list.append([i['created_at'], i['service']['name'], summary_parsed])
#print(i['created_at'] + ", " + i['service']['name'] + ", " + i['summary'])
offset = offset+page_size
df = pd.DataFrame(incidents_list, columns=['created_at', 'service', 'summary'])
print("PagerDuty Incidents, since: ", date_since)
print("# of incidents:", len(incidents_list))
print("".join(["-" for x in range(1, 80)]))
print
print("Top 10 Services")
print("".join(["-" for x in range(1, 80)]))
print(df["service"].value_counts()[:10])
print("".join(["#" for x in range(1, 80)]))
print()
print("Top 10 Summaries")
print("".join(["-" for x in range(1, 80)]))
print(df["summary"].value_counts()[:10])
print("".join(["#" for x in range(1, 80)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment