Automation

 View Only
Expand all | Collapse all

Clear Alarms on all hosts in a cluster - PowerCLI

LucD

LucDNov 10, 2022 10:47 PM

  • 1.  Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Jan 03, 2020 03:52 PM

    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-aba1-48bc-a320-5e35142b50af/doc/vim.alarm.AlarmManager.html

    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!



  • 2.  RE: Clear Alarms on all hosts in a cluster - PowerCLI
    Best Answer

    Posted Jan 03, 2020 04:17 PM

    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)



  • 3.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Apr 21, 2022 01:04 PM

    I know this is an old thread but is there a way to filter based on date?

    Scenario: 

    1. reset all alerts
    2. currently active one retriggers.
    3. tech is called for an already existing alert issue (host down or something like that). 

    Would be nice to filter based on date and only reset the older triggered alarms.   

    Could you filter based on acknowledged alerts and only clear those?  Then possibly use another method to acknowledge the older alerts and then clear only the acknowledged alerts with this method?

     

     

    This is the original solution posted by LucD which works great for clearing all triggered alarms. 

    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)



  • 4.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Apr 21, 2022 02:27 PM

    Afaik, this is still the only method that clears all alarms.

    No option to clear a specific alarm.



  • 5.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Jan 03, 2020 04:19 PM

    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.



  • 6.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Jan 03, 2020 04:46 PM
    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


  • 7.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Jan 03, 2020 05:55 PM

    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.



  • 8.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Jan 03, 2020 06:21 PM

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



  • 9.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 07:56 AM

    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 ?



  • 10.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 08:04 AM

    Try with


     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 ?




  • 11.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 10:04 AM

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



  • 12.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 10:33 AM

    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/1376175#M43525



  • 13.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 10:39 AM

    Which PowerCLI version are you using?



  • 14.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 11:20 AM

    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



  • 15.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 11:31 AM

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



  • 16.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 12:27 PM

    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)

     



  • 17.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 12:31 PM

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



  • 18.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 02:38 PM

    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



  • 19.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 02:50 PM

    I mean the vSphere version 6.7



  • 20.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 02:59 PM

    yes, vCenter 6.7



  • 21.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 01, 2021 03:25 PM

    Just tested again, works perfectly for me.

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



  • 22.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Dec 03, 2021 01:36 PM

    Thanks a lot LucD !! 

    As always you helped and its working fine now for me

    Thanks a again !!



  • 23.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Nov 10, 2022 09:40 PM

    I would like to know if there is a way to reset to green for specific alarm to only a VM , I want to attach a script to alarm



  • 24.  RE: Clear Alarms on all hosts in a cluster - PowerCLI

    Posted Nov 10, 2022 10:47 PM

    Afaik unfortunately no.