By Stephan Linke • May 5, 2017
How to receive PRTG notifications via Telegram
PRTG 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.
- 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
- With /newbot, you can start the bot creation, Godfather will guide you through it .
- 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.
- 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:
The result should look something like this:
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:
"title": "[Paessler] IT",
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:
There's a *%status* sensor in your PRTG!
*Last Message* %lastmessage
*Down since* %since
If you also want a corresponding up notification, create another one with the same URL and this post data:
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. All that’s left to do is adding it to your Groups, Devices, or Sensors. Actual notifications will look like.
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.