How to receive Veeam errors over Telegram

Often when you have installed and configured a system you take a step back and look at the work you did. Everything runs well and looks great. But how do you know if something fails on your newly installed Veeam Backup & Replication server? In this article, I want to show you how to monitor your Veeam server via Telegram messages without logging into it. This will help you to make sure everything is working as expected.

Table of contents

Creating a Telegram Bot

First of all, open up Telegram and search for the Botfather.
Send it the command /newbot it will ask you to type a name for your new bot.
After that, you will receive a message with your bot token / API code, save this for later use.
The next step is to open the newly created bot by clicking on the link in the message. It should look like this “t.me/botname”.

Now to get the second information we need, open a browser and visit the following webpage, please change the <YourBOTToken> to your API Code.

https://api.telegram.org/bot<YourBOTToken>/getUpdates

Now look for the chat id, it is digits only. It should look like in the picture below.

Telegram API Code Chat ID

Now we have all the information needed. To test if we are able to communicate with the Telegram bot, use the simple PS script below to test. You need to fill in the XXXX in the two variables with the information from above.

$MyToken = "XXXX"
$chatID = XXXX
Invoke-RestMethod -Uri "https://api.telegram.org/bot$($MyToken)/sendMessage?chat_id=$($chatID)&text=$("My PC can talk")"

If it has worked you will see the message popping up in your Telegram.

Retrieving Veeam error codes

Creating the PowerShell script

First, we create a PowerShell Script reporting errors when something happens on our server. For this we use the script we created above. But with another Text šŸ˜‰

$MyToken = "XXX"
$chatID = XXX
    
 Invoke-RestMethod -Uri "https://api.telegram.org/bot$($MyToken)/sendMessage?chat_id=$($chatID)&text=$("An error occured on your Veeam server")"

Creating a scheduled task to fetch the errors

Now go to your Windows server where you have installed Veeam and open the task scheduler. To track Veeam events, do the following steps:

  • Create a new task
  • Create a new trigger
  • Chose as begin the task “On an Event”
  • Chose custom
  • Hit new event filter
  • Switch the tab to XML
  • Click the edit query manually button
  • Enter the following XML code
<QueryList>
  <Query Id="0" Path="Veeam Backup">
    <Select Path="Veeam Backup">*[System[(Level=1  or Level=2 or Level=3)]]</Select>
  </Query>
</QueryList>
Windows Server 2016 Task Sehduler, Set a Trigger for A Specific Event


Next, we go to the actions tab and refer to the PowerShell script created before. In Program/script type Powershell.exe and as argument the path to the script.

Windows Server 2016 Task Shedluer start a Powershell Program

If you finished all the steps you will receive the message “An error occurred on your Veeam server” every time an error occurs on your Veeam server. This basic setup gives you a good idea or a better start on how to do many cool customizations on your servers.

Short description for those close to a zen master level

  • Create a Telegram bot
  • Create the script sending you a Telegram message
$MyToken = "XXX"
$chatID = XXX
    
 Invoke-RestMethod -Uri "https://api.telegram.org/bot$($MyToken)/sendMessage?chat_id=$($chatID)&text=$("An error occurred on your Veeam server")"
 
  • Create a scheduled task listening to Veeam errors and running your warning script
<QueryList>
  <Query Id="0" Path="Veeam Backup">
    <Select Path="Veeam Backup">*[System[(Level=1  or Level=2 or Level=3)]]</Select>
  </Query>
</QueryList>

Don’t be shocked by application failures, focus on your zen garden.

Zen master Xiakit

One thought on “How to receive Veeam errors over Telegram

Add yours

Leave a Reply

Powered by WordPress.com.

Up ↑

%d bloggers like this: