Skip to content

Instantly share code, notes, and snippets.

@jagland
Created April 12, 2023 17:38
Show Gist options
  • Save jagland/49471d0fd8b5acbed4f3956e0b5ee1a1 to your computer and use it in GitHub Desktop.
Save jagland/49471d0fd8b5acbed4f3956e0b5ee1a1 to your computer and use it in GitHub Desktop.
#!/bin/bash
SLACK_WEBHOOK="https://hooks.slack.com/services/..."
SLACK_CHANNEL="#alerts"
SLACK_USERNAME="monit on $MONIT_HOST"
if [[ "$MONIT_DESCRIPTION" =~ .*"succeeded".* ]]; then
SLACK_ICON=":white_check_mark:"
SLACK_USERNAME="monit on $MONIT_HOST - service up"
elif [[ "$MONIT_DESCRIPTION" =~ .*"failed".* ]]; then
SLACK_ICON=":exclamation:"
SLACK_USERNAME="monit on $MONIT_HOST - service down"
else
SLACK_ICON=":grey_exclamation:"
fi
curl -s -X POST --data-urlencode "payload={\"channel\": \"$SLACK_CHANNEL\", \"username\": \"$SLACK_USERNAME\", \"text\": \"*$MONIT_SERVICE* - $MONIT_DESCRIPTION\", \"icon_emoji\": \"$SLACK_ICON\"}" $SLACK_WEBHOOK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment