Automation

 View Only
  • 1.  PowerCLI - change existing Alarm in vcenter

    Posted Apr 28, 2020 02:30 PM

    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



  • 2.  RE: PowerCLI - change existing Alarm in vcenter
    Best Answer

    Posted Apr 28, 2020 03:06 PM

    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



  • 3.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 06:37 AM

    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?



  • 4.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 06:48 AM

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

    What does $trigger.Count return?



  • 5.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 09:45 AM

    There are 4 entries.

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



  • 6.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 09:46 AM

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



  • 7.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 09:56 AM

    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?



  • 8.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 10:00 AM

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



  • 9.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 10:06 AM

    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



  • 10.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 10:36 AM

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



  • 11.  RE: PowerCLI - change existing Alarm in vcenter

    Posted Apr 29, 2020 10:02 AM

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