Call Slack Hooks With Zabbix 4.2 Triggers

Published: 08 May 2019
on channel: SBCODE
5,671
58

Zabbix 5 Course : https://sbcode.net/zabbix/

I have a slack account, and I create an app for it that accepts incoming web hooks.
I get the sample URL from the app page and use it when a trigger is called in Zabbix.
On Zabbix, I create the media type and call it Slack, which calls a script, which I create on the file system, which also accepts a macro property named {ALERT.SUBJECT}

I then clone an existing trigger and make it happen all the time and set its severity to high so that my account gets the alerts in slack.
I also have slack on my phone, so I also get alerts there.

On zabbix server, I go to folder
/usr/lib/zabbix/alertscripts
and create a new file named slackalert.sh

########### slackalert.sh ###########
#!/bin/bash
curl -X POST -H 'Content-type: application/json' --data '{"text":"'"$1"'"}' https://hooks.slack.com/services/[your slack hook tokens]
##### end slackalert.sh ##########

Save, then give the file execute permissions,
$ chmod a+x /usr/lib/zabbix/alertscripts/slackalert.sh

Go back into Zabbix and create a new media type,
Name = 'Slack Alert'
Type = 'Script'
Script Name = slackalert.sh
Script Parameters = {ALERT.SUBJECT}

In zabbix4.2, you can test using the 'test' option for the new media type.

Open your slack channel on your browser and/or mobile phone and see the real time alerts.
Note that the slackalert.sh script is only passing the {ALERT.SUBJECT} value, so the 'Send To' and 'Message' test fields are ignored.

Thanks for watching, remember to like, comment, subscribe and share.

#zabbix-slack-alert