Skip to content

Commit

Permalink
Fix format of connection_timeout in mqtt_consumer (#3286)
Browse files Browse the repository at this point in the history
(cherry picked from commit 3d62e04)
  • Loading branch information
danielnelson committed Sep 29, 2017
1 parent f10d5b4 commit cfac750
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion plugins/inputs/mqtt_consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
9 changes: 7 additions & 2 deletions plugins/inputs/mqtt_consumer/mqtt_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
}
})
}

0 comments on commit cfac750

Please sign in to comment.