-
-
Save XaviTorello/d6e31df22746fa790d28 to your computer and use it in GitHub Desktop.
HipChat API v2 - Send a message to a room using cURL
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
#!/bin/bash | |
# Call it with $ ./hipchat-v2.sh "MESSGE" [STATUS | NOTIFICATION_TYPE] | |
# , optional parameters | |
# STATUS = 'w|c|o|u' | |
# NOTIFICATION_TYPE = "PROBLEM|RECOVERY|FLAPPING*|DOWNTIME*" | |
# | |
# Set the ROOM_ID & AUTH_TOKEN variables below. | |
# Ready to be integrated on Shinken / Nagios / Centreon as a new notification system | |
# Further instructions at https://www.hipchat.com/docs/apiv2/auth | |
ROOM_ID= | |
AUTH_TOKEN= | |
if [ -z $1 ]; then | |
echo "Provide a message to create the new notification" | |
exit 1 | |
fi | |
PRIORITAT=$2 | |
case $PRIORITAT in | |
w) | |
COLOR="yellow" | |
;; | |
c) | |
COLOR="red" | |
;; | |
o) | |
COLOR="green" | |
;; | |
u) | |
COLOR="purple" | |
;; | |
PROBLEM) | |
COLOR="red" | |
;; | |
RECOVERY) | |
COLOR="green" | |
;; | |
FLAPPINGSTART|FLAPPINGSTOP|FLAPPINGDISABLED) | |
COLOR="yellow" | |
;; | |
DOWNTIMESTART|DOWNTIMESTOP|DOWNTIMECANCELLED) | |
COLOR="purple" | |
;; | |
*) | |
COLOR="gray" | |
;; | |
esac | |
MESSAGE=$1 | |
curl -H "Content-Type: application/json" \ | |
-X POST \ | |
-d "{\"color\": \"$COLOR\", \"message_format\": \"text\", \"message\": \"$MESSAGE\" }" \ | |
https://api.hipchat.com/v2/room/$ROOM_ID/notification?auth_token=$AUTH_TOKEN | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment