Created
March 15, 2021 23:53
-
-
Save Caffe1neAdd1ct/6e86f9b3a265e6c458dce56086409921 to your computer and use it in GitHub Desktop.
Colourful Slack Notification In Bash
This file contains hidden or 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 | |
## Slack Alert Helper | |
function send_slack_message() { | |
action="$1" | |
status=$2 | |
message="$3" | |
case "$status" in | |
success ) color="#44d058";; | |
warning ) color="#D09E44";; | |
error ) color="#d84b4b";; | |
info ) color="#7099e6";; | |
primary ) color="#4360df";; | |
secondary ) color="#838c93";; | |
* ) color="#838c93";; | |
esac | |
curl -X POST --silent --output /dev/null \ | |
-H 'Content-type: application/json' \ | |
-H "Accept: application/json" \ | |
--data @<(cat <<EOF | |
{ | |
"attachments": [ | |
{ | |
"title": "$action", | |
"color": "$color", | |
"text": "$message" | |
} | |
], | |
"channel": "dedicated-server-backups" | |
} | |
EOF | |
) https://hooks.slack.com/services/XXXX/XXXX/XXXXXXXXXXXXXX & disown > /dev/null 2>&1 | |
} | |
send_slack_message "Example Action" "primary" "Some details about this action" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment