fix(inputs.mqtt_consumer): Client logs via option (#13663)

This commit is contained in:
Joshua Powers 2023-07-26 10:51:03 -06:00 committed by GitHub
parent 928ef00ca2
commit 80094507e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View File

@ -100,6 +100,12 @@ to use them.
## Use TLS but skip chain & host verification
# 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.
## Each data format has its own unique set of configuration options, read
## more about them here:

View File

@ -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...)
}

View File

@ -70,6 +70,7 @@ type MQTTConsumer struct {
Password config.Secret `toml:"password"`
QoS int `toml:"qos"`
ConnectionTimeout config.Duration `toml:"connection_timeout"`
ClientTrace bool `toml:"client_trace"`
MaxUndeliveredMessages int `toml:"max_undelivered_messages"`
parser telegraf.Parser
@ -104,6 +105,14 @@ func (m *MQTTConsumer) SetParser(parser telegraf.Parser) {
m.parser = parser
}
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
if m.PersistentSession && m.ClientID == "" {
return errors.New("persistent_session requires client_id")

View File

@ -63,6 +63,12 @@
## Use TLS but skip chain & host verification
# 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.
## Each data format has its own unique set of configuration options, read
## more about them here: