Created
October 6, 2023 14:44
-
-
Save lucaspar/64c9cf35756d1892e749c1bd735aa0fe to your computer and use it in GitHub Desktop.
Slack notification script
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/env bash | |
# Slack Notifications | |
SLACK_WEBHOOK_URL_DEFAULT="https://hooks.slack.com/services/GET/A/LINK" | |
SLACK_WEBHOOK_URL="$SLACK_WEBHOOK_URL_DEFAULT" | |
SLACK_PREFIX="${SLACK_PREFIX:=\`$(hostname)\`}" | |
# notify about error on slack channel if errors happened | |
function _slack_notify() { | |
local ERROR_MESSAGE="$SLACK_PREFIX | $1" | |
curl -X POST -H 'Content-type: application/json' --data '{"text": "'"$ERROR_MESSAGE"'"}' "$SLACK_WEBHOOK_URL" &>/dev/null | |
} | |
# pass arguments to function | |
_slack_notify "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment