CreateAlarm not (always) compatible with the vSphere client

In a recent PowerCLI Community thread someone asked how he could create Alarms with the current PowerCLI build. Since there is no PowerCLI cmdlet (yet) to create Alarms I had to fall back on the CreateAlarm method from the SDK.

The procedure as described in the vSphere Web Services SDK Programming Guide, chapter 15, is quite simple. The script I wrote created the alarm, but to my amazement I couldn’t use the Edit Settings option in the vSphere client. The option was grayed out.

alarm-edit-settingsFirst I doubted the correctness of my script but after some tests I could confirm that the alarm worked correctly.

With a bit of reverse engineering and with the help of Fiddler (see The Onyx alternative ?) I discovered that all the alarms that are created with the vSphere client use the GroupAlarmAction and the OrAlarmExpression objects even if there is only one alarm action and one alarm expression present.

That in itself is not really a big problem, but the fact that the vSPhere client can’t seem to get at the settings of the alarm when the alarm is not created along that line could be a problem.

Ultimately I ended up with two scripts.

In both cases the script creates an alarm that will trigger when the ESX server is placed in maintenance mode and will then send an SNMP trap.

The vSphere client compatible version:

The SDK version:

Perhaps someone @VMW should have a look and perhaps give some feedback ?


    Scott Elliott

    I am getting an error: Exception calling “CreateAlarm” with “2” argument(s): “A specified parameter was not correct: ”

    I am testing with a VCSA version 6.0 update 2.


    Hi Luc,
    This is a very useful script but I’m getting this error message:

    Get-View : 27/02/2013 4:00:57 PM Get-View View with Id ‘AlarmManager-AlarmManager’ was n
    ot found on the server(s).
    At D:\SM\2AlarmConfig\alarm.ps1:5 char:21
    + $alarmMgr = Get-View <<<< AlarmManager
    + CategoryInfo : ObjectNotFound: (:) [Get-View], VimException
    + FullyQualifiedErrorId : Core_GetView_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.


    In case anyone out there wants to use Luc’s great work to create the alarm in vCenter. I got this working by editing the lines 04 and 42 in the vSphere Compatible version of code.

    04 – Change “$entity = Get-VMHost $esxName | Get-View”


    $entity = Get-View -ViewType Folder

    42 – Change “$alarmMgr.CreateAlarm($entity.MoRef, $alarm)”


    $alarmMgr.CreateAlarm($entity[0].MoRef, $alarm)

    …Editing the alarm after creation must have been resolved. Editing works in 5.1

    Thanks again…. This is going to make my deployments much easier!


      Thanks for sharing that.


    Hi Luc, i need to create on vsphere5 an alarm that send an email when the disk usage is over a % value.
    I’ve tried also with onyx but the script created works only on that virtualcenter…
    Can you please help me


    Hi Luc,

    your script is not longer working with 4.1 ;-(



      I’ll have a look


    Hi Luc,

    Thank you for your post – I too noticed this behaviour and your tip about using the groupalarm action saved me.

    The least I can do is take the time to thank you.



    Lets have our SDK Dev Support team take a look.



      Thanks Pablo, I submitted a SR.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.