Quantcast
Channel: VMware Communities : All Content - All Communities
Viewing all articles
Browse latest Browse all 179681

Create and update alarms

$
0
0

Hi Any idea why I am getting the errors?

   if($deleteOriginal){
    $alarmObj.RemoveAlarm()
   }
   else{
    $updateAlarm = New-Object VMware.Vim.AlarmSpec
    $updateAlarm = $alarmObj.Info
    $oldName = $alarmObj.Info.Name
    $oldState = $alarmObj.Info.Enabled
    $oldDescription = $alarmObj.Info.Description
    $suffix = " (moved to " + ([string]($to | %{$_.Name + ","})).TrimEnd(",") + ")"
    if(($oldName.Length + $suffix.Length) -gt $alarmLength){
     $newName = $oldName.Substring(0, $alarmLength - $suffix.Length) + $suffix
    }
    else{
     $newName = $oldName + $suffix
    }
    $updateAlarm.Name =  $newName
    $updateAlarm.Enabled = $false
    $updateAlarm.Description += ("`r`n    Original name: " + $oldName)
    $updateAlarm.Expression.Expression | %{
     if($_.GetType().Name -eq "EventAlarmExpression"){
      $_.Status = $null
      $needsChange = $true
     }
    }

   $alarmObj.ReconfigureAlarm($updateAlarm)

    $alarmObj.Info.Name = $oldName
    $alarmObj.Info.Enabled = $oldState
    $alarmObj.Info.Description = $oldDescription
   }

   $newAlarm = New-Object VMware.Vim.AlarmSpec
   $newAlarm = $alarmObj.Info

   $oldName = $alarmObj.Info.Name
   $oldDescription = $alarmObj.Info.Description

   foreach($destination in $To){
    if($To.Count -gt 1){
     $suffix = " (" + $destination.Name + ")"
     if(($oldName.Length + $suffix.Length) -gt $alarmLength){
      $newName = $oldName.Substring(0, $alarmLength - $suffix.Length) + $suffix
     }
     else{
      $newName = $oldName + $suffix
     }
     $newAlarm.Name = $newName
     $newAlarm.Description += ("`r`n    Original name: " + $oldName)
    }
    $newAlarm.Expression.Expression | %{
     if($_.GetType().Name -eq "EventAlarmExpression"){
      $_.Status = $null
      $needsChange = $true
     }
    }

    $alarmMgr.CreateAlarm($destination.MoRef,$newAlarm)

 

 

 

 

Capture.PNG


Viewing all articles
Browse latest Browse all 179681

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>