VMware Cloud Community
Maschimidt
Contributor
Contributor

Script to monitor and restart VM locked

Hello,
I wonder if it is possible to run a script to check the status of a particular virtual machine, and even if the system is locked reset it


Thanks...

0 Kudos
7 Replies
LucD
Leadership
Leadership

You mean the overall status ?

Get-VM -Name MyVM  | Select @{N="OverallStatus";E={$_.ExtensionData.OverallStatus}}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Maschimidt
Contributor
Contributor

Hi Luc

I will explain, Monday realized that a virtual machine not responding "ping" and the VMware Tools status was Not Running, I opened the console and saw that the machine was locked, so I was thinking of a script to check the machine status , and the same answer as the offline script reset the machine automatically


Thanks..

0 Kudos
LucD
Leadership
Leadership

You mean locked in the sense that you couldn't interact with the guest OS from the console ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Maschimidt
Contributor
Contributor

Exactly, for some reason the machine was locked, did not answer, so I had to make a guest restart manually

0 Kudos
LucD
Leadership
Leadership

That situation is not always easy to detect I'm afraid.

You can test with a ping to the guest OS and check if the VMware Tools are not running.

Something like this

$vm = Get-VM -Name MyVM
if(!(Test-Connection -ComputerName $vm.Guest.HostName -Quiet) -and
   
$vm.Guest.State -eq "NotRunning"){
   
Stop-VM -VM $vm -Confirm:$false -Kill
   
Start-VM -VM $vm
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Maschimidt
Contributor
Contributor

I'll do some tests and give feedback

thank you

0 Kudos
MKguy
Virtuoso
Virtuoso

Apart from scripting something on your own maybe you should look into the VM monitoring feature of HA instead, which is designed to do exactly what you want: Resetting a crashed/unresponsive guest OS.

http://pubs.vmware.com/vsphere-50/index.jsp?topic=%2Fcom.vmware.vsphere.avail.doc_50%2FGUID-62B80D7A...

http://www.yellow-bricks.com/2011/07/20/testing-vm-monitoring-on-vsphere-5-0/

-- http://alpacapowered.wordpress.com
0 Kudos