Created
September 14, 2017 08:36
-
-
Save lionel-deglise/b5a41797ab377d6448756fde91675a87 to your computer and use it in GitHub Desktop.
Slack notification with 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