I'm looking for the poor man's monitoring solution. I have a Hyper-V 2008 R2 environment where power fluctuations at off-peak hours are pretty common. The battery keeps the box up for a fair amount of time. I'm working on a solution to have the battery issue shutdown commands to the box for a best solution but I'd like to get a simple monitoring solution in place to monitor the status of the virtual machines.
Essentially something like this:
- Power Goes Out.
- Power is eventually restored.
- Server automatically restarts (On Power Restore).
- Virtual Machines should restart (From off or saved based on settings in Hyper-V).
- Task Scheduler runs a task every hour or so and checks for Virtual Machines that are not started.
- If the machines are not started it sends a message, prefer SMTP to alert someone to check it.
I'm not exactly sure how best to accomplish the check of the VMs. Do I issue a CLI or PS script that has a return code the task scheduler can then make a decision on or use some other method?
I'm looking to use the built-in Windows tools as this seems like something that should be accomplishable. If not thats fine, alternates are great too. And yes, I want a free way to do this. Not looking to spend any cash here, or implement some giant tool like Nagios for this seemingly small problem.
If I'm crazy thats fine too!
I'd do the whole thing inside Powershell. I wrote a script a while back to do some poor man's load balancing. It called some CLI code to return the state of a VM and acted accordingly.
You'll do the same: Have the Powershell call a CLI statement (Using getstate) to get the state of your various guest VM's. If any of them are down, fire an SMTP email or use CLI to start the vm or whatever.
Launch the Powershell by scheduled task on whatever interval you choose. Ought to work like a charm.
It appears that in prior version of Windows Server (pre-2012) a PowerShell module was not included to manage Hyper-V. You could use some of the other modules such as Failover Clustering, etc. but you have to use WMI scripting to make changes to the hypervisor.
In 2012 this problem is as simple as this:
PS C:\> Get-VM –ComputerName Server1 | Where-Object {$_.State –eq 'Running'}
However, it appears that there is an open-source library that abstracts the WMI scripting and leaves everything in PowerShell. I'll take a look at this module tonight and see if I can get it to do what I want.
Thanks Bob for at least pointing me in the right direction.