Skip to content

Instantly share code, notes, and snippets.

@jriguera
Created January 6, 2016 13:59
Embed
What would you like to do?
how to notify slack and hipchat
# Define those variables according to hipchar of slack (in this case is for slack)
ROOM_ID="XXXXX"
ROOM_TOKEN="XXXXXX/XXXXXXX/XXXXXXXXXXXXXXXXXXXX"
notify_hipchat() {
local msg="[$(hostname)] microBOSH/CF $ENVIRONMET $BKPLEVEL backup $BKPSTATUS"
local notify="0"
[ "$STATUS" != "1" ] && notify="1"
curl -H "Content-type: application/json" \
-H "Authorization: Bearer $ROOM_TOKEN" \
-X POST \
-d "{\"color\": \"purple\", \"message_format\": \"text\",\"notify\": \"${notify}\",\"message\": \"${msg}\"}" \
https://api.hipchat.com/v2/room/$ROOM_ID/notification
}
notify_slack() {
# format message as a code block ```${msg}```
local msg="Commvault *microBOSH/CF backups* at \`$(hostname)\`: \`\`\`$ENVIRONMET ($STAGE) $BKPLEVEL backup $BKPSTATUS\`\`\`"
local notify=":slack:"
local icon=":cow:"
[ "$STATUS" != "1" ] && notify=":bangbang:"
curl --silent -X POST \
--data "payload={\"channel\": \"#${ROOM_ID}\", \"icon_emoji\": \"${icon}\", \"text\": \"${notify} ${msg}\"}" \
https://hooks.slack.com/services/$ROOM_TOKEN > /dev/null
}
# call the proper function
#notify_hipchat
notify_slack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment