Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 230200

create alarms with powercli

$
0
0

Hello,

I have a look in LucD scripts and ther was very helpfull, I have create a lot of personal simple alarms in my vSphere 4.1.

The script is not from me I have try to adopted the script from LucD.

But at the moment I have to create an Alarm (see screenshot) via powercli, and i don't know what is wrong in my script, I hope somebody can help me to finish my script.

Thank you in advance,

Philippe

 

$vCenterServer = "vcenter-server"

$user = "username"

$pass = "password"

if ( $DefaultVIServers.Length -lt 1 )

Connect-VIServer -Server $vCenterServer -Protocol https -User $user -Password $pass -WarningAction SilentlyContinue | Out-Null

}

 

$alarmMgr = Get-View AlarmManager

 

# Create AlarmSpec object
$alarm = New-Object VMware.Vim.AlarmSpec
$alarm.Name = "510_Hosts-1"
$alarm.Description = "specific Alert definition"
$alarm.Enabled = $TRUE

 

# Event expression 1 - Host Connection State
# will change state to "Red"
$expression1 = New-Object VMware.Vim.EventAlarmExpression
$expression1.EventType = "EventEx"
$expression1.eventTypeId = "Host Connection State"
$expression1.objectType = "HostSystem"
$expression1.status = "red"

 

# Attribute comparison for expression 1
$comparison1 = New-Object VMware.Vim.EventAlarmExpressionComparison
$comparison1.AttributeName = "Host Connection State"
$comparison1.Operator = "isEqualTo"
$comparison1.red = "Disconnected"
#$comparison1.RedInterval = 300
$comparison1.yellow = "None"
#$comparison1.yellowinterval = 300

$comparison1.Value = "1"
$expression1.Comparisons += $comparison1

 

# Event expression 2 - VM MAC changed
# will change state back to "red"
$expression2 = New-Object VMware.Vim.EventAlarmExpression
$expression2.EventType = "EventEx"
$expression2.eventTypeId = "Host Console SwapIn Rate (KBps)"
$expression2.objectType = "HostSystem"
$expression2.status = "red"

 

# Attribute comparison for expression 2
$comparison2 = New-Object VMware.Vim.EventAlarmExpressionComparison
$comparison2.AttributeName = "Host Console SwapIn Rate (KBps)"
$comparison2.Operator = "isAbove"
$comparison2.red = 4096
$comparison2.RedInterval = 1
$comparison2.yellow = 1024
$comparison2.yellowinterval = 1

$comparison2.Value = "1"
$expression2.Comparisons += $comparison2

 

# Add event expressions to alarm
$alarm.expression = New-Object VMware.Vim.OrAlarmExpression
$alarm.expression.expression += $expression1
$alarm.expression.expression += $expression2
#$alarm.expression.expression += $expression3

 

# Create alarm in vCenter root
$alarmMgr.CreateAlarm("Folder-group-d1",$alarm)

# Add action (send mail) to the newly created alarm
Get-AlarmDefinition $alarm.Name | New-AlarmAction -Script -ScriptPath 'd:\vcenter-alarmlog\virtual-machines.bat'


Viewing all articles
Browse latest Browse all 230200

Trending Articles