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
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
$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
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
$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
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?
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
There are 4 entries.
is it because I work with 4 vcenters in linked mode?
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
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?
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
Was that Alarm created with 2 triggers or is that after the script?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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
My bad, something went wrong there.
I updated the code above.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference