Fix format of connection_timeout in mqtt_consumer (#3286)

(cherry picked from commit 3d62e045af)
This commit is contained in:
Daniel Nelson 2017-09-29 15:58:38 -07:00 committed by Daniel Nelson
parent f10d5b43c4
commit cfac750469
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
2 changed files with 8 additions and 3 deletions

View File

@ -14,7 +14,7 @@ The plugin expects messages in the
## MQTT QoS, must be 0, 1, or 2 ## MQTT QoS, must be 0, 1, or 2
qos = 0 qos = 0
## Connection timeout for initial connection in seconds ## Connection timeout for initial connection in seconds
connection_timeout = 30 connection_timeout = "30s"
## Topics to subscribe to ## Topics to subscribe to
topics = [ topics = [

View File

@ -15,6 +15,9 @@ import (
"github.com/eclipse/paho.mqtt.golang" "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 { type MQTTConsumer struct {
Servers []string Servers []string
Topics []string Topics []string
@ -57,7 +60,7 @@ var sampleConfig = `
## MQTT QoS, must be 0, 1, or 2 ## MQTT QoS, must be 0, 1, or 2
qos = 0 qos = 0
## Connection timeout for initial connection in seconds ## Connection timeout for initial connection in seconds
connection_timeout = 30 connection_timeout = "30s"
## Topics to subscribe to ## Topics to subscribe to
topics = [ topics = [
@ -270,6 +273,8 @@ func (m *MQTTConsumer) createOpts() (*mqtt.ClientOptions, error) {
func init() { func init() {
inputs.Add("mqtt_consumer", func() telegraf.Input { inputs.Add("mqtt_consumer", func() telegraf.Input {
return &MQTTConsumer{} return &MQTTConsumer{
ConnectionTimeout: defaultConnectionTimeout,
}
}) })
} }