Skip to content

Instantly share code, notes, and snippets.

@K0rell
Created November 15, 2018 16:59
Show Gist options
  • Save K0rell/2c8d3c2fd695aafe00567649b30e74c5 to your computer and use it in GitHub Desktop.
Save K0rell/2c8d3c2fd695aafe00567649b30e74c5 to your computer and use it in GitHub Desktop.
Zabbix Alert in slack channel
#!/bin/bash
# Requirement curl
# Create new script in nano /usr/lib/zabbix/alertscripts/media-slack.sh
# chmod +x media-slack.sh
# Create Slack App https://api.slack.com/apps/new
# Choose your app
# Select and active Incomming Webhooks
# Choose your channel to send messages
# Get the webhooks URL and update the script !
# ZABBIX Administration > Media types > Create media type
# Name = Slack
# Type = Script
# Script name = media-slack.sh
# Script parameters (one per line with {}) = {ALERT.SENDTO} {ALERT.SUBJECT} {ALERT.MESSAGE}
# Administration > User > Media > Add (to slack channel)
TO=$1 # {ALERT.SENDTO} not used
MESSAGE="$2\n$3" # {ALERT.SUBJECT} \n {ALERT.MESSAGE}
curl -X POST -H 'Content-type: application/json' --data @<(cat <<EOF
{
"text": "$MESSAGE",
}
EOF
) https://hooks.slack.com/services/XXXXXXXX/XXXXXXXX/XXXXXXXXXXX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment