Simple Hyper-V replica warning / critical state notification…

I have been searching for a simple solution to get the notification when something goes wrong with Hyper-V replica replication… The problem is that things can go realy bad if you have Hyper-V replica in critical state for long period of time (AVHD differential disk grows and can make a big mess on source server…)

So here is the PS script that checks replica health and sends mail if one or more of VMs have Warning or Critical replication state.

You can modify sending parameters by looking at examples @ http://petermorrissey.blogspot.com/2013/01/sending-smtp-emails-with-powershell.html

Just save the script as (for example) c:\hvreplicamon\hvreplicamon.ps1

Create a Task Scheduler taks (screenshots below)

if ((Get-VMReplication | select-string -inputobject {$_.Health} -pattern “Warning”) -like “Warning”)
{
$SMTPServer = “smtp.gmail.com”
$SMTPPort = “587”
$Username = “username@gmail.com
$Password = “password”
$to = “my@emailwhereiwanttoreceivealert.com
$subject = “Replica WARNING error on SERVERNAME”
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.to.add($to)
$message.from = $username
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)
}
elseif ((Get-VMReplication | select-string -inputobject {$_.Health} -pattern “Critical”) -like “Critical”)
{
$SMTPServer = “smtp.gmail.com”
$SMTPPort = “587”
$Username = “username@gmail.com
$Password = “password”
$to = “my@emailwhereiwanttoreceivealert.com
$subject = “Replica CRITICAL error on SERVERNAME”
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.to.add($to)
$message.from = $username
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.send($message)
}

Task Scheduler task parameters

task1

task2

task3

Tags: , , , , ,

One Response to “Simple Hyper-V replica warning / critical state notification…”

  1. Rich says:

    I was also looking for a Hyper-V replication monitoring solution but I really wanted something that would not only look at the status but also send an alert even if the host completely failed or that data center went offline.

    I ended up programming our own solution. Uses a simple scheduled task to run a powershell script. This measures the replication stats and posts them to a web API hosted at Azure every 5 minutes.

    If more than a certain threshold of updates are missed, I get an alert that the host may be down. And you can configure the various rules and conditions you want to check for based on your own setup.

    Its not perfect but its a decent solution that is working for us. Feel free to check it out and fork/comment as you wish: https://github.com/rktect/HyperVStatusMonitor

    Cheers!

Leave a Reply

You must be logged in to post a comment.