Skip to content

Instantly share code, notes, and snippets.

@jriguera
Created January 6, 2016 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jriguera/c5352cf152ee6f3cc5a9 to your computer and use it in GitHub Desktop.
Save jriguera/c5352cf152ee6f3cc5a9 to your computer and use it in GitHub Desktop.
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