a-bali/janitor

Support for mqtts

Closed this issue · 2 comments

Hello,

Update: I've raised a PR #12

I'm wondering if you could add support for specifying the URL scheme in the config.yml? I've been running into an issue where my MQTT broker is setup to use SSL and thus the mqtts:// scheme (like https://) but it seems that Janitor doesn't support this?

I've built the Dockerfile locally and hardcoded the scheme in main.go which works for me, for now - the %s before seems to suggest it is supported but doesn't have a corresponding config key? I don't use golang though, so not sure.

// Original:
opts.AddBroker(fmt.Sprintf("%s://%s:%d", getConfig().Monitor.MQTT.Server, getConfig().Monitor.MQTT.Port))

// My change:
opts.AddBroker(fmt.Sprintf("mqtts://%s:%d", getConfig().Monitor.MQTT.Server, getConfig().Monitor.MQTT.Port))

If I don't specify mqtts, I get this error on startup of Janitor:

Unable to connect to MQTT for monitoring: network Error : EOF

If I specify mqtts in the server hostname in config.yml then I get the below error:

monitor:

  # MQTT monitoring
  mqtt:
    # Server connection details
    # Host name
    server: mqtts://mosquitto.int.price.gb.net
    # Port number (default: 1883)
    port: 8883
Unable to connect to MQTT for monitoring: network Error : dial tcp: lookup mqtts on 127.0.0.11:53: no such host

I don't use Golang at all, so don't know enough to propose a PR, but wondering if you could add support for this to be specified in config.yml at some point. Thanks for the great work you've done on Janitor - it's extremely helpful to me!

I actually dug a bit deeper and got this working properly, so will propose a PR.

As discussed in the PR if https://github.com/a-bali/janitor/blob/master/main.go#L473 is changed to the below:

opts.AddBroker(fmt.Sprintf("%s:%d", getConfig().Monitor.MQTT.Server, getConfig().Monitor.MQTT.Port))

This allows you to specify the scheme in the server url in config.yml. Example below.

  mqtt:
    # Server connection details
    # Host name
    server: mqtts://mosquitto.int.price.gb.net
    # Port number (default: 1883)
    port: 8883

As an aside, ssl://mosquitto.int.price.gb.net also works.