rauhmaru / rocketchat-zabbix

Sends Zabbix notifications to Rocket.Chat, an Open Source Slack Alternative
14 stars 5 forks source link
integrations json python rocketchat zabbix zabbix-templates

rocketchat-zabbix

Sends Zabbix notifications to Rocket.Chat, an Open Source Slack Alternative (Tested on Zabbix 2.4.5. For higher versions, change similar parameters.)

Definitions in examples

Variable URL
Zabbix URL zabbix.example.com
Rocket.Chat URL rocketchat.example.com

Rocket.chat

In Rocket.Chat, click in Options > Administration > Integrations > New integration > Incoming WebHook

Save changes and get Webhook URL. Example: http://rocketchat.example.com/hooks/7mbi7xr3akMfKZdna/2wPNTHja7xaREdZY39744eehskYTkw7yx6mwrBpD5Wjphfqg

Zabbix

Create a script

In directory of AlertScript (Use grep ^AlertScript /etc/zabbix/zabbix_server.conf), create a file rocketchat.py.

#!/usr/bin/python

import sys
import requests

url     = sys.argv[1]
body    = sys.argv[2]
body = body.encode(encoding='utf-8')

r = requests.post(url, body)

Add executable permissions to the script

chmod +x rocketchat.py

Create a media

In Administration > Media types > Create media type:

Script parameters:

{ALERT.SENDTO} will be changed by webhook url and {ALERT.MESSAGE} will be changed by alert message, formated in JSON.

zbx_alert

Click in add.

Create a user

IMPORTANT

I recommend that you create a group with read-only permission (zabbix-ro) of the items you want to receive alerts, and put the user rocketchat on it.

in Administration > Users > Create user

User Tab

Define

Media Tab:

Save changes.

Create Actions

In Configuration > Actions, select "event source: Triggers", and click in Create action.

Action Tab

Click in Recovery message

Click in Enabled, and Add.

Conditions tab

Label Name
A Maintenance status not in maintenance
B Trigger value = PROBLEM
C Trigger severity = Disaster
D Trigger severity = High

In this configuration, the triggers will only be sent if an event occurs in high severity or disaster. Minor events will not be reported. To add, just include them.

Operations tab

Operation details:

Click in Add to Operation details and Add in screen.

Image of Operations tab

So when a trigger is triggered, this will be the message sent to Rocket.Chat:

Rocket.Chat Trigger

Note: To view the graphs, you need to be logged in to Zabbix, or you can too (Thanks to @vjunior1981 in #3):

With this, you graphics are public. Use only if necessary.

Plus: Zabbix Template

__you need to set the user macro ROOT_URL on the host where the template will be applied.__

{$ROOT_URL}: Your Rocket.Chat URL (ex.: https://rocket.example.com )

This template monitors:

Itens

Triggers

Graphics