2

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!

Brent Pabst
  • 6,069
  • 2
  • 24
  • 36

2 Answers2

0

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.

Bob
  • 597
  • 2
  • 8
  • Do you have any links or supporting documentation to review? I'm not familiar with any of the PS Hyper-V modules. – Brent Pabst Aug 20 '12 at 02:31
  • you'll be launching vmware-cmd.exe (with arguments) from within Powershell itself. (No cmdlets, etc, just a DOS call.) I don't recall if I had to use Comspec, but I don't think I did. Google for how to call DOS out of Powershell, and Google for the syntax etc. for vmware-cmd.exe – Bob Aug 20 '12 at 02:33
  • 1
    why would I be calling a vmware CLI program? – Brent Pabst Aug 20 '12 at 12:04
  • Because the CLI framework has the command to tell you the running state of the guest vm's. You'll have Powershell call a CLI command that says, "What is the running state (getstate) of machine "xyz". The command will return a code to Powershell that you'll act on. – Bob Aug 20 '12 at 12:20
  • I was talking more along the lines of I'm using Hyper-V and not vmware. – Brent Pabst Aug 20 '12 at 12:32
  • Well that matters! :-) So either you write a powershell statement that validates to your satisfaction that a guest vm is "running" (you could simply ping the guest vm...) or you find a Hyper-V equivalent to VMWare's "getstate" command. – Bob Aug 20 '12 at 12:36
0

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.

Brent Pabst
  • 6,069
  • 2
  • 24
  • 36