Zabbix Slack



I’ve been using Slack and Zabbix now for a few years, and figured since there’s not too many guides out there on how to integrate the two easily. I know there are a few examples so far, but this is what’s worked best for me.

First I use this script, and put it in your alertscripts directory, ex. External hard drive not formatted for mac. /usr/lib/zabbix/alertscripts .

2
4
6
8
10
12
14
16
18
20
22
24
26
importyaml
slack_config=yaml.load(ymlfile)
slack=SlackClient(slack_config['slack_api_token'])
channel=sys.argv[1]
message='```Status: %sn%s```'%(sys.argv[2],sys.argv[3])
response=send_slack_message(channel,message)
ifresponse['ok']:
print('Message posted successfully: '+response['message']['ts'])
# If the message failed, check for rate limit headers in the response
elifresponse['ok']isFalseandresponse['headers']['Retry-After']:
# The `Retry-After` header will tell you how long to wait before retrying
print('Rate limited. Retrying in '+str(delay)+' seconds')
slack.api_call('chat.postMessage',channel=channel,text=message)
Zabbix

The path 'templates/media/slack/mediaslack.xml' does not exist at revision 'refs/heads/master'. Zabbix integration with Slack I want to be clear from the beginning, I am not going to write about Slackware (the distribution) but Slack (the platform/client chat). Zabbix is a solution for monitoring applications, networks and servers. Zabbix Slack AlertScript About. This is simply a Bash script that uses the custom alert script functionality within Zabbix along with the incoming web-hook feature of Slack.I originally created this since I could not find any already existing/similar scripts at the time. GitHub Gist: instantly share code, notes, and snippets. Alertscript for Zabbix to Slack. February 23, 2016 February 24, 2016.

Notice there’s no field for credentials. That’s because over time I found it easier to deploy with a configuration file that was in yaml format.

Make sure you create an API token for slack by creating a Slack App, then using it’s Verification Token. Hopefully in the future I revisit this and make use of the Client ID, Client Secret, Signing Secret configuration.

So to provide that file we need to create the following in your zabbix configuration directory ex. /ext/zabbix/slack.yml .

2
slack_api_token: {{zabbix_slack_api_token}}
Cable

This makes it easier at least for me to deploy and separate configuration from the script itself.

Mail for mac html signature. Next steps include creating the Slack Media Type.

Zabbix Slack Channel

Zabbix slack app

Navigate to Administration > Media types

Select “Create media type”, and fill out the following:

2
4
6
8
Type:Script
Script parameters:
{ALERT.SUBJECT}
Enabled:Checked

Zabbix Slack Cable

Don’t forget to save!

Zabbix Cloud

Your first value is going to be “Channel” the rest fill in the message details.