PRTG Hyper-V Azure Replication Monitoring

4 Jan

Since setting up Hyper-V Azure replication, the next step was to add this to the PRTG dashboard.

To do this create a PowerShell file (Hyper-V Replication.ps1 or similar) and store it in:

C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE

Enter the following code (remembering to change the Host server name)

$Session = New-PSSession -computername "HostName"

Import-PSSession $Session -Module Hyper-V -allowclobber | out-null

$VMReplication = Get-VMReplication | select name,health 

$VMReplication = Get-VMReplication | select name,health,state

$Errors = 0
$Warning = 0
$Critical = 0
foreach ($Name in $VMReplication) {
    if ($Name.Health -like "Normal" -and $Name.State -like "Replicating") {
    }
    elseif ($Name.Health -like "Warning") {
    $Warning = $Warning + 1
    }
    elseif ($Name.Health -like "Critical") {
    $Critical = $Critical + 1
    }

$Errors = $Errors + 1
}

if ($Critical -ge 1) {
Write-Host 2, ":ERROR", "Critical error with replication" 
}
elseif ($Warning -ge 1) {
Write-Host 1, ":WARNING", "Replication is behind schedule" 
}
else{
Write-Host 0, ":OK", "Replication is working fine"
}


Exit 0

Next, add a PRTG Sensor of the type EXE/Script

Select your newly created PowerShell file and it’s now setup to alert you of any replication issues.

hyper-v prtg replication

PS, it’s worth noting that you need to allow the PRTG credentials that are bing used must be a member of the Hyper-V administrators group on the Hyper-V host:

References: