Automation

 View Only
  • 1.  VC alarms

    Posted Apr 17, 2008 04:45 PM

    Is there any way to create a new alarm definition in VC using the VI toolkit?



  • 2.  RE: VC alarms
    Best Answer

    Posted Apr 17, 2008 09:07 PM

    As far as I know not with the current cmdlets.

    The only method I currently know about is by using the SDK (again).

    This sample script creates a rather simple alert depending on the state of a guest (VMName).

    $VCimpl = Get-VIServer -Server <VCServer>
    
    # Force load
    [http://Reflection.Assembly|http://Reflection.Assembly]::LoadWithPartialName("vmware.vim")
    
    $svcRef = new-object VMware.Vim.ManagedObjectReference 
    $svcRef.Type = "ServiceInstance" 
    $svcRef.Value = "ServiceInstance" 
    $serviceInstance = get-view $svcRef
    
    $alarmMgr = get-view $serviceInstance.Content.alarmManager
    $entity = Get-View (Get-VM -Name <VMName>).ID
    
    $alarm = New-Object VMware.Vim.AlarmSpec
    
    $alarm.Description = "My alarm description"
    $alarm.Enabled = $TRUE
    
    $alarm.expression = New-Object VMware.Vim.StateAlarmExpression
    $alarm.Expression.Operator = "isEqual"
    $alarm.expression.red = "poweredOff"
    $alarm.Expression.StatePath = "runtime.powerState"
    $alarm.expression.type = "VirtualMachine"
    $alarm.expression.yellow = "suspended"
    
    $alarm.Name = "My new state alarm"
    
    $alarm.setting = New-Object VMware.Vim.AlarmSetting
    $alarm.setting.reportingFrequency = 0
    $alarm.setting.toleranceRange = 0
    
    $alarmMgr.CreateAlarm($entity.MoRef, $alarm)
    

    For an overview of the creation and management of alerts with the SDK see chapter 9 in the SDK Programming Guide.

    For details about the objects used in the script see the SDK API Reference

    Since the forum SW reformats some of the code (despite the code and noformat tags) I have included the sample script as an attachment.