- Creare uno bot telegram e annotare la api key
- Creare il gruppo Readonly selezionando tutti i gruppi e dando accesso readonly
- Creare uno user in zabbix come read-only
- Creare un media type come
Name: Telegram
Type: script
Script name: zbxtg.py
Script parameters:
{ALERT.SENDTO}
{ALERT.SUBJECT}
{ALERT.MESSAGE}
- Aggiungere il media type al proprio utente (username Case Sensitive):
Type: Telegram
Send to: @UserName
- Installare python-requests:
apt-get install python-requests
cd /tmp
git clone https://github.com/ableev/Zabbix-in-Telegram.git
cd Zabbix-in-Telegram/
cp zbxtg.py $(cat /etc/zabbix/zabbix_server.conf | grep ^AlertScript | cut -f 2 --delimiter='=')
cp zbxtg_settings.example.py $(cat /etc/zabbix/zabbix_server.conf | grep ^AlertScript | cut -f 2 --delimiter='=')/zbxtg_settings.py
vi $(cat /etc/zabbix/zabbix_server.conf | grep ^AlertScript | cut -f 2 --delimiter='=')/zbxtg_settings.py
tg_key = "1234567890:AAGVIlIe5-YFWhLYTByI8gOCCxZfeEDpr20" # telegram bot api key without leading "bot-"
zbx_server = "http://127.0.0.1/zabbix/" # zabbix server full url or external url with fqdn
zbx_api_user = "zabbix-readonly-username"
zbx_api_pass = "password"
- Inviare al bot un messaggio qualsiasi, poi testare:
cd /usr/lib/zabbix/alertscripts
./zbxtg.py "MYTelegramUserNAME" "message_subject" "message_body" --debug