diff --git a/config.yaml.dist b/config.yaml.dist index f2154dc..66fd961 100644 --- a/config.yaml.dist +++ b/config.yaml.dist @@ -10,6 +10,7 @@ probes: # topic: internal/monitoring/mqtt-broker-ssl # client_prefix: mqtt_blackbox_exporter.mqtt-broker-ssl # messages: 10 +# message_payload: "Could be any string, even with double quotes within, just \"escape the quotes\". Furthermore if you include %d it'll use the increment of the configured number of \"messages\", e.g. 0...10" # interval: 30s - name: mqtt-broker-ssl diff --git a/main.go b/main.go index 1989df3..df14535 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,7 @@ type probeConfig struct { InsecureSkipVerify bool `yaml:"insecure_skip_verify"` Messages int `yaml:"messages"` TestInterval time.Duration `yaml:"interval"` + MessagePayload string `yaml:"message_payload"` } var build string @@ -237,8 +238,14 @@ func startProbe(probeConfig *probeConfig) { timeout := time.After(probeTimeout) receiveCount := 0 + // Support for custom message payload + msgPayload := "This is msg %d!" + if probeConfig.MessagePayload != "" { + msgPayload = probeConfig.MessagePayload + } + for i := 0; i < num; i++ { - text := fmt.Sprintf("this is msg #%d!", i) + text := fmt.Sprintf(msgPayload, i) token := publisher.Publish(probeConfig.Topic, qos, false, text) if !token.WaitTimeout(time.Until(probeDeadline)) { messagesPublishTimeout.WithLabelValues(probeConfig.Name, probeConfig.Broker).Inc()