From a5a585427624a93c9805a6ec4e8ed30b2805a36a Mon Sep 17 00:00:00 2001 From: Laurent Ulrich Date: Fri, 15 Sep 2023 23:35:16 +0200 Subject: [PATCH] Tables are now updated only if status of host changers --- hostchecker.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hostchecker.go b/hostchecker.go index 3ccbf5a..ff1a244 100644 --- a/hostchecker.go +++ b/hostchecker.go @@ -108,9 +108,11 @@ func main() { func checkGroup(name string, group Group, waitGroup *sync.WaitGroup, stopChannel chan bool) { channels := make(map[string]chan int) + statusPerHost := make(map[string]int) for _, host := range group.Hosts { channel := make(chan int, 1) channels[host] = channel + statusPerHost[host] = -1 waitGroup.Add(1) go checkHost(channels[host], name, host, group.Check, waitGroup, stopChannel) } @@ -133,9 +135,13 @@ func checkGroup(name string, group Group, waitGroup *sync.WaitGroup, stopChannel break case status := <-channel: if verbose > 1 { + log.Println("Status for ", host, "was", statusPerHost[host], "in group", name) log.Println("Status for ", host, "is", status, "in group", name) } - updateTables(host, status, group.Tables) + if statusPerHost[host] == -1 || statusPerHost[host] != status { + statusPerHost[host] = status + updateTables(host, status, group.Tables) + } default: time.Sleep(100 * time.Millisecond) }