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'
What doesn't work ?
Is the alarm not created ? Or does the alarm not fire correctly ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
An EventAlarmExpression doesn't have the yellow and red properties, those are used in MetricAlarmExpression.
Have a look at Alarm expressions – Part 2 : Event alarms, it shows how event based alarms should be created.
In fact what kind of alarm are you trying t create ?
Should it fire on an event, or a performance metric crossing a watermark ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
I hope the follow informations can help?
I tried to set folowing:
Righter general:
- Alarm Name: ....
- Alarm Description: ....
- Alarm Type Monitore: Hosts
- Monitor for specific conditions or state, for example, CPU usage, powerstate
Righter Trigger (with 6 Trigger):
- Trigger Type 1: Host Connection State
- Condition 1: Is equal to
- Warning 1: None
- Alert 1: Disconnected
- Trigger Type 2: Host Console SwapIn Rate (KBps)
- Condition 2: Is above
- Warning 2: 1024
- Condition Length 2: for 1 min
- Alert 2: 4096
- Condition Length 2: for 1 min
- Trigger Type 3: Host Console SwapOut Rate (KBps)
- Condition 3: Is above
- Warning 3: 1024
- Condition Length 3: for 1 min
- Alert 3: 4096
- Condition Length 3: for 1 min
- Trigger Type 4: Host CPU usage (%)
- Condition 4: Is above
- Warning 4: 80
- Condition Length 4: for 15 min
- Alert 4: 90
- Condition Length 4: for 10 min
- Trigger Type 5: Host Memory usage (%)
- Condition 5: Is above
- Warning 5: 90
- Condition Length 5: for 15 min
- Alert 5: 100
- Condition Length 5: for 10 min
- Trigger Type 6: Host Power State
- Condition 6: Is equal to
- Warning 6: None
- Alert 6: Standby
But I don't know how to do this? Maybe you can help me with an example?
Thanks
Philippe
I have try to take the MetricAlarmExpression but if I used this, I receive an error with the EventType ="EventEx"
For example:
# 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.MetricAlarmExpression
$expression1.EventType = "EventEx"
$expression1.eventTypeId = "Host Connection State"
$expression1.objectType = "HostSystem"
$expression1.status = "red"
Using a metric in an alarm is done differently.
See my Alarm expressions – Part 1 : Metric alarms post.
A MetricCounterId is not fixed, it can be a different ID in each vCenter. It depends on the components that are installed.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference