December 22, 2024

Virtual Machine Heartbeat State – Band Aid

From time to time, I get one of these:

Target: VirtualMachine1
Old Status: Green
New Status: Red

Current value:
Virtual Machine Heartbeat State – (State = Red)

Alarm: Virtual Machine Heartbeat State
([Yellow State Is Equal To yellow; Red State Is Equal To red])

Description:
Alarm Virtual Machine Heartbeat State on VirtualMachine1 changed from Green to Red

Just one of those alarms from vCenter that tells me that a VM’s Heartbeat isn’t being heard.

It is kind of a pain to look into these after hours, and when you aren’t paying attention to the alerts… So I figured I’d put a band-aid on the problem, until I get a chance to look deeper into the problem.

So I wrote a .VBS that will stop and restart the VMTOOLS service through a WMI call, and saved it to C:SCRIPTS on the vCenter Server.

Here’s the .VBS (restarttools.vbs):

‘Get the Guest Name from {targetName}
TargetServer = Wscript.Arguments(0)

‘The Domain User used to connect to the target guest via WMI
Username = “DOMAINUsername”

‘Get the Password from the 2nd Script Argument
Password = Wscript.Arguments(1)

Set objSWbemLocator = CreateObject(“WBemScripting.SWbemLocator”)

‘Connect using the Username and Password
Set objWMIService = objSWbemLocator.ConnectServer & _
(TargetServer, “rootcimv2”, Username, Password)

‘Grab all of the services named vmtools
Set colServices = objWMIService.ExecQuery (“Select * ” & _
from Win32_Service Where Name = ‘vmtools'”)

‘Stop the vmtools service
For Each objService in colServices
errReturnCode = objService.StopService()
Next

Wscript.Sleep 20000

‘Start the vmtools service
For Each objService in colServices
errReturnCode = objService.StartService()
Next

I then created an alarm that runs the .VBS when the Heartbeat State changes:

Make sure the “Run A Script” option has the following syntax:

cscript /nologo c:scriptsrestarttools.vbs {targetName} Password

I also have an e-mail alert to notify me when this happens. Typically, when this occurs, I’ll get a a Green to Red or Yellow, followed by a Red or Yellow to Green about a minute later.

It doesn’t happen often, but when it does, the little script does the trick.

3 thoughts on “Virtual Machine Heartbeat State – Band Aid

  1. Hiya — I added your blog to the Virtual Black Hole blogroll. Good stuff! Maybe now you can do the same for us…?

  2. Jase, you helped me back in september with this same issue. I used your script and it worked. I have since pointed virtual center to a new database which in essence deleted all of my alarms. I tried running this script again but I keep getting an error message that states ” SWBemlocator: User credentials cannot be used for local connections. Do you have any ideas.

  3. Хороший блог, много интересной информации в нем причем качественной. Автор молодец.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.