Task Scheduler and Virtual Machine Monitoring

hyper-vmonitoringtask-schedulerwindows-server-2008-r2

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:

  1. Power Goes Out.
  2. Power is eventually restored.
  3. Server automatically restarts (On Power Restore).
  4. Virtual Machines should restart (From off or saved based on settings in Hyper-V).
  5. Task Scheduler runs a task every hour or so and checks for Virtual Machines that are not started.
  6. 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!

Best Answer

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.

Related Topic