Skip to content

Instantly share code, notes, and snippets.

@adyrcz
Last active April 12, 2016 22:56
Show Gist options
  • Save adyrcz/598c686a6d9aaf3f5f8ca00b926f7c09 to your computer and use it in GitHub Desktop.
Save adyrcz/598c686a6d9aaf3f5f8ca00b926f7c09 to your computer and use it in GitHub Desktop.
Update Hipchat room topic with who is on call from PagerDuty
#!/usr/bin/env python
import requests, json
SUBDOMAIN='SUBDOMAIN'
API_ACCESS_KEY='YOURAPIACCESSKEY'
AUTH_CODE='APIAUTHCODE'
def get_oncall_name():
url = 'https://{0}.pagerduty.com/api/v1/escalation_policies/on_call'.format(SUBDOMAIN)
headers = {
'Authorization': 'Token token={0}'.format(API_ACCESS_KEY),
'Content-Type': 'application/json',
}
data = {'query': 'ops-default-escalation'}
payload = json.dumps(data)
r = requests.get(url, data=payload, headers=headers)
oncall = r.json()
whosoncall = oncall['escalation_policies'][0]['on_call'][0]['user']['name']
return whosoncall
def notify_hipchat():
whoisoncall = get_oncall_name()
hcurl = 'https://opinionlab.hipchat.com/v2/room/ROOM_ID/topic?auth_token={1}'.format(AUTH_CODE)
message = '{"topic" : "OnCall: %s"}' % whoisoncall
headers = {'content-type' : 'application/json'}
res = requests.put(hcurl, data=message, headers=headers)
print res
notify_hipchat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment