VMware Cloud Community
petermie
Enthusiast
Enthusiast
Jump to solution

Raise alarm on VM

I have a batch file i'm running via Invoke-VMScript that occasionally fails. I can capture the error code from the batch file on the VM, but i've been wondering if there's a way to raise any kind of alarm in vCenter so I can see that it failed? At the moment, I have my Invoke-VMScript script just print "ERROR" to the screen, but the ultimate goal is to put this into an automated process where I won't be seeing the output directly so I need some kind of indicator that it didn't work - ideally on the VM on the other end of the Invoke-VMScript call. Don't really care which alarm it is either, just need an indicator.

0 Kudos
1 Solution

Accepted Solutions
Craig_Baltzer
Expert
Expert
Jump to solution

There doesn't seem to be a direct method of generating an alarm, it appears they have to be generated off either an event or a condition threshold/state. You can write a user defined event to keep track of the failure which may get you part way to what you're looking for...

$VM = "VMName"

$EM = Get-View EventManager

$VMMoRef =  (Get-View -ViewType VirtualMachine -Filter @{Name = "$VM"}).MoRef

$EM.LogUserEvent($VMMoRef, "Here is a message")

When you look at the Events for the "VMName" VM you'll see

pastedImage_0.png

View solution in original post

0 Kudos
2 Replies
Craig_Baltzer
Expert
Expert
Jump to solution

There doesn't seem to be a direct method of generating an alarm, it appears they have to be generated off either an event or a condition threshold/state. You can write a user defined event to keep track of the failure which may get you part way to what you're looking for...

$VM = "VMName"

$EM = Get-View EventManager

$VMMoRef =  (Get-View -ViewType VirtualMachine -Filter @{Name = "$VM"}).MoRef

$EM.LogUserEvent($VMMoRef, "Here is a message")

When you look at the Events for the "VMName" VM you'll see

pastedImage_0.png

0 Kudos
petermie
Enthusiast
Enthusiast
Jump to solution

That did the trick, thanks Smiley Happy. I created an alarm on my VM with the event set to "vim.event.GeneralUserEvent" and it triggers the alarm when any user event is logged, which is exactly what I was looking for. Now I just have to play with the conditions box to see if I can find the right argument to type in to filter by a specific message but this definitely works for now.

0 Kudos