Skip to content

Commit

Permalink
Merge pull request #48 from seb-koch/support-for-message-payload
Browse files Browse the repository at this point in the history
Support for message_payload parameter
  • Loading branch information
hikhvar authored Aug 25, 2020
2 parents bfe858d + d9551d8 commit 5b4f809
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.yaml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 5b4f809

Please sign in to comment.