fix(inputs.mqtt_consumer): Client logs via option (#13663)
This commit is contained in:
parent
928ef00ca2
commit
80094507e4
|
|
@ -100,6 +100,12 @@ to use them.
|
||||||
## Use TLS but skip chain & host verification
|
## Use TLS but skip chain & host verification
|
||||||
# insecure_skip_verify = false
|
# insecure_skip_verify = false
|
||||||
|
|
||||||
|
## Client trace messages
|
||||||
|
## When set to true, and debug mode enabled in the agent settings, the MQTT
|
||||||
|
## client's messages are included in telegraf logs. These messages are very
|
||||||
|
## noisey, but essential for debugging issues.
|
||||||
|
# client_trace = false
|
||||||
|
|
||||||
## Data format to consume.
|
## Data format to consume.
|
||||||
## Each data format has its own unique set of configuration options, read
|
## Each data format has its own unique set of configuration options, read
|
||||||
## more about them here:
|
## more about them here:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package mqtt_consumer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/influxdata/telegraf"
|
||||||
|
)
|
||||||
|
|
||||||
|
type mqttLogger struct {
|
||||||
|
telegraf.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l mqttLogger) Printf(fmt string, args ...interface{}) {
|
||||||
|
l.Logger.Debugf(fmt, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l mqttLogger) Println(args ...interface{}) {
|
||||||
|
l.Logger.Debug(args...)
|
||||||
|
}
|
||||||
|
|
@ -70,6 +70,7 @@ type MQTTConsumer struct {
|
||||||
Password config.Secret `toml:"password"`
|
Password config.Secret `toml:"password"`
|
||||||
QoS int `toml:"qos"`
|
QoS int `toml:"qos"`
|
||||||
ConnectionTimeout config.Duration `toml:"connection_timeout"`
|
ConnectionTimeout config.Duration `toml:"connection_timeout"`
|
||||||
|
ClientTrace bool `toml:"client_trace"`
|
||||||
MaxUndeliveredMessages int `toml:"max_undelivered_messages"`
|
MaxUndeliveredMessages int `toml:"max_undelivered_messages"`
|
||||||
parser telegraf.Parser
|
parser telegraf.Parser
|
||||||
|
|
||||||
|
|
@ -104,6 +105,14 @@ func (m *MQTTConsumer) SetParser(parser telegraf.Parser) {
|
||||||
m.parser = parser
|
m.parser = parser
|
||||||
}
|
}
|
||||||
func (m *MQTTConsumer) Init() error {
|
func (m *MQTTConsumer) Init() error {
|
||||||
|
if m.ClientTrace {
|
||||||
|
log := &mqttLogger{m.Log}
|
||||||
|
mqtt.ERROR = log
|
||||||
|
mqtt.CRITICAL = log
|
||||||
|
mqtt.WARN = log
|
||||||
|
mqtt.DEBUG = log
|
||||||
|
}
|
||||||
|
|
||||||
m.state = Disconnected
|
m.state = Disconnected
|
||||||
if m.PersistentSession && m.ClientID == "" {
|
if m.PersistentSession && m.ClientID == "" {
|
||||||
return errors.New("persistent_session requires client_id")
|
return errors.New("persistent_session requires client_id")
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,12 @@
|
||||||
## Use TLS but skip chain & host verification
|
## Use TLS but skip chain & host verification
|
||||||
# insecure_skip_verify = false
|
# insecure_skip_verify = false
|
||||||
|
|
||||||
|
## Client trace messages
|
||||||
|
## When set to true, and debug mode enabled in the agent settings, the MQTT
|
||||||
|
## client's messages are included in telegraf logs. These messages are very
|
||||||
|
## noisey, but essential for debugging issues.
|
||||||
|
# client_trace = false
|
||||||
|
|
||||||
## Data format to consume.
|
## Data format to consume.
|
||||||
## Each data format has its own unique set of configuration options, read
|
## Each data format has its own unique set of configuration options, read
|
||||||
## more about them here:
|
## more about them here:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue