Created
January 6, 2016 13:59
-
-
Save jriguera/c5352cf152ee6f3cc5a9 to your computer and use it in GitHub Desktop.
how to notify slack and hipchat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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