From e4448239e23b132a2de5be1b24a395ca0d140d7c Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Fri, 26 May 2023 11:49:33 +1000 Subject: [PATCH] improve search --- main.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/main.go b/main.go index e26b478..4eec519 100644 --- a/main.go +++ b/main.go @@ -304,6 +304,26 @@ func main() { possibleHosts = append(possibleHosts, e) } } + log.Printf("After filtering there are %d events\n", len(possibleHosts)) + + // Its possible that the VM disconnected messages dont' relate to the host HA events that we found + // If that is the case then we fall back to the most recent host failure message in our list + if len(possibleHosts) == 0 { + log.Printf("No corresponding VM disconnected messages, falling back to any applicable host that experienced a HA event.\n") + // Search for host failures + for _, hostEvent := range hostFailures { + if hostEvent.CreatedTime.In(location).Before(vmRestartTime) || hostEvent.CreatedTime.In(location).Equal(vmRestartTime) { + possibleHosts = append(possibleHosts, hostEvent) + } + } + + log.Printf("Based on event times there were %d possible hosts this VM was running on\n", len(possibleHosts)) + + if len(possibleHosts) == 0 { + log.Printf("No ESXi outage events happened before VM %s restart event at %s, skipping this event.\n", event.Vm.Name, vmRestartTime) + continue + } + } /* disconnectedHost := disconnectedEvents[0]