Created
August 28, 2015 01:15
-
-
Save janeczku/24ced51b05a70347f4ba to your computer and use it in GitHub Desktop.
Slack notifications via 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 | |
function post_to_slack () { | |
# format message as a code block ```${msg}``` | |
SLACK_MESSAGE="\`\`\`$1\`\`\`" | |
SLACK_URL=https://hooks.slack.com/services/your-service-identifier-part-here | |
case "$2" in | |
INFO) | |
SLACK_ICON=':slack:' | |
;; | |
WARNING) | |
SLACK_ICON=':warning:' | |
;; | |
ERROR) | |
SLACK_ICON=':bangbang:' | |
;; | |
*) | |
SLACK_ICON=':slack:' | |
;; | |
esac | |
curl -X POST --data "payload={\"text\": \"${SLACK_ICON} ${SLACK_MESSAGE}\"}" ${SLACK_URL} | |
} | |
post_to_slack "Hello, World" "INFO" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment