From cd129feb094d75529d6da956ff75af42cd507c13 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Wed, 24 May 2023 12:30:28 +1000 Subject: [PATCH] try a different way of identifying previous host for VM --- main.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 8775089..15728ca 100644 --- a/main.go +++ b/main.go @@ -334,15 +334,26 @@ func main() { log.Printf("%d [%s] VM: %s, Host: %s, Message: %s\n", h.Key, h.CreatedTime.In(location).Format(time.ANSIC), h.Vm.Name, h.Host.Name, h.FullFormattedMessage) } - disconnectedHost := disconnectedEvents[0] - log.Printf("First disconnected message indicates that VM was running on host '%s' previously\n", disconnectedHost.Host.Name) - - // Capture all the failure events for this host - for _, hostEvent := range hostFailures { - if hostEvent.Host.Name == disconnectedHost.Host.Name { - possibleHosts = append(possibleHosts, hostEvent) + // Search for any disconnected messages prior to restart time + log.Printf("Filtering VmDisconnectedEvent list based on VM restart time %s\n", vmRestartTime) + for _, e := range disconnectedEvents { + if e.CreatedTime.In(location).Before(vmRestartTime) || e.CreatedTime.In(location).Equal(vmRestartTime) { + log.Printf("VM disconnected event on host %s at time %s is applicable\n", e.Host.Name, e.CreatedTime.In(location)) + possibleHosts = append(possibleHosts, e) } } + + /* + disconnectedHost := disconnectedEvents[0] + log.Printf("First disconnected message indicates that VM was running on host '%s' previously\n", disconnectedHost.Host.Name) + + // Capture all the failure events for this host + for _, hostEvent := range hostFailures { + if hostEvent.Host.Name == disconnectedHost.Host.Name { + possibleHosts = append(possibleHosts, hostEvent) + } + } + */ } else { log.Printf("could not determine previous host for this VM. Filtering all host failures for events prior to VM restart time '%s'\n", vmRestartTime)