Skip to content

Instantly share code, notes, and snippets.

@lichti
Last active September 29, 2016 17:47
Show Gist options
  • Save lichti/2f962e1548a4175daf4ffc8f746c2e9d to your computer and use it in GitHub Desktop.
Save lichti/2f962e1548a4175daf4ffc8f746c2e9d to your computer and use it in GitHub Desktop.
#!/bin/bash
hook_url='https://hooks.slack.com/services/'
hook_hash='XXXXXXXXXXXXXXX/YYYYYYYYYYYYYYYYYYYYYYYYYY'
username='INFRA-BOT'
url="$hook_url/$hook_hash"
to="${1:-"#lichtiteste"}"
subject="${2:-"INFO"}"
recoversub='^RECOVER(Y|ED)?$'
if [[ "$subject" =~ ${recoversub} ]]; then
subject='RECOVERED'
fi
case "$subject" in
"INFO")
emoji=':+1:'
color="#0000FF"
;;
"WARNING")
emoji=':warning:'
color="#FFFF00"
;;
"ERROR")
emoji=':bangbang:'
color="#FF0000"
;;
"BACKUP")
emoji=':package:'
color="#FFFF00"
;;
"PROBLEM")
emoji=':shit:'
color="#FF0000"
;;
"RECOVERED")
emoji=':pray:'
color="#00FF00"
;;
*)
emoji=':ghost:'
color="#000000"
;;
esac
message="${subject}: $3"
#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//\"/\\\"}\",
\"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