VMware Cloud Community
HarjitSB
Enthusiast
Enthusiast

Create Alarm Definition

Hello Team , Pls help me to create a three alarm on multiple vCenters in one go.

Requirement is to do the given via PowerCLI

"From the vSphere Client select the vCenter server at the top of the hierarchy and go to >> Alarms >> Definitions >> Right click in the empty space and select New Alarm. On the General tab provide an alarm name and description, Select vCenter for alarm type and 'Monitor for specific events occurring on this object', check 'Enable this alarm'. On the Triggers tab click Add three triggers and in the event column enter 'vim.event.PermissionAddedEvent', 'vim.event.PermissionRemovedEvent', and 'vim.event.PermissionUpdatedEvent' for the three triggers and click OK"

Rgds

-Harjit

Tags (3)
0 Kudos
3 Replies
LucD
Leadership
Leadership

What do you already have in your script?

Did you already do a search in this community?
There's bound to be many examples of creating an alarm.


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

0 Kudos
HarjitSB
Enthusiast
Enthusiast

Hi LucD, I have tried , but no luck, pls help.

I have tried this - found from the community itself.

$alarmMgr = Get-View AlarmManager

# Create AlarmSpec object

$alarm = New-Object VMware.Vim.AlarmSpec

$alarm.Name = "STIG VCWN-06-000048 - Permission Modification"

$alarm.Description = "Track permission changes"

$alarm.Enabled = $TRUE

# Event expression 1 - Permission Added

$expression1 = New-Object VMware.Vim.EventAlarmExpression

$expression1.EventType = "EventEx"

$expression1.EventTypeId = "vim.event.PermissionAddedEvent"

$expression1.ObjectType = "VirtualMachine"

$expression1.status = "Yellow"

# Event expression 2 - Permission Removed

$expression2 = New-Object VMware.Vim.EventAlarmExpression

$expression2.EventType = "EventEx"

$expression2.EventTypeId = "vim.event.PermissionRemovedEvent"

$expression2.ObjectType = "VirtualMachine"

$expression2.status = "Yellow"

# Event expression 3 - Permission Modified

$expression3 = New-Object VMware.Vim.EventAlarmExpression

$expression3.EventType = "EventEx"

$expression3.EventTypeId = "vim.event.PermissionUpdatedEvent"

$expression3.ObjectType = "VirtualMachine"

$expression3.status = "Yellow"

# Add event expressions to alarm

$alarm.expression = New-Object VMware.Vim.OrAlarmExpression

$alarm.expression.expression += $expression1

$alarm.expression.expression += $expression2

$alarm.expression.expression += $expression3

# Create alarm in vCenter root

$alarmMgr.CreateAlarm("{appliancename}",$alarm)

0 Kudos
LucD
Leadership
Leadership

My reply on the thread where you got this code from is still valid.
The first parameter needs to be a MoRef.
Change the last line to

$rootFolder = Get-Folder -Name Datacenters

$alarmMgr.CreateAlarm($rootFolder.ExtensionData.MoRef,$alarm)


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

0 Kudos