skip to Main Content

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").

Does anyone know that may be causing the problem?

2

Answers


  1. Chosen as BEST ANSWER

    I managed to solve it using python3, but this time I removed the other versions of python completely before installing again, the steps were as follows:

    sudo python -m pip uninstall pyTelegramBotAPI
    sudo apt remove python python-pip python-setuptools
    sudo apt install python3 python3-pip python3-setuptools python3-six
    sudo python3 -m pip install pyTelegramBotAPI six
    sudo pip install six
    

  2. For like these errors, reinstall the library or use (–upgrade) when you install it!

    like this:

    pip uninstall telebot
    pip install pyTelegramBotAPI
    pip install pytelegrambotapi --upgrade
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search