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.
First we need to create the bot with the help of “The Botfather”:
Chat with BotFather
Bot configuration
The bot's profile
The bot's profile
Well, that covers creating the bot. Quite some work so far, but we’re not done yet.
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
⚠️ 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
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.