Zabbix 6.2
- Serve il bot id, che si è ottenuto UAN SOLA VOLTA quando si è creato il bot
- Serve il chat_id, che si ricava chattando con il bot @myidbot, e chidendolo:
/getid
- Importare il media template
- Settarlo come mostrato
- Avviare il bot dal proprio telegram con
/start
- Fare il test inserendo in To: il proprio chat ID
- Assegnare il chat_id al proprio utente zabbix
Zabbix 4
- 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