Skip to content

Instantly share code, notes, and snippets.

@Caffe1neAdd1ct
Created March 15, 2021 23:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Caffe1neAdd1ct/6e86f9b3a265e6c458dce56086409921 to your computer and use it in GitHub Desktop.
Save Caffe1neAdd1ct/6e86f9b3a265e6c458dce56086409921 to your computer and use it in GitHub Desktop.
Colourful Slack Notification In Bash
#!/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