aculed
Contributor
Contributor

Clear Alarms on all hosts in a cluster - PowerCLI

Jump to solution

Can someone please provide an example of how to make use of the new ESXi 6.7 API function ClearTriggeredAlarms as described here: https://vdc-repo.vmware.com/vmwb-repository/dcr-public/3325c370-b58c-4799-99ff-58ae3baac1bd/45789cc5...

Currently, I'm acknowledging alarms on all hosts within a cluster in a script, but I'd like to take that a step further and clear that specific alarm on all hosts as well.  I can't seem to get the filter right to do this appropriately.

Thanks!

1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Try something like this.
Note that you can specify different values for all three enums, depending on which alarms you want to clear.

$alarmMgr = Get-View AlarmManager

$filter = New-Object VMware.Vim.AlarmFilterSpec

$filter.Status += [VMware.Vim.ManagedEntityStatus]::red

$filter.TypeEntity = [VMware.Vim.AlarmFilterSpecAlarmTypeByEntity]::entityTypeVm

$filter.TypeTrigger = [vmware.vim.AlarmFilterSpecAlarmTypeByTrigger]::triggerTypeEvent


$alarmMgr.ClearTriggeredAlarms($filter)


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

View solution in original post

23 Replies
LucD
Leadership
Leadership

Try something like this.
Note that you can specify different values for all three enums, depending on which alarms you want to clear.

$alarmMgr = Get-View AlarmManager

$filter = New-Object VMware.Vim.AlarmFilterSpec

$filter.Status += [VMware.Vim.ManagedEntityStatus]::red

$filter.TypeEntity = [VMware.Vim.AlarmFilterSpecAlarmTypeByEntity]::entityTypeVm

$filter.TypeTrigger = [vmware.vim.AlarmFilterSpecAlarmTypeByTrigger]::triggerTypeEvent


$alarmMgr.ClearTriggeredAlarms($filter)


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

LucD
Leadership
Leadership

Btw, this methods is for all alarms in a vCenter, there is no option afaik, to only clear alarms in a specific cluster with this method.


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

aculed
Contributor
Contributor
Thank you for your help as always.  Can I use the TypeTrigger to filter on a specific vC alarm?  I worry about your last point that this is clears across the entire vC
LucD
Leadership
Leadership

I'm afraid not, the AlarmFilterSpecAlarmTypeByTrigger enum only has three values: All, Event and Metric.

The AlarmFilterSpecAlarmTypeByEntity enum also has three possibilities: All, VM and Host.
Add to that the status which takes a value from the ManagedEntityStatus enum: gray, green, red and yellow.s.

You have some limited filtering possibilities.

For example: all red alarms for ESXi nodes that are triggered by an event.


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

aculed
Contributor
Contributor

That's what I was afraid of.  Thank you again!

rachappachalmi
Enthusiast
Enthusiast

Hi LucD,

I am looking for PowerCLI script which clears all the vCenter alarms in one shot,

I just want to schedule this every week Friday end of business hours, can you pls help me with script to clear all the alarms  in mulitple vCenters in one shot pls ?

0 Kudos
LucD
Leadership
Leadership

Try with


@rachappachalmi wrote:

Hi LucD,

I am looking for PowerCLI script which clears all the vCenter alarms in one shot,

I just want to schedule this every week Friday end of business hours, can you pls help me with script to clear all the alarms  in mulitple vCenters in one shot pls ?


$alarmMgr = Get-View AlarmManager
$filter = New-Object VMware.Vim.AlarmFilterSpec
$filter.Status += [VMware.Vim.ManagedEntityStatus]::red
$filter.TypeEntity = [VMware.Vim.AlarmFilterSpecAlarmTypeByEntity]::entityTypeAll
$filter.TypeTrigger = [vmware.vim.AlarmFilterSpecAlarmTypeByTrigger]::triggerTypeAll

$alarmMgr.ClearTriggeredAlarms($filter)


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

rachappachalmi
Enthusiast
Enthusiast

thanks a lot LucD, I will check this and update back.

rachappachalmi
Enthusiast
Enthusiast

when I use this , I am getting below error

New-Object : Cannot find type [VMware.Vim.AlarmFilterSpec]: verify that the assembly containing this type is loaded.

you also discussed solution for this in below tread but  am still not able to able to understand, would you be able provide step by step what exactly needs to be done to fix this if possible ?

https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/how-to-use-powercli-Data-Objects/m-p/1...

LucD
Leadership
Leadership

Which PowerCLI version are you using?


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

rachappachalmi
Enthusiast
Enthusiast

PowerCLI Version
----------------
VMware PowerCLI 6.5 Release 1 build 4624819
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component 6.5 build 4624453
VMware VimAutomation Core PowerCLI Component 6.5 build 4624450
VMWare ImageBuilder PowerCLI Component 6.5 build 4561891
VMWare AutoDeploy PowerCLI Component 6.5 build 4561891
VMware Vds PowerCLI Component 6.5 build 4624695
VMware Cloud PowerCLI Component 6.5 build 4624821
VMware HA PowerCLI Component 6.0 build 4525225
VMware HorizonView PowerCLI Component 7.0.2 build 4596620
VMware Licensing PowerCLI Component 6.5 build 4624822
VMware PCloud PowerCLI Component 6.5 build 4624825
VMware Storage PowerCLI Component 6.5 build 4624820
VMware vROps PowerCLI Component 6.5 build 4624824
VMware vSphere Update Manager PowerCLI 6.5 build 4540462

 

PowerCLI E:\Rachappa\TEST\alarms> Get-Module -Name VMware* -ListAvailable | Select Name,Version

Name Version
---- -------
VMware.DeployAutomation 6.0.0.0
VMware.ImageBuilder 6.0.0.0
VMware.VimAutomation.Cis.Core 6.5.0.4624453
VMware.VimAutomation.Cloud 6.5.0.4624821
VMware.VimAutomation.Common 6.5.0.4624451
VMware.VimAutomation.Core 6.5.0.2604913
VMware.VimAutomation.HA 6.0.0.0
VMware.VimAutomation.HorizonView 7.0.2.4596620
VMware.VimAutomation.License 6.5.0.4624822
VMware.VimAutomation.PCloud 6.5.0.4624825
VMware.VimAutomation.Sdk 6.5.0.4624452
VMware.VimAutomation.Storage 6.5.0.4624820
VMware.VimAutomation.Vds 6.5.0.4624695
VMware.VimAutomation.vROps 6.5.0.4624824
VMware.VumAutomation 6.0.0.0

0 Kudos
LucD
Leadership
Leadership

That is a rather old version.
I suggest you upgrade first.
See Welcome PowerCLI to the PowerShell Gallery - Install Process Updates - VMware PowerCLI Blog


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

rachappachalmi
Enthusiast
Enthusiast

Hi LucD,

As you suggested, i upgraded and its running without any error but alerts are not resetting green.

PS C:\Users\RachappaChalmi\Documents\Scripts> .\AlarmTestvCenter.ps1
PS C:\Users\RachappaChalmi\Documents\Scripts> .\AlarmTestvCenter.ps1
PS C:\Users\RachappaChalmi\Documents\Scripts> .\AlarmTestvCenter.ps1
PS C:\Users\RachappaChalmi\Documents\Scripts>

Below is the script you shared, i just put this in notepad and made it .ps1 and ran it. but alerts are not resetting

$alarmMgr = Get-View AlarmManager
$filter = New-Object VMware.Vim.AlarmFilterSpec
$filter.Status += [VMware.Vim.ManagedEntityStatus]::red
$filter.TypeEntity = [VMware.Vim.AlarmFilterSpecAlarmTypeByEntity]::entityTypeAll
$filter.TypeTrigger = [vmware.vim.AlarmFilterSpecAlarmTypeByTrigger]::triggerTypeAll

$alarmMgr.ClearTriggeredAlarms($filter)

 

0 Kudos
LucD
Leadership
Leadership

This is a method that was introduced in 6.7.
You are on 6.7 or higher I assume?


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

rachappachalmi
Enthusiast
Enthusiast

PowerCLI Version
----------------
VMware PowerCLI 12.4.0 build 18627050
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.4 build 18627061
VMware Cis Core PowerCLI Component PowerCLI Component 12.4 build 18627057
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.4 build 18627056
VMware VimAutomation Srm PowerCLI Component PowerCLI Component 12.3 build 17843071
VMware VimAutomation License PowerCLI Component PowerCLI Component 12.0 build 15939670
VMware VimAutomation Storage PowerCLI Component PowerCLI Component 12.4 build 18735056
VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 12.4 build 18627062
VMware CloudServices PowerCLI Component PowerCLI Component 12.4 build 18627058
VMware Vmc PowerCLI Component PowerCLI Component 12.4 build 18627053
VMware Nsxt PowerCLI Component PowerCLI Component 12.3 build 17843496
VMware VimAutomation vROps PowerCLI Component PowerCLI Component 12.2 build 17532798
VMware HorizonView PowerCLI Component PowerCLI Component 12.3 build 18592768
VMware VimAutomation Cloud PowerCLI Component PowerCLI Component 12.0 build 15940183
VMWare ImageBuilder PowerCLI Component 7.0 build 17849781
VMWare AutoDeploy PowerCLI Component 7.0 build 17849781
VMware vSphere Update Manager PowerCLI 6.5 build 16941488
VMware VimAutomation Security PowerCLI Component PowerCLI Component 12.3 build 17833870
VMware Hcx PowerCLI Component PowerCLI Component 12.4 build 18627051
VMware Workload Management PowerCLI Component PowerCLI Component 12.4 build 18627055

0 Kudos
LucD
Leadership
Leadership

I mean the vSphere version 6.7


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

rachappachalmi
Enthusiast
Enthusiast

yes, vCenter 6.7

LucD
Leadership
Leadership

Just tested again, works perfectly for me.

If your alarms have the Yellow status, you could add that option

$alarmMgr = Get-View AlarmManager
$filter = New-Object VMware.Vim.AlarmFilterSpec
$filter.Status = [VMware.Vim.ManagedEntityStatus]::red,[VMware.Vim.ManagedEntityStatus]::yellow
$filter.TypeEntity = [VMware.Vim.AlarmFilterSpecAlarmTypeByEntity]::entityTypeAll
$filter.TypeTrigger = [vmware.vim.AlarmFilterSpecAlarmTypeByTrigger]::triggerTypeAll

$alarmMgr.ClearTriggeredAlarms($filter)


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

rachappachalmi
Enthusiast
Enthusiast

Thanks a lot LucD !! 

As always you helped and its working fine now for me 🙂

Thanks a again !!