1
Hello!
I am configuring the bot to send Zabbix alerts, I have installed Python and the necessary modules:
sudo apt install python python-pip python-setuptools
Then I installed the bot API to use in Zabbix:
python -m pip install --user pyTelegramBotAPI
I created the script in /usr/lib/Zabbix/alertscripts/ :
#!/usr/bin/env python
import telebot,sys
BOT_TOKEN='TOKENAQUI'
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)
I changed the execution permissions:
sudo chmod +x telegram
sudo chown -R zabbix telegram
And when testing the script in the terminal or in Zabbix the following error appears:
Traceback (Most recent call last): File "/usr/lib/Zabbix/alertscripts/Telegram", line 2, in import telebot,sys Import: No module named 'telebot'
I tried to solve by installing the module:
python -m pip install --user telebot
Installing the module did not solve, then I tried to use python3, so the terminal worked, but in Zabbix keeps showing the same error, I ended up going back to python.
Does anyone know who might be causing the problem?
Which version returned with
/usr/bin/env python --version
and with onlypython --version
?– Woss
In both is Python 2.7.12
– Lucas SF
Any specific reason you used the
--user
? Know if the directory is part of your environment variablePATH
? You can confirm by checking the path withpython -c 'import site; print(site.USER_BASE)'
andecho $PATH
.– Woss
The
--user
I saw in one of the forum I visited while trying to solve, where it said to try using it. The directories of the variablePATH
sane/home/appliance/.local
and/home/appliance/bin:/home/appliance/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
.– Lucas SF
I had tried before to install without the option
--user
? Also gave the error?– Woss
Yes, I was wrong too, but I can try again
– Lucas SF
Hasn’t changed, keeps making the same mistake.
– Lucas SF
The module
telebot
appears withpip list
? Or when, inside the python terminal, you give the commandhelp("modules")
?– Murilo Sitonio
It only appears inside the Python terminal
– Lucas SF