Zabbix – Send alerts to Slack

Zabbix – Send alerts to Slack

2017-04-20 2 Par seuf

Today I’ve configured my Zabbix Server to automatically send alerts to the #alerting channel of my slack team.

To to this, you have to create un new Incoming WebHook in your slack Team.

  • Click on your team, select App and Integration.
  • Search for Incoming Webhook
  • Click « Add a configuration »
  • Configure the webhook with the default destination topic, etc..
  • Copy the generated URL in your clipboard, you will need it later. The webhook url is something like https://hooks.slack.com/services/ABCDEFGHIJKJMNOPQRSTUVWXYZ

Next Go to your Zabbix Server.

Edit the /etc/zabbix/zabbix_server.conf file to specify a correct Path for AlertScriptPath, for example :

AlertScriptsPath=/usr/share/zabbix/alertscripts

Then go to the /usr/share/zabbix/alertscripts directory and create a tiny shell script post_to_slack.sh :

#!/bin/sh

webhook_url=$1
message=$2

curl -k -X POST -d "payload={\"username\":\"zabbix\", \"text\":\"$message\"}" $webhook_url

Then Go to The Zabbix IHM and add a new media type of type script, with the script name you created before (Administration > Media Types > create media type)

Add 2 parameters for your script :

  1. The first one is the Slack Webhook URL you generated in step 1,
  2. the second is the Alert Subject.

Then, Configure a Zabbix Actions (Configuration > Actions) to send a message to slack media for the admin user.

Set a correct Subject message to get all the information you need. For example :

[{HOST.HOST}] {TRIGGER.SEVERITY}: {TRIGGER.NAME}

Finaly edit the Zabbix admin user and add a new media of type slack.

That’s It !

Now all your Zabbix Alerts are sent to your slack #alerting Channel \o/

PS : You can configure multiple slack media type to send alerts to multiple webhooks, according to the Host group.