1 2 Previous Next 21 Replies Latest reply on Jun 23, 2020 8:44 AM by winsolo

    PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

    hharold Hot Shot

      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

        • 1. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
          LucD Guru
          vExpertCommunity WarriorsUser Moderators

          Did you try it this way

          $cluster = Get-Cluster MyCluster
          $alarm = Get-AlarmDefinition -Entity $cluster -Name "Just an alarm"
          Set-AlarmDefinition -AlarmDefinition $alarm -Enabled:$false
          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
            hharold Hot Shot

            Hi Luc,

             

            Thanks for taking a look at this.

             

            But this script would disable an alarm throughout the entire vcenter.

             

            Most important alarm I don't want to trigger alarm actions is: Host connection and power state

            This alarm is set and managed on the vcenter top level.

             

            During patching of one cluster, I still want to get alarms from other clusters/hosts.

             

            Regards,

            Harold

            • 3. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              That is just the principle behind the alarms; you define them on an entity and all child entities will inherit that alarm.

              Assume a datacenter with 3 clusters.

              You defined an alarm on the datacenter.

              If you want to disable that alarm on a specific cluster, without disabling it on the other clusters, you will have to define the alarm not on the datacenter but on each of the clusters individualy , I'm afraid.

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                hharold Hot Shot

                I was kinda afraid that was going to be the answer

                 

                Within the vSphere Client I can right-click a host or cluster and select Alarms | Disable Alarm Actions

                I was hoping PowerCLI could do the same for me.

                 

                I can see the PowerCLI property, but have no idea how to change these:

                [vSphere PowerCLI] D:\Scripts> $esxhost = get-vmhost myhost
                [vSphere PowerCLI] D:\Scripts> $esxhost.ExtensionData.AlarmActionsEnabled
                False
                
                [vSphere PowerCLI] D:\Scripts> $cluster = get-cluster mycluster
                [vSphere PowerCLI] D:\Scripts> $cluster.ExtensionData.AlarmActionsEnabled
                False
                
                

                 

                Regards,
                     Harold

                • 5. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                  LucD Guru
                  User ModeratorsvExpertCommunity Warriors

                  Ok, it seems we were talking about two different things.

                  What you want to do can be done from a PowerCLI script.

                  Something like this

                   

                  $alarmMgr = Get-View AlarmManager 
                  $cluster
                  = Get-Cluster MyCluster
                  #
                  To disable alarm actions
                  $alarmMgr
                  .EnableAlarmActions($cluster.Extensiondata.MoRef,$false) # To enable alarm actions
                  $alarmMgr
                  .EnableAlarmActions($cluster.Extensiondata.MoRef,$true)

                   

                  The same can be done for an ESX(i) host

                   

                  $alarmMgr = Get-View AlarmManager 
                  $esx = Get-VMHost MyEsx

                  # To disable alarm actions
                  $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false) # To enable alarm actions
                  $alarmMgr
                  .EnableAlarmActions($esx.Extensiondata.MoRef,$true)

                   

                  Sorry about the confusion

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  1 person found this helpful
                  • 6. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                    hharold Hot Shot

                    Luc,

                     

                    thanks a lot !

                     

                    This is exactly what I was looking for !

                     

                    Thanks again and best regards,

                         Harold

                    • 7. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                      GP84 Novice

                      Hi all,

                       

                      Is it possible only for one Virtual machine ?

                       

                      With the GUi is easy (right click on VM and disable) but in powershell is not really ....

                       

                      Many thanks

                      • 8. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                        LucD Guru
                        Community WarriorsUser ModeratorsvExpert

                        With the functions I provided in Alarm actions – enable – disable – report you should be able to specify a VM.

                        Something like this

                         

                        $vm = Get-VM MyVM
                        $vm | Set-AlarmActionState -Enabled:$false
                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 9. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                          GP84 Novice

                          Great, working fine !!!!!!

                           

                           

                          Many Thanks

                          • 10. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                            kwg66 Enthusiast

                            this works great, but with the syntax presented, I can't figure out how to do multiple clusters at once, or the entire stack of hosts within vCenter.   Can you please update this post to show how I can run this and disable all hosts in a specific vcenter?   Otherwise, I would have to run this script against each cluster one by one... 

                            • 11. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                              LucD Guru
                              vExpertUser ModeratorsCommunity Warriors

                              Not sure i get your question 100%.
                              Do you want to enable/disable a specific alarm action on all alarms on all VMs in all cluster under all vCenters?

                              Are you working in single or multiple mode?

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 12. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                                kwg66 Enthusiast

                                I want to disable and the later re-enable Alarm actions on each host in the vCenter inventory, not within a single cluster.  Right click the host, you see alarms and from there disable or enable alarm actions.  If doing maintenance on a single host you would first disable alarm actions so that snmp traps don't get sent when the host is rebooted for example.  Then after maintenance you re-enable so that when a real issue occurrs the alarms can act and send the snmp traps. 

                                 

                                See, VMware alerting is bugging, to say the least.  Some alarms, when you edit them, trigger actions (snmp traps) that go to our automation system and pages get sent.  So before I start editing any more alerts I want to be certain the no snmp traps are going to get sent.    the host connection and powerstate alert was sending too many false alerts, I opened it up to look at it, clicked ok when done, and boom snmp traps were sent by every host in vCenter to our automation system which then sent a bunch of emails and pages.  This happened 2x now, and I'm afraid to touch this alert again until each host has the alarm actions disabled so the traps aren't sent when configuring the alarms.     

                                • 13. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                                  LucD Guru
                                  vExpertUser ModeratorsCommunity Warriors

                                  The following will for each connected vCenter, get all the ESXi nodes, and then for each ESXi disable Alarms.
                                  For the reverse you comment out the 'disable' line and uncomment the 'enable' line.

                                   

                                   

                                  foreach($vc in $global:DefaultVIServers){

                                      $alarmMgr = Get-View AlarmManager -Server $vc

                                      foreach($esx in Get-VMHost -Server $vc){

                                          # To disable alarm actions

                                          $alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$false)

                                         

                                          # To enable alarm actions

                                          #$alarmMgr.EnableAlarmActions($esx.Extensiondata.MoRef,$true)

                                      }

                                  }

                                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                  • 14. Re: PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters
                                    kwg66 Enthusiast

                                    thank you sir - you are the man. 

                                    1 2 Previous Next