From cfac750469a1bf6bf76220b156c3eb70a27270e6 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Fri, 29 Sep 2017 15:58:38 -0700 Subject: [PATCH] Fix format of connection_timeout in mqtt_consumer (#3286) (cherry picked from commit 3d62e045affb58ff57b09c6a47872824de1fdc87) --- plugins/inputs/mqtt_consumer/README.md | 2 +- plugins/inputs/mqtt_consumer/mqtt_consumer.go | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/mqtt_consumer/README.md b/plugins/inputs/mqtt_consumer/README.md index c61545e8e..52990ef76 100644 --- a/plugins/inputs/mqtt_consumer/README.md +++ b/plugins/inputs/mqtt_consumer/README.md @@ -14,7 +14,7 @@ The plugin expects messages in the ## MQTT QoS, must be 0, 1, or 2 qos = 0 ## Connection timeout for initial connection in seconds - connection_timeout = 30 + connection_timeout = "30s" ## Topics to subscribe to topics = [ diff --git a/plugins/inputs/mqtt_consumer/mqtt_consumer.go b/plugins/inputs/mqtt_consumer/mqtt_consumer.go index 3cd98baea..e0d668879 100644 --- a/plugins/inputs/mqtt_consumer/mqtt_consumer.go +++ b/plugins/inputs/mqtt_consumer/mqtt_consumer.go @@ -15,6 +15,9 @@ import ( "github.com/eclipse/paho.mqtt.golang" ) +// 30 Seconds is the default used by paho.mqtt.golang +var defaultConnectionTimeout = internal.Duration{Duration: 30 * time.Second} + type MQTTConsumer struct { Servers []string Topics []string @@ -57,7 +60,7 @@ var sampleConfig = ` ## MQTT QoS, must be 0, 1, or 2 qos = 0 ## Connection timeout for initial connection in seconds - connection_timeout = 30 + connection_timeout = "30s" ## Topics to subscribe to topics = [ @@ -270,6 +273,8 @@ func (m *MQTTConsumer) createOpts() (*mqtt.ClientOptions, error) { func init() { inputs.Add("mqtt_consumer", func() telegraf.Input { - return &MQTTConsumer{} + return &MQTTConsumer{ + ConnectionTimeout: defaultConnectionTimeout, + } }) }