Hi All,
if anyone can help in creating a script for the host to go in maintenance mode if specified error message it sees.
example like.. I will give defined or predefined error message so that when ever host see such pre defined error message it should in maintenance mode.
Can you be a bit more concrete on the type of error you envisage?
FOr example, is it an error that would/could fire a vSphere alarm?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes LucD, the error it should pick from alarm then it take host in maintenance mode.
The following example will create an alarm that is fired by 2 triggers, a Host warning or a Host IP changed.
You can of course change these triggers, they just server as examples.
If either of these triggers fires the alarm, the action will place the host in maintenance mode.
The alarm is defined on a datacenter (but you can change that)
$dcName = "MyDatacenter"
$alarmMgr = Get-View AlarmManager
$entity = Get-Datacenter $dcName | Get-View
# AlarmSpec
$alarm = New-Object VMware.Vim.AlarmSpec
$alarm.Name = "Test2"
$alarm.Description = "Testing"
$alarm.Enabled = $false
# Action - Place host in maint mode
$alarm.action = New-Object VMware.Vim.GroupAlarmAction
$trigger1 = New-Object VMware.Vim.AlarmTriggeringAction
$trigger1.action = New-Object VMware.Vim.MethodAction
$trigger1.Action.Name = 'EnterMaintenanceMode_Task'
$arg1 = New-Object VMware.Vim.MethodActionArgument
$arg1.Value = 0
$arg2 = New-Object VMware.Vim.MethodActionArgument
$arg2.Value = $false
$arg3 = New-Object VMware.Vim.MethodActionArgument
$arg3.Value = $null
$trigger1.Action.Argument = @($arg1,$arg2,$arg3)
# Transition yellow --> red
$trans1a = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec
$trans1a.StartState = "yellow"
$trans1a.FinalState = "red"
$trigger1.TransitionSpecs += $trans1a
$alarm.action.action += $trigger1
# Expression 1 - Host warning
$expression1 = New-Object VMware.Vim.EventAlarmExpression
$expression1.EventType = 'GeneralHostWarningEvent'
#$expression1.eventTypeId = $null
$expression1.objectType = "HostSystem"
$expression1.status = "red"
# Expression 2 - License removed
$expression2 = New-Object VMware.Vim.EventAlarmExpression
$expression2.EventType = 'HostIpChangedEvent'
#$expression2.eventTypeId = $null
$expression2.objectType = "HostSystem"
$expression2.status = "red"
$alarm.expression = New-Object VMware.Vim.OrAlarmExpression
$alarm.expression.expression += $expression1
$alarm.expression.expression += $expression2
$alarm.setting = New-Object VMware.Vim.AlarmSetting
$alarm.setting.reportingFrequency = 0
$alarm.setting.toleranceRange = 0
# Create alarm.
$alarmMgr.CreateAlarm($entity.MoRef, $alarm)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
