Skip to content

Instantly share code, notes, and snippets.

@lucaspar
Created October 6, 2023 14:44
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 lucaspar/64c9cf35756d1892e749c1bd735aa0fe to your computer and use it in GitHub Desktop.
Save lucaspar/64c9cf35756d1892e749c1bd735aa0fe to your computer and use it in GitHub Desktop.
Slack notification script
#!/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