From 915eea4def25340830c33dd61b341d08199b5e7a Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Mon, 9 Feb 2026 13:45:30 +0100 Subject: [PATCH 1/4] fix typo --- pkg/nagflux/nagflux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/nagflux/nagflux.go b/pkg/nagflux/nagflux.go index e35362e..5c4c4d8 100644 --- a/pkg/nagflux/nagflux.go +++ b/pkg/nagflux/nagflux.go @@ -336,6 +336,6 @@ func checkActiveModuleCount(stoppables []Stoppable) { } } if activeItemCount == 0 { - log.Fatalf("No active watcher/spooler/listeneder were constructed after processing the config file, enable at least an item.") + log.Fatalf("No active watcher/spooler/listener were constructed after processing the config file, enable at least an item.") } } From 7d7d3b7cf948bfe7b2ea86620075c4b5f517bc30 Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Mon, 9 Feb 2026 14:14:36 +0100 Subject: [PATCH 2/4] - stop adding items to the stoppables[] array if they are nil - properly compare if the interface itself and its value inside is not nill before calling Stop() - add nil checks on the Stop() functions to see if the receiver pointer value is nil --- .../collector/livestatus/CacheBuilder.go | 5 +++++ pkg/nagflux/collector/livestatus/Collector.go | 5 +++++ .../collector/nagflux/nagfluxFileCollector.go | 5 +++++ .../spoolfile/nagiosSpoolfileCollector.go | 5 +++++ pkg/nagflux/nagflux.go | 20 ++++++++++++++++--- pkg/nagflux/statistics/prometheus.go | 1 + pkg/nagflux/target/elasticsearch/Worker.go | 5 +++++ pkg/nagflux/target/influx/Worker.go | 5 +++++ 8 files changed, 48 insertions(+), 3 deletions(-) diff --git a/pkg/nagflux/collector/livestatus/CacheBuilder.go b/pkg/nagflux/collector/livestatus/CacheBuilder.go index cc412f5..6362096 100644 --- a/pkg/nagflux/collector/livestatus/CacheBuilder.go +++ b/pkg/nagflux/collector/livestatus/CacheBuilder.go @@ -58,6 +58,11 @@ func NewLivestatusCacheBuilder(livestatusConnector *Connector) *CacheBuilder { // Stop signals the cache to stop. func (builder *CacheBuilder) Stop() { + if builder == nil { + log := logging.GetLogger() + log.Warnf("cannot stop CacheBuilder, as it is nil") + return + } builder.quit <- true <-builder.quit builder.log.Debug("LivestatusCacheBuilder stopped") diff --git a/pkg/nagflux/collector/livestatus/Collector.go b/pkg/nagflux/collector/livestatus/Collector.go index 0411e60..16953a0 100644 --- a/pkg/nagflux/collector/livestatus/Collector.go +++ b/pkg/nagflux/collector/livestatus/Collector.go @@ -134,6 +134,11 @@ func NewLivestatusCollector(jobs collector.ResultQueues, livestatusConnector *Co // Stop signals the collector to stop. func (live *Collector) Stop() { + if live == nil { + log := logging.GetLogger() + log.Warnf("cannot stop Collector, as it is nil") + return + } live.quit <- true <-live.quit live.log.Debug("LivestatusCollector stopped") diff --git a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go b/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go index 64c2924..75d512c 100644 --- a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go +++ b/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go @@ -48,6 +48,11 @@ func NewNagfluxFileCollector(results collector.ResultQueues, folder string, fiel // Stop stops the Collector. func (nfc *FileCollector) Stop() { + if nfc == nil { + log := logging.GetLogger() + log.Warnf("cannot stop Nagflux File Collector, as it is nil") + return + } nfc.quit <- true <-nfc.quit nfc.log.Debug("NagfluxFileCollector stoped") diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go index a16dd5d..9a0a095 100644 --- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go +++ b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go @@ -51,6 +51,11 @@ func NagiosSpoolfileCollectorFactory(spoolDirectory string, workerAmount int, re // Stop stops his workers and itself. func (s *NagiosSpoolfileCollector) Stop() { + if s == nil { + log := logging.GetLogger() + log.Warnf("cannot stop Nagios File Collector, as it is nil") + return + } s.quit <- true <-s.quit for _, worker := range s.workers { diff --git a/pkg/nagflux/nagflux.go b/pkg/nagflux/nagflux.go index 5c4c4d8..5d48c77 100644 --- a/pkg/nagflux/nagflux.go +++ b/pkg/nagflux/nagflux.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "os/signal" + "reflect" "runtime" "syscall" "time" @@ -286,7 +287,18 @@ For further informations / bugs reports: https://github.com/ConSol-Monitoring/na switch <-signalChannel { case syscall.SIGINT, syscall.SIGTERM: log.Warn("Got Interrupted") - stoppables = append(stoppables, []Stoppable{livestatusCollector, livestatusCache, nagiosCollector, nagfluxCollector}...) + if livestatusCollector != nil { + stoppables = append(stoppables, livestatusCollector) + } + if livestatusCache != nil { + stoppables = append(stoppables, livestatusCache) + } + if nagiosCollector != nil { + stoppables = append(stoppables, nagiosCollector) + } + if nagfluxCollector != nil { + stoppables = append(stoppables, nagfluxCollector) + } cleanUp(stoppables, resultQueues) quit <- true return @@ -317,7 +329,9 @@ func waitForDumpfileCollector(dump *nagflux.DumpfileCollector) { func cleanUp(itemsToStop []Stoppable, resultQueues collector.ResultQueues) { log.Info("Cleaning up...") for i := len(itemsToStop) - 1; i >= 0; i-- { - if itemsToStop[i] != nil { + // the type is Stoppable , which is an interface + // interface nil checks only work if both type and value are nil + if itemsToStop[i] != nil && !reflect.ValueOf(itemsToStop[i]).IsNil() { itemsToStop[i].Stop() } } @@ -331,7 +345,7 @@ func cleanUp(itemsToStop []Stoppable, resultQueues collector.ResultQueues) { func checkActiveModuleCount(stoppables []Stoppable) { activeItemCount := 0 for _, stoppable := range stoppables { - if stoppable != nil { + if stoppable != nil && !reflect.ValueOf(stoppable).IsNil() { activeItemCount++ } } diff --git a/pkg/nagflux/statistics/prometheus.go b/pkg/nagflux/statistics/prometheus.go index 9a3f62e..25f8acd 100644 --- a/pkg/nagflux/statistics/prometheus.go +++ b/pkg/nagflux/statistics/prometheus.go @@ -141,6 +141,7 @@ func (s PrometheusServer) WatchResultQueueLength(channels collector.ResultQueues } // Stop stops the Server +// why is this not using pointer receiver ? func (s PrometheusServer) Stop() { prometheusListener.Close() } diff --git a/pkg/nagflux/target/elasticsearch/Worker.go b/pkg/nagflux/target/elasticsearch/Worker.go index 6d95916..d9f8eff 100644 --- a/pkg/nagflux/target/elasticsearch/Worker.go +++ b/pkg/nagflux/target/elasticsearch/Worker.go @@ -65,6 +65,11 @@ func WorkerGenerator(jobs chan collector.Printable, connection, index, dumpFile, // Stop stops the worker func (worker *Worker) Stop() { + if worker == nil { + log := logging.GetLogger() + log.Warnf("cannot stop Worker, as it is nil") + return + } worker.quitInternal <- true worker.quit <- true <-worker.quit diff --git a/pkg/nagflux/target/influx/Worker.go b/pkg/nagflux/target/influx/Worker.go index 62daf8f..a3a413a 100644 --- a/pkg/nagflux/target/influx/Worker.go +++ b/pkg/nagflux/target/influx/Worker.go @@ -79,6 +79,11 @@ func WorkerGenerator(jobs chan collector.Printable, connection, dumpFile, versio // Stop stops the worker func (worker *Worker) Stop() { + if worker == nil { + log := logging.GetLogger() + log.Warnf("cannot stop Worker, as it is nil") + return + } worker.quitInternal <- true worker.quit <- true <-worker.quit From b44b6c41a3f6e700c73a8a2c01301b77c79eccd5 Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Mon, 9 Feb 2026 14:20:38 +0100 Subject: [PATCH 3/4] linter fix --- pkg/nagflux/nagflux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/nagflux/nagflux.go b/pkg/nagflux/nagflux.go index 5d48c77..af8d59c 100644 --- a/pkg/nagflux/nagflux.go +++ b/pkg/nagflux/nagflux.go @@ -330,7 +330,7 @@ func cleanUp(itemsToStop []Stoppable, resultQueues collector.ResultQueues) { log.Info("Cleaning up...") for i := len(itemsToStop) - 1; i >= 0; i-- { // the type is Stoppable , which is an interface - // interface nil checks only work if both type and value are nil + // with golang, interface nil checks only work if both type and value are nil if itemsToStop[i] != nil && !reflect.ValueOf(itemsToStop[i]).IsNil() { itemsToStop[i].Stop() } From d9798005199716ac9284e58ba91800e8605464ab Mon Sep 17 00:00:00 2001 From: Ahmet Oeztuerk Date: Tue, 10 Feb 2026 10:13:08 +0100 Subject: [PATCH 4/4] revert unwanted changes - remove nil checks for receivers - remove nil checks while stopping and counting stoppables --- pkg/nagflux/collector/livestatus/CacheBuilder.go | 5 ----- pkg/nagflux/collector/livestatus/Collector.go | 5 ----- .../collector/nagflux/nagfluxFileCollector.go | 5 ----- .../spoolfile/nagiosSpoolfileCollector.go | 5 ----- pkg/nagflux/nagflux.go | 14 ++------------ pkg/nagflux/statistics/prometheus.go | 1 - pkg/nagflux/target/elasticsearch/Worker.go | 5 ----- pkg/nagflux/target/influx/Worker.go | 5 ----- 8 files changed, 2 insertions(+), 43 deletions(-) diff --git a/pkg/nagflux/collector/livestatus/CacheBuilder.go b/pkg/nagflux/collector/livestatus/CacheBuilder.go index 6362096..cc412f5 100644 --- a/pkg/nagflux/collector/livestatus/CacheBuilder.go +++ b/pkg/nagflux/collector/livestatus/CacheBuilder.go @@ -58,11 +58,6 @@ func NewLivestatusCacheBuilder(livestatusConnector *Connector) *CacheBuilder { // Stop signals the cache to stop. func (builder *CacheBuilder) Stop() { - if builder == nil { - log := logging.GetLogger() - log.Warnf("cannot stop CacheBuilder, as it is nil") - return - } builder.quit <- true <-builder.quit builder.log.Debug("LivestatusCacheBuilder stopped") diff --git a/pkg/nagflux/collector/livestatus/Collector.go b/pkg/nagflux/collector/livestatus/Collector.go index 16953a0..0411e60 100644 --- a/pkg/nagflux/collector/livestatus/Collector.go +++ b/pkg/nagflux/collector/livestatus/Collector.go @@ -134,11 +134,6 @@ func NewLivestatusCollector(jobs collector.ResultQueues, livestatusConnector *Co // Stop signals the collector to stop. func (live *Collector) Stop() { - if live == nil { - log := logging.GetLogger() - log.Warnf("cannot stop Collector, as it is nil") - return - } live.quit <- true <-live.quit live.log.Debug("LivestatusCollector stopped") diff --git a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go b/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go index 75d512c..64c2924 100644 --- a/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go +++ b/pkg/nagflux/collector/nagflux/nagfluxFileCollector.go @@ -48,11 +48,6 @@ func NewNagfluxFileCollector(results collector.ResultQueues, folder string, fiel // Stop stops the Collector. func (nfc *FileCollector) Stop() { - if nfc == nil { - log := logging.GetLogger() - log.Warnf("cannot stop Nagflux File Collector, as it is nil") - return - } nfc.quit <- true <-nfc.quit nfc.log.Debug("NagfluxFileCollector stoped") diff --git a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go index 9a0a095..a16dd5d 100644 --- a/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go +++ b/pkg/nagflux/collector/spoolfile/nagiosSpoolfileCollector.go @@ -51,11 +51,6 @@ func NagiosSpoolfileCollectorFactory(spoolDirectory string, workerAmount int, re // Stop stops his workers and itself. func (s *NagiosSpoolfileCollector) Stop() { - if s == nil { - log := logging.GetLogger() - log.Warnf("cannot stop Nagios File Collector, as it is nil") - return - } s.quit <- true <-s.quit for _, worker := range s.workers { diff --git a/pkg/nagflux/nagflux.go b/pkg/nagflux/nagflux.go index af8d59c..2f66ac2 100644 --- a/pkg/nagflux/nagflux.go +++ b/pkg/nagflux/nagflux.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "os/signal" - "reflect" "runtime" "syscall" "time" @@ -329,11 +328,7 @@ func waitForDumpfileCollector(dump *nagflux.DumpfileCollector) { func cleanUp(itemsToStop []Stoppable, resultQueues collector.ResultQueues) { log.Info("Cleaning up...") for i := len(itemsToStop) - 1; i >= 0; i-- { - // the type is Stoppable , which is an interface - // with golang, interface nil checks only work if both type and value are nil - if itemsToStop[i] != nil && !reflect.ValueOf(itemsToStop[i]).IsNil() { - itemsToStop[i].Stop() - } + itemsToStop[i].Stop() } for _, q := range resultQueues { log.Debugf("Remaining queries %d", len(q)) @@ -343,12 +338,7 @@ func cleanUp(itemsToStop []Stoppable, resultQueues collector.ResultQueues) { // Depending on the configuration, we might not have added any active watchers. // Exit the program if that is the case func checkActiveModuleCount(stoppables []Stoppable) { - activeItemCount := 0 - for _, stoppable := range stoppables { - if stoppable != nil && !reflect.ValueOf(stoppable).IsNil() { - activeItemCount++ - } - } + activeItemCount := len(stoppables) if activeItemCount == 0 { log.Fatalf("No active watcher/spooler/listener were constructed after processing the config file, enable at least an item.") } diff --git a/pkg/nagflux/statistics/prometheus.go b/pkg/nagflux/statistics/prometheus.go index 25f8acd..9a3f62e 100644 --- a/pkg/nagflux/statistics/prometheus.go +++ b/pkg/nagflux/statistics/prometheus.go @@ -141,7 +141,6 @@ func (s PrometheusServer) WatchResultQueueLength(channels collector.ResultQueues } // Stop stops the Server -// why is this not using pointer receiver ? func (s PrometheusServer) Stop() { prometheusListener.Close() } diff --git a/pkg/nagflux/target/elasticsearch/Worker.go b/pkg/nagflux/target/elasticsearch/Worker.go index d9f8eff..6d95916 100644 --- a/pkg/nagflux/target/elasticsearch/Worker.go +++ b/pkg/nagflux/target/elasticsearch/Worker.go @@ -65,11 +65,6 @@ func WorkerGenerator(jobs chan collector.Printable, connection, index, dumpFile, // Stop stops the worker func (worker *Worker) Stop() { - if worker == nil { - log := logging.GetLogger() - log.Warnf("cannot stop Worker, as it is nil") - return - } worker.quitInternal <- true worker.quit <- true <-worker.quit diff --git a/pkg/nagflux/target/influx/Worker.go b/pkg/nagflux/target/influx/Worker.go index a3a413a..62daf8f 100644 --- a/pkg/nagflux/target/influx/Worker.go +++ b/pkg/nagflux/target/influx/Worker.go @@ -79,11 +79,6 @@ func WorkerGenerator(jobs chan collector.Printable, connection, dumpFile, versio // Stop stops the worker func (worker *Worker) Stop() { - if worker == nil { - log := logging.GetLogger() - log.Warnf("cannot stop Worker, as it is nil") - return - } worker.quitInternal <- true worker.quit <- true <-worker.quit