Why custom event alarm can not get $env:VMWARE_ALARM_EVENTDESCRIPTION value ?
The output is similar like event.xxx.fullFormat (xxx), but in vCenter GUI, the custom description is showing....
Do I need to use Get-ItemPropertyValue or Get-Item $env:VMWARE_ALARM_EVENTDESCRIPTION ?
Thanks
Would you mind sharing the script with which you created the Alarm.
And also the Action script.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
# Create AlarmSpec object
$sampleAlarm = New-Object VMware.Vim.AlarmSpec
$sampleAlarm.Name = $sampleAlarmName
$sampleAlarm.Description = $sampleAlarmDescription
$sampleAlarm.Enabled = $TRUE
# Configure Trigger Events
# sampleAlarm Action - Send email
$sampleAlarm.action = New-Object VMware.Vim.GroupAlarmAction
$sampleTrigger = New-Object VMware.Vim.AlarmTriggeringAction
$sampleTrigger.action = New-Object VMware.Vim.SendEmailAction
$sampleTrigger.action.ToList = $ToEmail
$sampleTrigger.action.Subject = $env:VMWARE_ALARM_NAME
$sampleTrigger.action.CcList = $ccMailList
$sampleTrigger.action.Body = $env:VMWARE_ALARM_EVENTDESCRIPTION
# current output here is event.SAMPLE11011.fullFormat (SAMPLE11011), however the main program sent the trigger event and detail description to vCenter
# Transition 1a - green --> yellow
$sampleTrans1a = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec
$sampleTrans1a.StartState = "green"
$sampleTrans1a.FinalState = "yellow"
# Transition 1b - yellow --> red
$sampleTrans1b = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec
$sampleTrans1b.StartState = "yellow"
$sampleTrans1b.FinalState = "red"
# Transition 1c - red --> yellow
$sampleTrans1c = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec
$sampleTrans1c.StartState = "red"
$sampleTrans1c.FinalState = "yellow"
# Transition 1d - yellow --> green
$sampleTrans1d = New-Object VMware.Vim.AlarmTriggeringActionTransitionSpec
$sampleTrans1d.StartState = "yellow"
$sampleTrans1d.FinalState = "green"
$sampleTrigger.TransitionSpecs += $sampleTrans1a
$sampleTrigger.TransitionSpecs += $sampleTrans1b
$sampleTrigger.TransitionSpecs += $sampleTrans1c
$sampleTrigger.TransitionSpecs += $sampleTrans1d
$sampleAlarm.action.action += $sampleTrigger
# Cluster Event expression 1 - SAMPLE11011 ("yellow" state)
$sampleEvent1 = New-Object VMware.Vim.EventAlarmExpression
#$expression1.EventType = "EventEx"
$sampleEvent1.EventType = $null
$sampleEvent1.eventTypeId = "SAMPLE11011"
$sampleEvent1.objectType = "ClusterComputeResource"
$sampleEvent1.status = "yellow"
# Cluster Event expression 2 - SAMPLE11012 ("green" state)
$sampleEvent2 = New-Object VMware.Vim.EventAlarmExpression
#$expression1.EventType = "EventEx"
$sampleEvent2.EventType = $null
$sampleEvent2.eventTypeId = "SAMPLE11012"
$sampleEvent2.objectType = "ClusterComputeResource"
$sampleEvent2.status = "green"
# Cluster Event expression 3 - SAMPLE11013 ("red" state)
$sampleEvent3 = New-Object VMware.Vim.EventAlarmExpression
#$expression1.EventType = "EventEx"
$sampleEvent3.EventType = $null
$sampleEvent3.eventTypeId = "SAMPLE11013"
$sampleEvent3.objectType = "ClusterComputeResource"
$sampleEvent3.status = "red"
# Add cluster event expressions to alarm
$sampleAlarm.expression = New-Object VMware.Vim.OrAlarmExpression
$sampleAlarm.expression.expression += $sampleEvent1
$sampleAlarm.expression.expression += $sampleEvent2
$sampleAlarm.expression.expression += $sampleEvent3
$sampleAlarm.setting = New-Object VMware.Vim.AlarmSetting
$sampleAlarm.setting.reportingFrequency = $ReportFrequency
# Create alarms in vCenter for Root Folder
$alarmMgr.CreateAlarm($rootFolder,$sampleAlarm)
I'm afraid I'm not grasping what you are trying to.
You're creating a new Alarm, and some of the properties are based on environment variables.
The environment variables seem to be those that are provided when an Alarm has a script action.
You're not creating the new Alarm from within a script action I guess?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
This is event alarm, which will triggered by defined events from one main java program.
So I can only use environment variables to fetch the event description.
Can you check what environment variables are populated, and with what?
Do a dir env:VMWARE*
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
When I exported the events, it also shows similar like "event.SAMPLEVENT.fullFormat(SAMPLEVENT)" in spreadsheet, however the full message is correct in vCenter GUI....
User VSPHERE.LOCAL\ella@10.62.81.225 logged in as | Information | Sunday, August 19, 2018 5:36:37 PM | |
event.VXR23C013.fullFormat (VXR23C013) | Information | Sunday, August 19, 2018 5:36:37 PM |
Still not sure what the question actually is.
What is in the event export? Is that the "event.Vxxxxx.fullFormat(yyyyy)" entry?
And what do you see in the Web Client?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Actually just would like to find a way to fetch the custom event description ....
Ok, I suspect this might be what you are after.
What you see is the FullFormattedMessage property.
You can extract the description from there, or go for the EventTypeId property.
The following example might clarify (I hope)
$clusterName = 'MyCluster'
$event = New-Object VMware.Vim.EventEx
$arg = New-Object VMware.Vim.KeyAnyValue
$arg.Key = 'MyKey'
$arg.Value = Get-Date -Format 'yyyyMMdd HH:mm'
$event.Arguments += $arg
$event.UserName = "$($env:USERDOMAIN)\$($env:USERNAME)"
$event.EventTypeId = 'CustomMade' # <== This is the Custom Description value
$event.FullFormattedMessage = 'Fullformat - My custom event'
$event.Message = 'Message - My custom event'
$event.ObjectId = $cluster.ExtensionData.MoRef.Value
$event.ObjectName = $cluster.Name
$event.ObjectType = $cluster.ExtensionData.MoRef.Type
$event.Severity = [VMware.Vim.EventEventSeverity]::info
$eventMgr.PostEvent($event,$null)
Get-VIEvent -Entity $cluster -Start (Get-Date).AddMinutes(-2) |
where{$_ -is [VMware.Vim.EventEx]} |
Select @{N='Custom Description';E={$_.EventTypeId}},
@{N='Custom Description option 2';E={$_.FullFormattedMessage.Split('(')[1].TrimEnd(')')}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Above code works, in further, I have 3 custom eventTypeId for Trigger events, so how can I know what the exact eventTypeId is when any one of them is triggering an event-driven alarm ? (saying eventTypeId A/B/C to trigger alarm X by state changes, how to determine if A/B/C is the trigger event at a time ?) 2 mins may not work in this case now.
Current alarm email is always like this:
Subject:
[VMware vCenter - Alarm custom alarm name] event.VXRSAMPLE1.fullFormat (VXRSAMPLE1)
Body:
Target: Datacenters
Previous Status: Gray
New Status: Yellow
Alarm Definition:
([Event alarm expression: event.VXRSAMPLE1; Status = Yellow] OR [Event alarm expression: event.VXRSAMPLE2; Status = Green] OR [Event alarm expression: event.VXRSAMPLE3; Status = Red])
Event details:
event.VXRSAMPLE1.fullFormat (VXRSAMPLE1)
The exact custom event description is in Message field........ if I can not get the exact eventTypeId for each alarm, it's very difficult to get this Message field.
I have been doing some further testing with this type of multi-event alarm.
And I'm afraid it blew up my VCSA.
Tested on VCSA 6.5 and 6.7, and both had problem after I fired one of the events, with https://<VCSA-FQDN>/sdk unavailable.
Followed by an error "org.apache.http.conn.HttpHostConnectException: Connect to localhost:8085 [localhost/127.0.0.1] failed: Connection refused (Connection refused) Unexpected status code: 503" in the Web Client.
On which type of vCenter are you testing this?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
on VCSA6.5, sorry for confusing you. I think I can move a little bit forward....
$sampleTrigger.Action.Body = "{triggeringSummary}" // The event description can be found in {triggeringSummary}, but not sure how to split the message out.
The whole email Body is as below:
Event: event.SAMPLE001
Summary: event.SAMPLE001.fullFormat (SAMPLE001)
Date: 08/22/18 19:17:21
User name: VSPHERE.LOCAL\test
Arguments:
eventTypeId = SAMPLE001
message = host upgrade operation tested
severity = info
eventcode = SAMPLE001
component = Node
component_id = NODESN000001
SAMPLE001.fullFormat = SAMPLE001: host upgrade operation tested // Need this message, but even I do "{triggeringSummary}" .Split('=')[7] , it does not response anything
data = hostname001.externalsample.com
category = Status
I don't think you have access to these functions for a mail action.
Imho your best bet is to go for a script action, and send the email from there.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
If so, can I reuse your Get-VIEventPlus function and return only the newest event ($events[0]) and one more value of the collection index ?
And then I can compare with the index of other custom events, the smallest one should be the one I need...
The question is if I can get index here from eventCollector ? Thanks a lot, LucD : )
while($eventsBuffer){
$events += $eventsBuffer
$index ++ // ?
$eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
}
When you create the eventHistoryCollector, you can specify a filter.
In there you specify the EventTypeId, the maxCount and the Alarm.
That should get you the required event quite quickly.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference