Created
August 19, 2016 21:51
-
-
Save lichti/4e640b9781fa297f0180af93aaae4284 to your computer and use it in GitHub Desktop.
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 | |
hook_url='https://hooks.slack.com/services/' | |
hook_hash='XXXXXXXXXXXXXXXXXXXXXXXXXX' | |
username='INFRA-BOT' | |
url="$hook_url/$hook_hash" | |
to="${1:-"#generic"}" | |
subject="${2:-"INFO"}" | |
environment="${3:-"Unknown"}" | |
project=${4:-"Unknown"} | |
color=${5:-"#000000"} | |
recoversub='^RECOVER(Y|ED)?$' | |
if [[ "$subject" =~ ${recoversub} ]]; then | |
subject='RECOVERED' | |
fi | |
case "$subject" in | |
"INFO") | |
emoji=':+1:' | |
;; | |
"WARNING") | |
emoji=':warning:' | |
;; | |
"ERROR") | |
emoji=':bangbang:' | |
;; | |
"BACKUP") | |
emoji=':package:' | |
;; | |
"PROBLEM") | |
emoji=':shit:' | |
;; | |
"RECOVERED") | |
emoji=':pray:' | |
;; | |
*) | |
emoji=':ghost:' | |
;; | |
esac | |
message="${subject}: $6" | |
#payload="payload={\"channel\": \"${to//\"/\\\"}\", \"username\": \"${username//\"/\\\"}\", \"text\": \"${message//\"/\\\"}\", \"icon_emoji\": \"${emoji}\"}" | |
payload="payload={ | |
\"channel\": \"${to//\"/\\\"}\", | |
\"username\": \"${username//\"/\\\"}\", | |
\"icon_emoji\": \"${emoji}\", | |
\"attachments\": [ { | |
\"fallback\": \"${message//\"/\\\"}\", | |
\"text\": \"${message//\"/\\\"}\", | |
\"fields\": [ { | |
\"title\": \"Project\", | |
\"value\": \"${project//\"/\\\"}\", | |
\"short\": true | |
}, | |
{ \"title\": \"Environment\", | |
\"value\": \"${environment//\"/\\\"}\", | |
\"short\": true}], | |
\"color\": \"${color}\" | |
} | |
] | |
}" | |
curl -m 5 --data-urlencode "${payload}" $url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment