Sends Zabbix notifications to Rocket.Chat, an Open Source Slack Alternative (Tested on Zabbix 2.4.5. For higher versions, change similar parameters.)
Variable | URL |
---|---|
Zabbix URL | zabbix.example.com |
Rocket.Chat URL | rocketchat.example.com |
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
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
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.
Click in add.
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
Define
Save changes.
In Configuration > Actions, select "event source: Triggers", and click in Create action.
{
"text": ":negative_squared_cross_mark: *{TRIGGER.NAME} ({ITEM.VALUE1})*",
"attachments": [
{
"color": "#FF0000",
"title": "[INCIDENT] {HOST.NAME} ({HOST.CONN})",
"title_link": "https://zabbix.example.com/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}",
"text": "Verified in {TIME}, at {EVENT.DATE}",
"image_url": "https://zabbix.example.com/chart3.php?&width=900&height=200&period=3600&name={HOST.NAME}: {TRIGGER.NAME}&legend=1&items[0][itemid]={ITEM.ID}&items[0][drawtype]=5&items[0][color]=ff0000"
}
]
}
Click in Recovery message
{
"text": ":white_check_mark: *{TRIGGER.NAME} ({ITEM.VALUE1})*",
"attachments": [
{
"color": "#00FF00",
"title": "[OK] {HOST.NAME} ({HOST.CONN})",
"title_link": "https://zabbix.example.com/tr_events.php?triggerid={TRIGGER.ID}&eventid={EVENT.ID}",
"text": "Verified in {TIME}, at {EVENT.DATE}",
"image_url": "https://zabbix.example.com/chart3.php?&width=900&height=200&period=3600&name={HOST.NAME}: {TRIGGER.NAME}&legend=1&items[0][itemid]={ITEM.ID}&items[0][drawtype]=5&items[0][color]=00ff00"
}
]
}
To understand more about Zabbix Macros, check the link: https://www.zabbix.com/documentation/3.4/manual/appendix/macros/supported_by_location
Click in Enabled, and Add.
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.
Operation details:
Click in Add to Operation details and Add in screen.
So when a trigger is triggered, this will be the message sent to Rocket.Chat:
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.
__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: