Highlighted
Enthusiast
Enthusiast

PowerCLI: Enable / Disable Alarm Actions on Hosts / Clusters

Jump to solution

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 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

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 Smiley Happy


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

View solution in original post

21 Replies
Highlighted
User Moderator
User Moderator

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Enthusiast
Enthusiast

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

0 Kudos
Highlighted
User Moderator
User Moderator

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Enthusiast
Enthusiast

I was kinda afraid that was going to be the answer Smiley Sad

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

0 Kudos
Highlighted
User Moderator
User Moderator

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 Smiley Happy


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

View solution in original post

Highlighted
Enthusiast
Enthusiast

Luc,

thanks a lot !

This is exactly what I was looking for !

Thanks again and best regards,

     Harold

0 Kudos
Highlighted
Contributor
Contributor

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

0 Kudos
Highlighted
User Moderator
User Moderator

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Contributor
Contributor

Great, working fine !!!!!!

Many Thanks

0 Kudos
Highlighted
Hot Shot
Hot Shot

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... 

0 Kudos
Highlighted
User Moderator
User Moderator

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Hot Shot
Hot Shot

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.     

0 Kudos
Highlighted
User Moderator
User Moderator

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Highlighted
Hot Shot
Hot Shot

thank you sir - you are the man. 

0 Kudos
Highlighted
Contributor
Contributor

Thanks LucD, seems in 6.7 i'm having issues trying to find the view in html5 that shows you that satus of Host Alarms Enabled/Disabled?

Can you elaborate on how one can do this with PowerCLI, just show an operator the status of alarms within a VC?

TIA

0 Kudos
Highlighted
User Moderator
User Moderator

The Get-AlarmDefinition cmdlet has the Enabled property.


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

0 Kudos
Highlighted
Contributor
Contributor

I'm still a bit confused here.

Im looking for a powerCLI solution, to not only Enable or Disable alarms, but one that would also just list the hosts and the status Enabled/Disabled (True or False) in the output letting me know if a have an unwanted host enabled or disabled.

In the Thick client i swear there was a view that allowed you to see all the hosts and that status, however in HTML5 6.7 i'm just not seeing it anymore.

0 Kudos
Highlighted
User Moderator
User Moderator

You could do something like this

Get-VMHost -PipelineVariable esx | Get-AlarmDefinition |

Select @{N='VMHost';E={$esx.Name}},Enabled,Name

And you can also see that in the Web Client

alarm.png


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

0 Kudos
Highlighted
Enthusiast
Enthusiast

Hey LucD

Are these commands still valid? Will they work with VMware PowerCLI 12.0.0 build 15947286, VCSA 6.7.0 15976728, VMware ESXi 6.7.0 build-15018017

$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)
0 Kudos