VMware Cloud Community
wolficool
Contributor
Contributor
Jump to solution

Create new Alarm in vCenter for Host Administrator access enabled - disabled

Hello,

i want to create a new vCenter Alarm with Powercli.

The Alarm Defininitons see in the attached Screenshot.

Manually it works, but to automate these with Powercli works not.

I have read William Lam Post and wanted to try it with these.. but it just work on Datacenter Level..

https://williamlam.com/2019/02/creating-vcenter-alarms-based-on-task-events-such-as-folder-creation....

See here my tests for that:

 

$eventType = Get-EventType | Where {$_.id -eq 'EventType-HostAdminDisableEvent;FullFormat-Administrator access to the host {host.name} is disabled'}
$eventTrigger = New-AlarmTrigger -EventType $eventType -EntityStatus Yellow -EntityType VMHost
New-AlarmDefinition -Name "Host Lockdown Mode Disabled" -Description "Administrator access to the host has been enabled" -Entity (Get-Datacenter) -Trigger $eventTrigger 

Name                 Description                                             Enabled
----                 -----------                                             -------
Host Lockdown Mod... Administrator access to the host has been enabled       True 

 

But i want to define the alarm not on the Datacenter Level. I want to create these alarm on the vCenter root Level.

How can i do these?

Also i want to define the Reset to Green Level with the EventType when the Administrator access is enabled again??

Email Notifications is not needed as it is in the screesnhot

Maybe someone has a hint for me how to do that.

Thx

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

For that, you will have to use a 2nd trigger based on the "enabled" event.

Btw, I used "splatting" for the New-AlarmDefintiion cmdlet parameters, it makes the code more legible imho.

$haDisabled = Get-EventType | Where-Object { $_.Key -eq 'HostAdminDisableEvent' }
$haEnabled = Get-EventType | Where-Object { $_.Key -eq 'HostAdminEnableEvent' }

$eventTrigger1 = New-AlarmTrigger -EventType $haDisabled -EntityStatus Yellow -EntityType VMHost
$eventTrigger2 = New-AlarmTrigger -EventType $haEnabled -EntityStatus green -EntityType VMHost

$sAlarm = @{
  Name = "Host Lockdown Mode Disabled"
  Description = "Administrator access to the host has been enabled"
  Entity = (Get-Folder -Name Datacenters)
  Trigger = $eventTrigger1, $eventTrigger2
}
New-AlarmDefinition @sAlarm

 


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You do use Get-Datacenter on the Entity parameter, so it is normal the Alarm is defined on the Datacenter.
If you want to define the Alarm in the root of the vCenter, use

-Entity (Get-Folder -Name Datacenters)


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

0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Thx LucD that works 🙂

But how can i define the Alarm that he go back into the green State?

Any Ideas?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

For that, you will have to use a 2nd trigger based on the "enabled" event.

Btw, I used "splatting" for the New-AlarmDefintiion cmdlet parameters, it makes the code more legible imho.

$haDisabled = Get-EventType | Where-Object { $_.Key -eq 'HostAdminDisableEvent' }
$haEnabled = Get-EventType | Where-Object { $_.Key -eq 'HostAdminEnableEvent' }

$eventTrigger1 = New-AlarmTrigger -EventType $haDisabled -EntityStatus Yellow -EntityType VMHost
$eventTrigger2 = New-AlarmTrigger -EventType $haEnabled -EntityStatus green -EntityType VMHost

$sAlarm = @{
  Name = "Host Lockdown Mode Disabled"
  Description = "Administrator access to the host has been enabled"
  Entity = (Get-Folder -Name Datacenters)
  Trigger = $eventTrigger1, $eventTrigger2
}
New-AlarmDefinition @sAlarm

 


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

0 Kudos
wolficool
Contributor
Contributor
Jump to solution

Thx LucD, i see..

Here should be created two Alarm trigger. One for the yellow state and the 2nd for the green State.

Many Thx for you Help

0 Kudos