How To Receive PRTG Notifications Via Telegram

 Originally published on May 04, 2017 by Stephan Linke
Last updated on March 16, 2023 • 13 minute read

Paessler PRTG monitoring software already features a lot of notification options: sending email, SMS, executing commands, calling URLs, and many more. With Telegram, there is another option: Bots! You can send messages to them and they will output them in a group with all your fellow administrator colleagues. 

While the bots in Telegram offer an amazing API that allows you to build your own chat-based PRTG app, we’ll only cover sending basic messages. Tinkering with the API requires some programming knowledge and will take some time. 

Be where thousands of Paessler PRTG users share their expertise! Join our LinkedIn group

Requirements

  • Telegram account
  • A group chat where you can invite the bot
  • Your PRTG server must have access to https://api.telegram.org/

Creating the Bot

First we need to create the bot with the help of “The Botfather”: 

  • Start a new chat with “Botfather” in Telegram
Chat with BotFather

Chat with BotFather

  • With /newbot, you can start the bot creation, Godfather will guide you through it .
Bot configuration

Bot configuration

  • You’ll receive an API key for your bot – we’ll need that for later
  • By default, your Bot can be invited to all groups requested. Also he will be able to read all messages sent to the channel. Use /setprivacy and /setjoingroups to configure this accordingly when everything is up and running
  • In the bot's profile, you can add it to the group you want PRTG to send notifications to.
The bot's profile

The bot's profile

The bot's profile

The bot's profile

  • Within the group chat, type /start to activate the bot. 
  • Now is the time to configure privacy and group joining as mentioned earlier, via /setprivacy and /setjoingroups.

 Well, that covers creating the bot. Quite some work so far, but we’re not done yet. 


Setting Up The Notification

This is where the API key from step three comes into play. Open up the following URL within your browser: 

https://api.telegram.org/bot<apikey>/getMe

The result should look something like this: 

{
   "ok": true,
   "result": {
      "id": 1234567890,
      "first_name": "PRTGNotiBot",
      "username": "PRTGNotificationBot"
   }
}

If you get any errors here, make sure that the URL and API key are correct. Now, open the same URL, but with getUpdates instead of getMe. You’ll receive an overview of the chats the bot is added to. It will look like the following: 

{
   "ok": true,
   "result": [{
      "update_id": 521075218,
      "message": {
         "message_id": 3,
         "from": {
            "id": 11512298,
            "first_name": "xxxxxxxxx",
            "last_name": "xxxxxxxxx",
            "username": "xxxxxxxxx"
         },
         "chat": {
            "id": -12345690,
            "title": "[Paessler] IT",
            "type": "group",
            "all_members_are_administrators": true
         },
         "date": 1493834122,
         "text": "/start",
         "entities": [{
            "type": "bot_command",
            "offset": 0,
            "length": 6
         }]
      }
   }]
}

We’ll need the chat ID (in our example it's "-12345690"), including the leading – sign. Now we’re ready to create the notifications in PRTG. Create a new HTTP notification and use the following parameters: 

URL:

https://api.telegram.org/bot<your-api-key>/sendMessage 

Post data: 

chat_id=-<your-chat-id>&text=
There's a *%status* sensor in your PRTG!
[%sensor](%linksensor)

*Last Message* %lastmessage 
*Down since* %since
*Device* %device
*Group* %group&parse_mode=Markdown

If you also want a corresponding up notification, create another one with the same URL and this post data: 

chat_id=-196449333&text=
Phew! Looks like [%sensor](%linksensor) is *%status* again!&parse_mode=Markdown

Of course, you can alter the text to your likings. Markdown options for Telegram messages can be found under https://core.telegram.org/bots/api#formatting-options.

The test notification should look like this:

Test notification

Test notification

 ⚠️ All that’s left to do is adding the notification to your Groups, Devices, or Sensors.


Actual notifications will look like this:

This is what the notifications look like

This is what the notifications look like

The author

 

Stephan is part of the Paessler technical support team. He's one of our most experienced and ambitious scripters, having created many tools and scripts for us and our customers.