Skip to content

Commit

Permalink
Enable setting a clientID for MQTT Output
Browse files Browse the repository at this point in the history
  • Loading branch information
zan-xhipe authored and Nick White committed Jan 31, 2017
1 parent 41bf3b9 commit 52f0363
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ in their config file.
- [#1937](https://github.com/influxdata/telegraf/pull/1937): HAProxy session limit metric.
- [#2068](https://github.com/influxdata/telegraf/issues/2068): Accept strings for StatsD sets.
- [#1893](https://github.com/influxdata/telegraf/issues/1893): Change StatsD default "reset" behavior.
- [#2079](https://github.com/influxdata/telegraf/pull/2079): Enable setting ClientID in MQTT output.

### Bugfixes

Expand Down
12 changes: 10 additions & 2 deletions plugins/outputs/mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ var sampleConfig = `
# username = "telegraf"
# password = "metricsmetricsmetricsmetrics"
## client ID, if not set a random ID is generated
# client_id = ""
## Optional SSL Config
# ssl_ca = "/etc/telegraf/ca.pem"
# ssl_cert = "/etc/telegraf/cert.pem"
Expand All @@ -46,7 +49,8 @@ type MQTT struct {
Database string
Timeout internal.Duration
TopicPrefix string
QoS int `toml:"qos"`
QoS int `toml:"qos"`
ClientID string `toml:"client_id"`

// Path to CA file
SSLCA string `toml:"ssl_ca"`
Expand Down Expand Up @@ -155,7 +159,11 @@ func (m *MQTT) publish(topic string, body []byte) error {
func (m *MQTT) createOpts() (*paho.ClientOptions, error) {
opts := paho.NewClientOptions()

opts.SetClientID("Telegraf-Output-" + internal.RandomString(5))
if m.ClientID != "" {
opts.SetClientID(m.ClientID)
} else {
opts.SetClientID("Telegraf-Output-" + internal.RandomString(5))
}

tlsCfg, err := internal.GetTLSConfig(
m.SSLCert, m.SSLKey, m.SSLCA, m.InsecureSkipVerify)
Expand Down

0 comments on commit 52f0363

Please sign in to comment.