Skip to main content

Zabbix alert Notification with Telegram

Zabbix Notifications with graphs in Telegram.

Features

  •  Graphs based on latest data are sent directly to your messenger
  •  You can send messages both in private and group chats
  •  Channels support
  •  Saves chatid as a temporary file
  •  Simple markdown and HTML are supported
  •  Emoji in messages

First of all : Nedd to install python (>3) on Cent os 

# yum -y install python-pip
# yum install -y https://centos7.iuscommunity.org/ius-release.rpm
#  yum install -y python34u python34u-libs python34u-devel python34u-pi
# yum -y install python-pip

You need to install the requests module for python, this is required for operation!

# pip install requests

  • Put zbxtg.py in your AlertScriptsPath directory, the path is set inside your zabbix_server.conf (once confirm by zabbix server conf file )
Link to download ZBXTG.PY file 

https://drive.google.com/open?id=0BxB8j19aCMZ8dFl1aHVuLVJyRjQ

# cp zbxtg.py /usr/local/share/zabbix/alertscripts/

  • Create zbxtg_settings.py with your settings and save them in the same directory as the script, see example for layout
Link to download ZBXTG_SETTING.PY File 

https://drive.google.com/open?id=0BxB8j19aCMZ8QzJYbVY3MlZ3dWs

# cp zbxtg_settings.py /usr/local/share/zabbix/alertscripts/

  • Create a bot in Telegram and get API key
Search for Telegram botfather in telegram

/start
/newbot

Then it will give you a bot api store that .

  • Create readonly user in Zabbix (for getting graphs images from zabbix)
edit zbxtg_settings.py  file with your server info and bot api  .

  • Add new media for Telegram in Zabbix web interface with these settings:
  • Add another one if you want to send messages to the group
Last value: {ITEM.LASTVALUE1} ({TIME})
zbxtg;graphs
zbxtg;graphs_period=10800
zbxtg;itemid:{ITEM.ID1}
zbxtg;title:{HOST.HOST} - {TRIGGER.NAME}
  • Add the appropriate Media Type to your user
  • The username is CASE-SENSITIVE
  • Group chats don't have URLs, so you need to put group's name in media type
  • Messages for channels should be sent as for private chats
  • Private:
  • Group:

Annotations

zbxtg;graphs -- enables attached graphs
zbxtg;graphs_period=10800 -- set graphs period (default - 3600 seconds)
zbxtg;graphs_width=700 -- set graphs width (default - 900px)
zbxtg;graphs_height=300 -- set graphs height (default - 300px)
zbxtg;itemid:{ITEM.ID1} -- define itemid (from trigger) for attach
zbxtg;title:{HOST.HOST} - {TRIGGER.NAME} -- graph title
zbxtg;debug -- enables debug mode, some logs and images will be saved in the tmp dir (temporary doesn't affect python version)
zbxtg;channel -- enables sending to channels
You can use markdown or html formatting in your action: https://core.telegram.org/bots/api#markdown-style + https://core.telegram.org/bots/api#html-style.

Debug

  • You can use the following command to send a message from your command line: 
    ./zbxtg.py "<username>" "<message_subject>" "<message_body>" --debug
  • For <username> substitute your Telegram username, NOT that of your bot (case-sensitive)
  • For <message_subject> and <message_body> just substitute something like "test" "test" (for Telegram it's doesn't matter between subject and body
  • You can omit the ", these are optional



Example Message From server to telegram:

/usr/local/share/zabbix/alertscripts/zbxtg.py "telegram_username" "hello" "how are you ?"


Comments

  1. I really impressed after read this because of some quality work and informative thoughts . I just wanna say thanks for the writer and wish you all the best for coming!. telegramdownload10.com

    ReplyDelete

Post a Comment

Popular posts from this blog

How to remove zabbix-agent from Ubuntu 16.04 (Xenial Xerus)

Uninstall zabbix-agent To remove just zabbix-agent package itself from Ubuntu 16.04 (Xenial Xerus) execute on terminal: sudo apt-get remove zabbix-agent Uninstall zabbix-agent and it's dependent packages To remove the zabbix-agent package and any other dependant package which are no longer needed from Ubuntu Xenial. sudo apt-get remove --auto-remove zabbix-agent Purging zabbix-agent If you also want to delete configuration and/or data files of zabbix-agent from Ubuntu Xenial then this will work: sudo apt-get purge zabbix-agent To delete configuration and/or data files of zabbix-agent and it's dependencies from Ubuntu Xenial then execute: sudo apt-get purge --auto-remove zabbix-agent

Install Zabbix Agent on Suse Linux and Configure

Install taken from Suse –  http://software.opensuse.org/download/package?project=server:monitoring&package=zabbix-agent For SLE 12 SP1 run the following as root : zypper addrepo http://download.opensuse.org/repositories/server:monitoring/SLE_12_SP1/server:monitoring.repo zypper refresh zypper install zabbix-agent For SLE 12 run the following as root : zypper addrepo http://download.opensuse.org/repositories/server:monitoring/SLE_12/server:monitoring.repo zypper refresh zypper install zabbix-agent For SLE 11 SP4 run the following as root : zypper addrepo http://download.opensuse.org/repositories/server:monitoring/SLE_11_SP4/server:monitoring.repo zypper refresh zypper install zabbix-agent For SLE 11 SP3 run the following as root : zypper addrepo http://download.opensuse.org/repositories/server:monitoring/SLE_11_SP3/server:monitoring.repo zypper refresh zypper install zabbix-agent To configure the agent – Instructions t...