rNico
Contributor
Contributor

PowerCLI - change existing Alarm in vcenter

Jump to solution

Hi Guys,

I have seen some blogs/posts about this but I am not able to easily adapt it.

I just want to change the time interval of the existing alarm "VM CPU load" for the critical alarm.

Currently it says if CPU load is over 90% for 5 minutes, create an alarm.

so I just want to change it from 5 to 15minutes.

Ho can I do this with PowerCLI?

thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

I took the 'Virtual Machine CPU Usage' alarm as an example.

It is set to 5 mins for the red trigger.

The script copies all values of the old trigger, except for the RedIntervalSeconds paramater
You could do something like this

$alarmName = 'Virtual machine CPU usage'

$alarm = Get-AlarmDefinition -Name $alarmName

$trigger = Get-AlarmTrigger -AlarmDefinition $alarm -TriggerType Metric

$sTrigger = @{

    AlarmDefinition = $trigger.Alarm

    EntityType = 'VirtualMachine'

    Metric = $trigger.Metric

    Red = $trigger.Red

    MetricAlarmOperator = $trigger.Operator

    Yellow = $trigger.Yellow

    RedIntervalSeconds = 15 * 60

    YellowIntervalSeconds = $trigger.YellowInterval


}

$newTrigger = New-AlarmTrigger @sTrigger

Set-AlarmDefinition -AlarmDefinition $alarm -AlarmTrigger $newTrigger


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

View solution in original post

0 Kudos
10 Replies
LucD
Leadership
Leadership

I took the 'Virtual Machine CPU Usage' alarm as an example.

It is set to 5 mins for the red trigger.

The script copies all values of the old trigger, except for the RedIntervalSeconds paramater
You could do something like this

$alarmName = 'Virtual machine CPU usage'

$alarm = Get-AlarmDefinition -Name $alarmName

$trigger = Get-AlarmTrigger -AlarmDefinition $alarm -TriggerType Metric

$sTrigger = @{

    AlarmDefinition = $trigger.Alarm

    EntityType = 'VirtualMachine'

    Metric = $trigger.Metric

    Red = $trigger.Red

    MetricAlarmOperator = $trigger.Operator

    Yellow = $trigger.Yellow

    RedIntervalSeconds = 15 * 60

    YellowIntervalSeconds = $trigger.YellowInterval


}

$newTrigger = New-AlarmTrigger @sTrigger

Set-AlarmDefinition -AlarmDefinition $alarm -AlarmTrigger $newTrigger


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

View solution in original post

0 Kudos
rNico
Contributor
Contributor

Hi Luc,

the following exception is thrown after  $newTrigger = New-AlarmTrigger @sTrigger

New-AlarmTrigger : "System.Object[]" kann nicht in den Typ "System.Nullable`1[System.Int32]" konvertiert werden, der

für den Parameter "YellowIntervalSeconds" erforderlich ist. Die angegebene Methode wird nicht unterstützt.

In Zeile:1 Zeichen:32

+ $newTrigger = New-AlarmTrigger @sTrigger

+                                ~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [New-AlarmTrigger], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewAlarmTrigger

Any idea?

0 Kudos
LucD
Leadership
Leadership

It looks as if you have more than 1 object in $trigger.

What does $trigger.Count return?


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

0 Kudos
rNico
Contributor
Contributor

There are 4 entries.

is it because I  work with 4 vcenters in linked mode?

0 Kudos
LucD
Leadership
Leadership

Most probably.
The easiest way would then be to use a ForEach loop, and handle these Alarms one-by-one


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

0 Kudos
rNico
Contributor
Contributor

for testing purposes I have created a new alarm within the UI , but for that I also get 2 trigger entries where red and yellow is seperated

EntityType     : VirtualMachine

Metric         : VMware.VimAutomation.ViCore.Types.V1.MetricImpl

Operator       : Above

Red            :

Yellow         : 7000

YellowInterval : 300

RedInterval    :

Alarm          : nw

EntityType     : VirtualMachine

Metric         : VMware.VimAutomation.ViCore.Types.V1.MetricImpl

Operator       : Above

Red            : 5000

Yellow         :

YellowInterval :

RedInterval    : 300

Alarm          : nw

can you explain why is that?

0 Kudos
LucD
Leadership
Leadership

That looks like a trigger for yellow and another for red.
Looks normal, if that was the intention.


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

0 Kudos
LucD
Leadership
Leadership

Was that Alarm created with 2 triggers or is that after the script?


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

0 Kudos
rNico
Contributor
Contributor

but if I check the trigger for "virtual machine CPU usage", red and yellow are both in one entry.

in the last line of your code you refer to $alarm, which is empty

0 Kudos
LucD
Leadership
Leadership

My bad, something went wrong there.
I updated the code above.


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

0 Kudos