Skip to content

Instantly share code, notes, and snippets.

@Deconstrained
Last active February 7, 2017 17:37
Show Gist options
  • Save Deconstrained/6729c66912827265118d383e7234494f to your computer and use it in GitHub Desktop.
Save Deconstrained/6729c66912827265118d383e7234494f to your computer and use it in GitHub Desktop.
PagerDuty Team to Integration Email Report
#!/usr/bin/env python
# Generates a report in CSV format showing the integration emails used on services corresponding to each team
import csv,pypd,sys
pypd.api_key='' # Your API key here
teamobjs = pypd.Team.find()
teams = {}
for team in teamobjs:
teamid = team['id']
teamname = team['name']
print 'Getting services for team "%s", id=%s'%(teamname,teamid)
serviceobjs = pypd.Service.find(team_ids=[teamid],include=['integrations'])
print 'Team "%s" has %d associated services'%(teamname,len(serviceobjs))
teams[teamname] = set([])
for service in serviceobjs:
for integration in service['integrations']:
if 'integration_email' in integration:
teams[teamname].add((
integration['name'],
integration['integration_email']
))
print 'Writing CSV file...'
with open('teams-integration-emails.csv','wb') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Team Name','Integration','Integration Key'])
for teamname,integrations in teams.items():
if not len(integrations):
writer.writerow([teamname,'',''])
for (name,email) in integrations:
writer.writerow([teamname,name,email])
print 'Data written to teams-integration-emails.csv'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment