View Only
  • 1.  Alarm configuration scripting

    Posted Jun 28, 2010 01:59 PM


    I'm a beginner with PowerCLI but with the help of and the VI Api, I am writting a script to automate my alarm configuration for vCenter.

    The purpose of my script is to:

    -delete all action for all alerts

    -rename some alerts with a prefix to remark them

    -configuring those same alerts with the special values we use in our structure

    the structure of the script is as follow (I wasn't able to join the script to the topic when posting...):

    #listing all alert I target


    $alarmMgr = Get-View AlarmManager

    $alarms = $alarmMgr.GetAlarm($null)

    $alarms | %{

    + $alarm = Get-View $_+

    + $spec = New-Object VMware.Vim.AlarmSpec#Ecrasement des anciennes actions (SNMP...)+

    + $spec.Action = New-Object VMware.Vim.GroupAlarmAction #Copie des spécifications inchangées+

    + $spec.Expression = $alarm.Info.Expression+

    + $spec.Setting = $alarm.Info.Setting+

    + $spec.Name = $alarm.Info.Name+

    + $spec.Enabled = $alarm.Info.Enabled+

    + $spec.Description = $alarm.Info.Description+

    + +

    + if( $tgtAlarmName -contains $alarm.Info.Name){+

    + $spec.Name = "RBS "$alarm.Info.Name

    + $alarmTrigger = New-Object VMware.Vim.AlarmTriggeringAction+

    + $alarmTrigger.Action = New-Object VMware.Vim.SendEmailAction+

    + $alarmTrigger.Action.toList = $cibleMail+

    + $alarmTrigger.Action.CcList = $cibleMailCopie+

    + $alarmTrigger.Action.Subject = $objetMail$spec.Name

    + $alarmTrigger.Action.Body = " Alerte vCenter \n\n Probleme avec le moniteur :"$spec.Name"\n\n Verifiez son état\n"+

    + +

    + #here some condition block to proceed different configuration+

    + ......+

    + $spec.Action.Action = $alarmTrigger

    + }+

    + $alarm.ReconfigureAlarm($spec)+


    The unitary testing was well working but when I execute my script with the wright values for final testing, I always get an error:

    "Exception calling "ReconfigureAlarm" with "1" argument(s): "Not initialized: vim.alarm.alarmAction[] action..."

    on line 203 of my script, and occurring the same number of times, that the number of alarms I have in vCenter.

    As the declaration of the VMware.Vim.AlarmSpec object isn't in a conditionned block, I can't figure why I get those error,

    As anyone thoughts on that?

    PS : Excuse my poor english, if one of my sentences wasn't clear enough, fell free to re-ask

    // the same way, my comments on the script is in french, but if you need I can translate some lines

  • 2.  RE: Alarm configuration scripting

    Posted Jun 28, 2010 02:05 PM

    still wasn't able to attach the file... if one of you want to take a look at the code, i eventually can send the .ps1 file by email.

    As said, any help will be welcomed. Thanks again

  • 3.  RE: Alarm configuration scripting

    Posted Jun 28, 2010 02:51 PM

    few tests later, it seems that it's not allowed to proceed a reconfiguration of an alarm with an empty GroupAlarmAction (even a SendEmailAction without any AlarmTriggeringActionTransitionSpec won't work... )

    So, has anyone a way to reconfigure an alarm without action, or with an action that won't do anything?

    (Again, the purpose is, deleting the SendSNMPAction that is by default on alert)

  • 4.  RE: Alarm configuration scripting
    Best Answer

    Posted Jun 28, 2010 03:01 PM

    Sure, I PM-ed you my email address.


    Blog: LucD notes

    Twitter: lucd22

  • 5.  RE: Alarm configuration scripting

    Posted Jun 28, 2010 03:29 PM

    I sent you the script by email,

    btw, thank for all the help your blog already gave me :smileyhappy:

  • 6.  RE: Alarm configuration scripting

    Posted Jun 28, 2010 04:44 PM

    Thanks, you're welcome.

    I think I found the problem in your script.

    By default you create a GroupAlarmAction. That is ok, provided you have some actions in the Action property.

    If there are no actions on an alarm, you have to throw away the GroupAlarmAction and set the $spec.Action property to $null.

    I have added a simple test that solves this problem.

    	#Remplacement des alarmes avec les nouvelles spécifications
    	if($spec.Action.Action -eq $null){
    		$spec.Action = $null


    Blog: LucD notes

    Twitter: lucd22

  • 7.  RE: Alarm configuration scripting

    Posted Jun 29, 2010 06:54 AM

    Thank you for your prompt answer,

    I think that test solve the problem, nevertheless I still got an error on execution.

    On the same line , "Execution calling "ReconfigurationAlarm" with "1" argument(s) 'a specified parameter was not correct.' "

    and this time it appears only one time.

    So I suppose that I have a problem during the configuration of one alert,

    but I can't figure which one, because the script don't do any of my "Write-Host" cmdlets, so I can't locate in which conditionnal block it is.

    Any idea, on how I can do, to debug something like that?

    Is there a way to have a view of the execution stack in Powershell?

  • 8.  RE: Alarm configuration scripting

    Posted Jun 29, 2010 07:05 AM

    How do you run the script ?

    From the PowerCLI prompt ? Or from another environment ? PS ISE, the VESI... ?

    I have no problem seeing the Write-Host output.


    Blog: LucD notes

    Twitter: lucd22

  • 9.  RE: Alarm configuration scripting

    Posted Jun 29, 2010 07:12 AM

    I run it from the PowerCLI prompt and I only see the WriteHost output comming from the few line I have add on the top of the script.

    But I don't see the few I added in the conditionnal block, so I can't see how much alert are configured well before the error occurs.

    Moreover, it seems that the script don't enter in the configuration part I made, probably because of the String recognition,

    Is there a way to use a sort of ID to determine which alert it is, instead of the .Name parameter?

  • 10.  RE: Alarm configuration scripting

    Posted Jun 29, 2010 07:30 AM

    Ok... my mistake... I was testing the $spec.Name parameter (that I already add prefixed) , instead of $

    So your test bellow really answer my question. Thanks again =D