- Zabbix server
- Nginx
- Python 2.7
- SSL certificate
Installation steps testing on Ubuntu 14.04 and Debian 8
apt-get install python-flask python-pip nginx uwsgi uwsgi-plugin-python
upstream telegram4zabbix {
server 192.168.78.4:9090;
}
server {
listen 80;
listen 443 ssl;
server_name telegram.geri4.ru;
charset utf-8;
if ( $scheme = "http" ) {
rewrite ^/(.*)$ https://$host/$1 permanent;
}
access_log /var/log/nginx/$host.access.log;
keepalive_timeout 70;
#HTTPS
ssl_certificate /etc/letsencrypt/live/geri4.ru/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/geri4.ru/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets on;
ssl_session_ticket_key current.key;
ssl_session_ticket_key prev.key;
ssl_session_ticket_key prevprev.key;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5';
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/geri4.ru/fullchain.pem;
resolver 8.8.8.8 8.8.4.4;
location /.well-known/acme-challenge {
root /var/www/letsencrypt;
}
location / {
proxy_pass http://telegram4zabbix;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
[uwsgi]
http-socket = :9090
pythonpath = /opt/telegram4zabbix/
module = telegramhook:app
plugins = python27
cd /opt
git clone https://github.com/Geri4/telegram4zabbix.git
chown -R www-data: /opt/telegram4zabbix
chmod ug+rwx -R telegram4zabbix
pip install pickledb simplejson pyzabbix python-telegram-bot
touch /var/log/telegram.log
chown zabbix: /var/log/telegram.log
TelegramBotToken='164444419:BBERDQsjJBG_lx8qPQsAFLDCMIc1XxhINlw'
ZabbixServerUrl='https://zabbix.example.com'
ZabbixUsername='gerasimov'
ZabbixPassword='qwerty123'
DBFile='/opt/telegram4zabbix/telegram.db'
WebHookUrl='https://telegram.example.org/hook'
ChatPassword='verysecret'
LogFile='/var/log/telegram.log'
service uwsgi restart
service nginx reload
1)Create link telegram-send script on zabbix default alert folder: ln -s /opt/telegram4zabbix/telegram-send.py /usr/lib/zabbix/alertscripts/telegram-send.py
2)Go to Administration->Media types->Create media type
3)Set following:
Name='Telegram'
Type='Script'
Script name='telegram-send.py'
Script parameters:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
- Add new media to zabbix user from which you need receive alerts, in 'Send to' field write any address.
- Create Action in zabbix, open Configuration->Actions->Create action, set following: Action tab:
Name: Telegram
Default subject: {TRIGGER.STATUS}: {TRIGGER.NAME}
Default message:
{TRIGGER.STATUS}: {TRIGGER.NAME}
Host: {HOSTNAME}
Trigger severity: {TRIGGER.SEVERITY}
Original event ID: {EVENT.ID}
Recovery subject: {TRIGGER.STATUS}: {TRIGGER.NAME}
Recovery message:
{TRIGGER.STATUS}: {TRIGGER.NAME}
Host: {HOSTNAME}
Trigger severity: {TRIGGER.SEVERITY}
Original event ID: {EVENT.ID}
Conditions tab:
Type of calculation: And/Or
Conditions:
Maintenance status not in maintenance
Trigger value = PROBLEM
Operations tab: Add step that send telegram message to specified zabbix users or groups.