31. 03. 2020 Giuseppe Di Garbo NetEye, Unified Monitoring

How to Configure Telegram Notifications on NetEye

In a previous post, Valentina showed us how to configure Slack Notifications… and here I will similarly show you how to configure Telegram notifications on NetEye.

Create a Telegram Bot

A very easy way to create a bot on Telegram is through … another bot 😉

BotFather is a Telegram bot dedicated to the creation of new bots. It’s helpful for the first steps and for general settings, such as the definition of the name, the username, the description and the commands to be set.

By typing to Telegram’s @BotFather you can start the activation procedure of our bot with the /start option:

Next we can type /newbot and specify the name of the bot we want to create:

Create the username and take note of the token provided by BotFather for accessing the API via HTTP.

Token example format: 10XXXXXX:AAXXXXXX-y2TDkdgy8Fr6XXXXXX

Create a Telegram Group

Now create a new group and add the previously created Telegram Bot along with the recipients for NetEye notifications:


After creating the group, write at least one message in the group channel (which must contain at least us and the bot created initially)

Get the chat_id from the Telegram Bot

To use the notification commands we need the chat_id, which is the unique group/channel id of the group where the message has been sent.

We can use the curl command in this way calling api.telegram.org:

curl https://api.telegram.org/bot<TELEGRAM_BOT_TOKEN>/getUpdates

Here’s an example:

[root@neteye4 ~]# curl -i -X GET https://api.telegram.org/bot10XXXXXX:AAXXXXXX-y2TDkdgy8Fr6XXXXXX/getUpdates
 HTTP/1.1 200 OK
 Server: nginx/1.16.1
 Date: Mon, 23 Mar 2020 14:47:45 GMT
 Content-Type: application/json
 Content-Length: 380
 Connection: keep-alive
 Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
 Access-Control-Allow-Origin: *
 Access-Control-Allow-Methods: GET, POST, OPTIONS
 Access-Control-Expose-Headers: Content-Length,Content-Type,Date,Server,Connection
 {"ok":true,"result":[{"update_id":414892163,
 "message":{"message_id":6,"from":{"id":8933484,"is_bot":false,"first_name":"my_first_name","last_name":"my_last_name","username":"my_username"},"chat":{"id":-488860198,"title":"NetEye Telegram","type":"group","all_members_are_administrators":true},"date":1584974858,"text":"/setprivacy","entities":[{"offset":0,"length":11,"type":"bot_command"}]}}]}

In the example above, the chat-id is -488860198.

Pay attention, the chat-id must start with a “–“!

Create the Notification Commands

To create the notification commands on NetEye you need to clone this git repository in NetEye plugin repository:

# cd /neteye/shared/monitoring/plugins/
# git clone https://github.com/sysadmama/icinga2-notification-telegram 

Testing a Notification

We can now send a test notification. In the example below you will find a full example, but remember to substitute the telegram_bot (-p), telegram_chat_id (-q) and telegram_bot_token (-r) options.

[root@neteye4 ~]# su -s /bin/bash icinga -c "'/neteye/shared/monitoring/plugins/host-by-telegram.sh' '-4' 'neteye.mydomain.com' '-6' '' '-b' 'root' '-c' 'TELEGRAM NETEYE NOTIFICATION' '-d' '2020-03-23 12:11:01 +0100' -i 'http://neteye.mydomain.com' '-l' 'neteye.mydomain.com' '-n' 'neteye.mydomain.com' '-o' 'PING CRITICAL - Packet loss = 100%' '-p' 'neteye_telegram_bot' '-q' '-488860198' '-r' ' 10XXXXXX:AAXXXXXX-y2TDkdgy8Fr6XXXXXX ' -s 'DOWN'"

And then import the telegram-host-notification and telegram-service-notification commands into Icinga Director, importing the basket you will find in our NetEye 4 repository.

For each command created, update the three custom properties related to telegram_bot, telegram_bot_token and telegram_chat_id:

Create the NetEye Notifications

You can now customize the notification definition to better satisfy your needs using, for example, a custom variable to filter the hosts for which you want to have notifications on Telegram.

Giuseppe Di Garbo

Giuseppe Di Garbo

Consultant at Würth Phoenix
Hi everybody. I’m Giuseppe and I was born in Milan in 1979. Since the early years of university, I was attracted by the Open Source world and operating system GNU\Linux. After graduation I had the opportunity to participate in a project of a startup for the realization of an Internet Service Provider. Before joining Würth Phoenix as SI consultant, I gained great experience as an IT consultant on projects related to business continuity and implementation of open source software compliant to ITIL processes of incident, change and service catalog management. My free time is completely dedicated to my wife and, as soon as possible, run away from Milan and his caotic time and trekking discover our beautiful mountain near Lecco for relax and lookup the (clean) sky.

Author

Giuseppe Di Garbo

Hi everybody. I’m Giuseppe and I was born in Milan in 1979. Since the early years of university, I was attracted by the Open Source world and operating system GNU\Linux. After graduation I had the opportunity to participate in a project of a startup for the realization of an Internet Service Provider. Before joining Würth Phoenix as SI consultant, I gained great experience as an IT consultant on projects related to business continuity and implementation of open source software compliant to ITIL processes of incident, change and service catalog management. My free time is completely dedicated to my wife and, as soon as possible, run away from Milan and his caotic time and trekking discover our beautiful mountain near Lecco for relax and lookup the (clean) sky.

One Reply to “How to Configure Telegram Notifications on NetEye”

  1. Patrick Zambelli says:

    Update related to steps for telegram configuration.

    You need to update and allow privacy settings to BOT member:
    Get your bots:
    /mybots

    Assign your bot:
    /setjoingroups
    @mybotname

    Set privacy permissions:
    Enable

    /setprivacy
    @mybotyname

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive