VMware Cloud Community
hharold
Enthusiast
Enthusiast
Jump to solution

PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

Hello All,

I have done some serious googling, and am about to accept that it is not possible through PowerCLI.

But I wanted to make a last effort by asking you guys.

For ESXi host maintenance, I want to use a PowerCLI script which does this:

  1. - disable alarm actions on Cluster
  2. - disable alarm actions on Hosts

  3. - perform maintenance (can be anything, but will include host reboots)

  4. - enable alarm actions on Hosts
  5. - enable alarm actions on Cluster

Because we have 300+ ESXi hosst, you can imagine I want to do this scripted.

Is there any way to disable/enable alarm actions through PowerCLI ?

Thanks and kind regards,

Harold

34 Replies
LucD
Leadership
Leadership
Jump to solution

Since then the cmdlets Get-AlarmDefinition and Set-AlarmDefinition were introduced.
You can easily enable/disable an alarm with those cmdlets.


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

Reply
0 Kudos
winsolo
Enthusiast
Enthusiast
Jump to solution

Thanks  

Reply
0 Kudos
nikhilgoel80
Contributor
Contributor
Jump to solution

It is not working now in the new version PowerCli. I'm getting below error.

 

Exception calling "EnableAlarmActions" with "2" argument(s): "The object 'vim.HostSystem:host-266712' has already been deleted or has not been completely created"
At line:1 char:1
+ $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$true)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

Tags (1)
Reply
0 Kudos
rm_bk
Enthusiast
Enthusiast
Jump to solution

Same error here: "Exception calling "EnableAlarmActions" with "2" argument(s): "The object 'vim.HostSystem:host-102792' has already been deleted or has not been completely created"

For an hour I've been trying to find a working method to disable alarm actions for all hosts in a cluster via PowerCLI.  I'm about to give up and just tell my colleagues to ignore the alarms.  Nothing works!

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you stop/start your PowerShell session in between tries?


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

Reply
0 Kudos
rm_bk
Enthusiast
Enthusiast
Jump to solution

It works for a colleague.  I think my PowerShell is broken.

167 ms | C:\Users\e12> Set-PSDebug -Trace 2
9 ms | C:\Users\e12> $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)
DEBUG: 1+ >>>> $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)
DEBUG: ! CALL function '<ScriptBlock>'
DEBUG: 19+ if ( & >>>> { Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
DEBUG: ! CALL function '<ScriptBlock>'
DEBUG: 19+ if ( & { >>>> Set-StrictMode -Version 1; $_.PSMessageDetails } ) {
DEBUG: 19+ if ( & { Set-StrictMode -Version 1; >>>> $_.PSMessageDetails } ) {
DEBUG: 1+ & >>>> { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
DEBUG: ! CALL function '<ScriptBlock>'
DEBUG: 1+ & { >>>> Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { Set-StrictMode -Version 1; >>>> $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails >>>> }
DEBUG: 19+ if ( & { Set-StrictMode -Version 1; $_.PSMessageDetails >>>> } ) {
DEBUG: 26+ $errorCategoryMsg = & >>>> { Set-StrictMode -Version 1; $_.ErrorCategory_Message }
DEBUG: ! CALL function '<ScriptBlock>'
DEBUG: 26+ $errorCategoryMsg = & { >>>> Set-StrictMode -Version 1; $_.ErrorCategory_Message }
DEBUG: 26+ $errorCategoryMsg = & { Set-StrictMode -Version 1; >>>> $_.ErrorCategory_Message }
DEBUG: 26+ $errorCategoryMsg = & { Set-StrictMode -Version 1; $_.ErrorCategory_Message >>>> }
DEBUG: 42+ $originInfo = & >>>> { Set-StrictMode -Version 1; $_.OriginInfo }
DEBUG: ! CALL function '<ScriptBlock>'
DEBUG: 42+ $originInfo = & { >>>> Set-StrictMode -Version 1; $_.OriginInfo }
DEBUG: 42+ $originInfo = & { Set-StrictMode -Version 1; >>>> $_.OriginInfo }
DEBUG: 42+ $originInfo = & { Set-StrictMode -Version 1; $_.OriginInfo >>>> }
Exception calling "EnableAlarmActions" with "2" argument(s): "The object 'vim.HostSystem:host-83069' has already been deleted or has not been completely created"
At line:1 char:1
+ $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException

Reply
0 Kudos
ChrisLeblanc
Contributor
Contributor
Jump to solution

Posting this in case it helps someone.

I got this error as well. I think it was because in testing I had 2 connections to vcenter.

When I used get-vmhost, I had double entries for each system.

I disconnected my connections and tried again (commenting out my connect line after I entered my creds as I was debugging)

I didn't see the error after that.

Reply
0 Kudos
nicolaeprecup
Contributor
Contributor
Jump to solution

Hi

Is it possible to get the Alarms-Status for every element in vCenter: Clusters, Hosts, Vms, Datastore, Networks ?

We hat the Alarms disabled for one Hosts, and for one Storage. The Infrastructure has 9 Hosts, 250 VMs, 30-40 NFS Datastores, and dSwitches. To check them manually...not a good idea 🙂

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Would this work for you?

Get-AlarmDefinition |
Select Name, @{N='Entity';E={$_.Entity.Name}},Enabled


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

nicolaeprecup
Contributor
Contributor
Jump to solution

Hi.

Thank you for the time.

No. I can find this script output in the AlarmDefinition of the vCenter.

What I need to see if any of the Hosts, VMs or Datastores have the option "Alarms -> Disable Alarm Actions" - from the Right click Menu - disabled.

Have a nice day.

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You mean something like this?

Get-Inventory |
Select Name,
  @{N='Type';E={$_.GetType().Name.Replace('Impl','')}},
  @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}


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

nicolaeprecup
Contributor
Contributor
Jump to solution

Hi

Perfect.

Together with the 

Get-Datastore | Select Name, @{N='Type';E={$_.GetType().Name.Replace('Impl','')}}, @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}

I have manage to find some VMs and some Storages that had the Alarms disabled.

Thank you!

Reply
0 Kudos
dbutch1976
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Sorry for awakening this old thread, but I had a related question:

I suspect there are individual hosts in my environment which have the alarm actions disabled. Is there a simple way to get a list of all of them that are in this state?

Thanks.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try something like this

Get-VMHost |
Where{-not $_.ExtensionData.AlarmActionsEnabled} |
Select Name,
  @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}


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

dbutch1976
Hot Shot
Hot Shot
Jump to solution

Thanks LucD!

I did some testing and noticed that this only was showing hosts that had the setting, very simple to check the clusters using the same logic and just changing to get-cluster:

Get-Cluster |
Where{-not $_.ExtensionData.AlarmActionsEnabled} |
Select Name,
  @{N='AlarmActionsEnabled';E={$_.ExtensionData.AlarmActionsEnabled}}

 

Reply
0 Kudos