search all vm disconnected events
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
19
main.go
19
main.go
@@ -315,10 +315,20 @@ func main() {
|
||||
return hostFailures[i].CreatedTime.Before(hostFailures[j].CreatedTime)
|
||||
})
|
||||
|
||||
allVmDisconnectedEvents := getEvents([]string{"VmDisconnectedEvent"}, []types.ManagedObjectReference{}, *begin, *end)
|
||||
log.Printf("Retrieved '%d' VmDisconnectedEvent events from '%s' to '%s'.\n", len(allVmDisconnectedEvents), begin.String(), end.String())
|
||||
if len(allVmDisconnectedEvents) > 0 {
|
||||
// Sort the disconnected events by time
|
||||
sort.Slice(allVmDisconnectedEvents[:], func(i, j int) bool {
|
||||
return allVmDisconnectedEvents[i].CreatedTime.Before(allVmDisconnectedEvents[j].CreatedTime)
|
||||
})
|
||||
}
|
||||
|
||||
for i := range vmFailures {
|
||||
var outageStart, restartTime time.Time
|
||||
var failedHost string
|
||||
var possibleHosts []types.Event
|
||||
var vmDisconnectedEvents []types.Event
|
||||
event := vmFailures[i]
|
||||
vmRestartTime := event.CreatedTime.In(location)
|
||||
|
||||
@@ -335,11 +345,18 @@ func main() {
|
||||
// If we couldn't find the vm then skip this event
|
||||
if len(vm.ExtensibleManagedObject.Self.Value) == 0 {
|
||||
log.Printf("No VM matching string '%s' found in cluster '%s'\n", event.Vm.Name, cluster.Reference())
|
||||
for _, e := range allVmDisconnectedEvents {
|
||||
if e.Vm.Name == event.Vm.Name {
|
||||
log.Printf("Adding VM disconnected event on host %s at time %s\n", e.Host.Name, e.CreatedTime.In(location))
|
||||
vmDisconnectedEvents = append(vmDisconnectedEvents, e)
|
||||
}
|
||||
}
|
||||
log.Printf("Filtered '%d' VmDisconnectedEvent events.\n", len(vmDisconnectedEvents))
|
||||
continue
|
||||
}
|
||||
|
||||
// Use VmDisconnectedEvent to see which host this VM was on
|
||||
vmDisconnectedEvents := getEvents([]string{"VmDisconnectedEvent"}, []types.ManagedObjectReference{vm.Reference()}, *begin, *end)
|
||||
vmDisconnectedEvents = getEvents([]string{"VmDisconnectedEvent"}, []types.ManagedObjectReference{vm.Reference()}, *begin, *end)
|
||||
log.Printf("Retrieved '%d' VmDisconnectedEvent events.\n", len(vmDisconnectedEvents))
|
||||
|
||||
// Determine which host the VM was previoulsy running on
|
||||
|
Reference in New Issue
Block a user