A D Vishnu Prasad

CID - Cloud Infrastructure Desinger

Send Hipchat Notifications Using Python

There might be scenarios where you want to send hipchat notifications programatically. Following python script will help you to create notifications in 3 simple steps.

Hipchat Image * Image credit: google images

Step 1:

Generate your auth token from your hipchat account. Hipchat -> Account Settings -> API Access

Step 2:

Note: I am using hipchat api v1.

hipchat.py
1
2
3
4
5
6
7
8
#!/usr/bin/env python3.5

import requests, json

def notify(message, deployer = 'Vishnu', color = 'green'):
  url = "https://api.hipchat.com/v1/rooms/message?auth_token=<auth_token>&format=json"
  payload = { "room_id" : "deployments" , "from" : deployer, "message" : message, "color" : color, "notify" : 1 }
  requests.post(url, params=payload)

Step 3:

deployer.py
1
2
3
4
5
6
7
8
9
#!/usr/bin/env python3.5

import hipchat

# For successful notif
hipchat.notify("Deployment started", "Vishnu", "green")

# If you want error notif
hipchat.notify("Deployment failed", "Vishnu", "red")

Comments