From 80829b3b5afbd173adf0692be2144015c0508c91 Mon Sep 17 00:00:00 2001 From: Sven Rebhan <36194019+srebhan@users.noreply.github.com> Date: Tue, 27 Jul 2021 23:39:43 +0200 Subject: [PATCH] Fix attempt to connect to an empty list of servers. (#9503) --- plugins/inputs/nsq_consumer/nsq_consumer.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/nsq_consumer/nsq_consumer.go b/plugins/inputs/nsq_consumer/nsq_consumer.go index 718a2ed3e321c..34360472ab0b9 100644 --- a/plugins/inputs/nsq_consumer/nsq_consumer.go +++ b/plugins/inputs/nsq_consumer/nsq_consumer.go @@ -2,6 +2,7 @@ package nsq_consumer import ( "context" + "fmt" "sync" "github.com/influxdata/telegraf" @@ -134,15 +135,28 @@ func (n *NSQConsumer) Start(ac telegraf.Accumulator) error { return nil })) + // For backward compatibility + if n.Server != "" { + n.Nsqd = append(n.Nsqd, n.Server) + } + + // Check if we have anything to connect to + if len(n.Nsqlookupd) == 0 && len(n.Nsqd) == 0 { + return fmt.Errorf("either 'nsqd' or 'nsqlookupd' needs to be specified") + } + if len(n.Nsqlookupd) > 0 { err := n.consumer.ConnectToNSQLookupds(n.Nsqlookupd) if err != nil && err != nsq.ErrAlreadyConnected { return err } } - err := n.consumer.ConnectToNSQDs(append(n.Nsqd, n.Server)) - if err != nil && err != nsq.ErrAlreadyConnected { - return err + + if len(n.Nsqd) > 0 { + err := n.consumer.ConnectToNSQDs(n.Nsqd) + if err != nil && err != nsq.ErrAlreadyConnected { + return err + } } n.wg.Add(1)