I'm configuring a bot to send alerts from Zabbix, so I installed Python and the modules:
sudo apt install python python-pip python-setuptools
After that, I installed the bot API to use on Zabbix:
python -m pip install --user pyTelegramBotAPI
Created the script in /usr/lib/zabbix/alertscripts/ :
#!/usr/bin/env python
import telebot,sys
BOT_TOKEN='123TOKENAQUI321'
DESTINATION=sys.argv[1]
SUBJECT=sys.argv[2]
MESSAGE=sys.argv[3]
MESSAGE = MESSAGE.replace('/n','\n')
tb = telebot.TeleBot(BOT_TOKEN)
tb.send_message(DESTINATION,SUBJECT + '\n' + MESSAGE)
Changed permissions:
sudo chmod +x telegram
sudo chown -R zabbix telegram
And when testing the script on terminal or Zabbix the following error appears:
Traceback (most recent call last): File "/usr/lib/zabbix/alertscripts/telegram", line 2, in import telebot,sys ImportError: No module named 'telebot'
I tried to solve by installing the module:
python -m pip install --user telebot
Installing the module did not solve it, so I tried to use python3, and the script on the terminal worked, but in Zabbix still showing the same error. I ended up going back to python.
The telebot module does not appear with pip list
, only inside the python terminal using the command help ("modules")
.
What may be causing the problem and how to resolve it?