Sign in

Setup Telegram notifications on Zabbix docker stack

Hello friends, in this article we are going to setup Telegram notifications on Zabbix running from a Docker compose file.

Recently my notification container (that was using https://github.com/vysheng/tg as telegram client) broke, so I decided to build a very simple container (without third party software) to do the same function. This notifications container (https://hub.docker.com/repository/docker/pedropilla/telegram-sendmessage) uses socat to listen on desired port and curl to send the message via GET method.

We will need a bot to send the notifications, so create a bot with @BotFather and save the token.

First we want to create the notification script that Zabbix will use and setup Zabbix notifications.

root@secondary:~/zabbix# cat scripts/telegram-ncat.sh#!/bin/bash
echo $1 $2| nc telegram 6666

This script will send our notifications to telegram container that will be listening on port 6666. Now we can configure media type and action.

Here we create the media type.
And here we set the user media type with the UserID that we want to send notifications.
Finally we create the action that will send the notifications.

Now we must add the notifications container to compose file:

version: "3"
services:
# Application service layer
zabbix-server:
image: zabbix/zabbix-server-mysql:latest
volumes:
- "./scripts:/usr/lib/zabbix/alertscripts"
environment:
- ZBX_SERVER_NAME=Zabbix
- MYSQL_DATABASE=zabbix
- DB_SERVER_HOST=1.2.3.4
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
ports:
- "1.1.1.1:10051:10051"
restart: always
# Web service layer
zabbix-web:
image: zabbix/zabbix-web-nginx-mysql
environment:
- ZBX_SERVER_NAME=Zabbix
- MYSQL_DATABASE=zabbix
- DB_SERVER_HOST=1.2.3.4
- MYSQL_USER=zabbix
- MYSQL_PASSWORD=zabbix
- ZBX_SERVER_HOST=zabbix-server
ports:
- "1.1.1.1:80:80"
restart: always
# Telegram
telegram:
image: pedropilla/telegram-sendmessage:v0.1
environment:
- BOT_TOKEN=885937569:AAF480nKhsVgGOpZ4c-l6ogcfI79a-XYW8k
- LISTEN_PORT=6666
restart: always

Simple like that, less is more. Hope you all liked.

Network Administrator | IT Analyst | Monitoring Architect

Network Administrator | IT Analyst | Monitoring Architect