Backstory 🔗
A few months ago, my manager tasked me with setting up automated monitoring and alerting of replication for the virtual machines on our Microsoft Hyper-V Server 2012 R2 (core) hypervisor servers (a task that I was more than happy to accommodate considering I had been meaning to anyway and I love programming but, unfortunately, it's rarely a part of my job) and IM-ed me "http://luka.manojlovic.net/2015/03/05/simple-hyper-v-replica-warning-critical-state-notification/".
I appreciated the starting point but I despise alerting via email because it's a nightmare to manage.
Our Remote Monitoring and Management (RMM) system, MAX RemoteManagement, is integrated with our helpdesk / Professional Services Automation (PSA) system, Autotask. The main benefit of this is that if the RMM system detects an issue then in the PSA system it automatically creates a ticket containing the details, etc. Obviously, it made infinitely more sense to make use of this so I decided to look into it.
I found that MAX RemoteManagement does not natively support this task but it does support the usage of custom scripts. The relevant documentation states the following:
So, this suggested that I should simply be able to use a PowerShell script to check the VM replication health and return the appropriate exit codes.
Obviously, I'm not going to waste my time creating a PowerShell script to accomplish a task if one already exists so I browsed the web looking for one that I could modify to our needs but I didn't find much and what I did find either wasn't suitable or I wasn't satisfied with. (Hence, this post).
So, I created my own.
Quickly, I got a crude-but-functional system working but over the next few months I noticed pitfalls and issues so I regularly refined and adapted it.
A few months later, I give you "Check Hyper-V VM replication health v6.ps1".
Code 🔗
Screenshots 🔗
The whole system when issues exist:
The whole system when no issues exist:
I hope this is helpful to someone. :)