Use PRTG to monitor Azure Backup status

Recently I received the question if it is possible to monitor Azure Backup with PRTG. Now this might seem to be a bit weird, as we could use Azure monitoring. But in this case, it was a service provider that needed a single solution for all their services, including custom dashboards and monitoring.

So, challenge accepted, lets get this done! In this case the customer has a Azure Recovery Service Vault with 2 virtual machines, with a backup schedule of only once every 24 hours with a retention of 30 days.

Our goal will be to have 3 sensors in PRTG with the completed jobs, failed jobs and running jobs. If you follow the next steps you should be able to set this up your self as well.

Step 1: Create and application registration in the Azure Portal, so go to Azure Active Directory, and fill in all the required fields. Note, the Redirect URL may be completely random, but it is nice to set it to your PRTG monitoring URL. In this example its just a random address.

Step 2: Go to your created application, and go to overview. Copy the Application ID and Tenant ID to a notepad or something, we will need them later.

Step 3: Go to certificates & secrets, and create a new client secret. Make sure that you save the secret, you will not be able to read it again! You can only create a new key.

Step 4: Now go to the service recovery vault where you want to read the backups from, and assign the PRTG application the Backup Reader role.

Step 5: On your PRTG (Probe) server install the AzureRM Module using the following command:

install-module azurerm

Step 6: On your PRTG (Probe) server, we will need to create a little powershell script, and save it on the following location: C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\AzureBackupStatus.ps1

Code of the script AzureBackupStatus.ps1

Script from 2azure.nl (PRTG Monitoring of Azure Services Recovery Vault)
 param(
        $password,
        $applicationid,
        $TenantId
 )
 function getbackupstatus {
 $principalPassword = ConvertTo-SecureString $password -AsPlainText -Force
 $psCred = New-Object System.Management.Automation.PSCredential($applicationid, $principalPassword)
 $null = connect-AzureRmAccount -Credential $psCred -ServicePrincipal -TenantId $TenantId
 $Subscriptions = Get-AzureRmsubscription
 if ($SubscriptionName)
 {
     $Subscriptions = $Subscriptions | where { $_.SubscriptionName -EQ $SubscriptionName }
 }
 elseif ($SubscriptionId)
 {
     $Subscriptions = $Subscriptions | where { $_.SubscriptionId -EQ $SubscriptionId }
 }
 $jobsAllArray = @()
 $i=0
 foreach ( $Subscription in $Subscriptions ) 
 {
     $SubscriptionId = $Subscription.SubscriptionId
 $i++ $rcvaults=Get-AzureRmRecoveryServicesVault foreach ($rcvault in $rcvaults) {     get-azurermrecoveryservicesvault -name $rcvault.Name | set-azurermrecoveryservicesvaultcontext ;    $JobStatus=Get-AzureRmRecoveryServicesBackupJob -From (Get-Date).AddDays(-1).ToUniversalTime() |Select Status;              }  $global:CompletedJobs= $JobStatus| Where({$_.Status -eq 'Completed'}) $global:InprogressJobs= $JobStatus| Where({$_.Status -eq 'InProgress'}) $global:FailedJobs= $JobStatus| Where({$_.Status -eq 'Failed'}) } 
 }
 getbackupstatus 
 If(($Failedjobs.status.count -eq 0) -and ($CompletedJobs.status.count -gt 0))  {
 $result = "<prtg>         <result>         <channel>Completed jobs</channel>         <value>$($CompletedJobs.status.count)</value>         </result>         <result>         <channel>Failed jobs</channel>         <value>$($FailedJobs.status.count)</value>         </result>         <result>         <channel>Running jobs</channel>         <value>$($InprogressJobs.status.count)</value>         </result>         <text>Backup succesvol</text>         </prtg>"
 }
 else{
     $result = "     1
     Backup failed, failed jobs: $($failedjobs.status.count)     "
 }
 Write-Host $result

Step 7: The final step, go into your PRTG environment, and create a new sensor on the device where you’ve added the powershell script. Search for the EXE sensor, and create the EXE/Script Advanced Sensor.

Next step is to configure the sensor properly with the following settings:

  • Sensor Name: Set it to whatever you like 🙂
  • EXE/Script: AzureBackupStatus.ps1
  • Parameters: -password ” -applicationid ” -TenantId ”

Make sure that the entries from the previous steps are added between the ”. When finished click create.

The last step is to change the interval in PRTG. Change it to something smart for your environment. I would recommend max once every hour. The result will look like this:

3 completed jobs, 0 failed jobs, 0 running jobs in this screenshot

If you want to improve, or if you have any suggestions, please let me know by using the comment box below.

2 Replies to “Use PRTG to monitor Azure Backup status”

Leave a Reply

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