From fd23121a7c27c7f3717dbb920e8dfc07d0051d02 Mon Sep 17 00:00:00 2001 From: Nathan Coad Date: Mon, 18 Mar 2024 10:28:33 +1100 Subject: [PATCH] filter ha unreachable to hosts that actually failed --- main.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 0083997..5cda579 100644 --- a/main.go +++ b/main.go @@ -277,8 +277,23 @@ func main() { for _, h := range haStatusChanges { unreachableMessage := strings.Contains(strings.ToLower(h.FullFormattedMessage), "changed to unreachable") if unreachableMessage { - haUnreachableEvents = append(haUnreachableEvents, h) - log.Printf("Host %s unreachable HA status event at %s : '%s'\n", h.Host.Name, h.CreatedTime.In(location).Format(time.ANSIC), h.FullFormattedMessage) + + // make sure this host was in the host failures list + hostFound := false + for _, f := range hostFailures { + if h.Host.Name == f.Host.Name { + // got it + hostFound = true + break + } + } + + if hostFound { + haUnreachableEvents = append(haUnreachableEvents, h) + log.Printf("Host %s unreachable HA status event at %s : '%s'\n", h.Host.Name, h.CreatedTime.In(location).Format(time.ANSIC), h.FullFormattedMessage) + } else { + log.Printf("Host %s was not found in the list of hostfailure events, skipping this host\n", h.Host.Name) + } } }