-
-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mqtt support #950
base: master
Are you sure you want to change the base?
Mqtt support #950
Conversation
Hey, thanks for implementing this! I gave it a spin, and while basic functionality seems to work, I have some questions. First:
It sounds like this is like "ping" service, checking if MQTT broker responds? Or possibly expecting a known value on configured topic? That would monitor the broker functionality itself, not the values published by other clients. Second, I'm not sure how to configure for alerting for usecases mentioned in the original issue:
Could you guide me? |
Yeah, what I implemented is a ping to ensure that the basic MQTT infrastructure is up and running. You are correct that it will not monitor the values published by other clients. Given that, I don't think those kind of alerts can be created. The cases you mention seem to be quite different from how Gatus does other checks. They would require a persistent checker that would be subscribing from MQTT and exposing a metric. This is more in line with how a Prometheus exporter works. I believe that external endpoints or #596 would be a better fit for those checks. |
@TwiN Can you review? |
@@ -32,6 +36,12 @@ var ( | |||
|
|||
whoisClient = whois.NewClient().WithReferralCache(true) | |||
whoisExpirationDateCache = gocache.NewCache().WithMaxSize(10000).WithDefaultTTL(24 * time.Hour) | |||
|
|||
mqttTemplateEngine = template.New("base").Funcs(template.FuncMap{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only think I'm unsure about is the fact that this uses a templating engine, while everything else leverages placeholder and functions. Maybe this should be exposed as a placeholder instead? I feel supporting [UUID4]
globally (and not just for MQTT) would be more beneficial, albeit more complicated.
The UUID4 placeholder should also be unique per endpoint, meaning that if it's in the url and the body, it should be the same. Let me know if that doesn't make sense, I can give you some examples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I will look around and see if I can just figure it out.
@@ -5,6 +5,7 @@ import ( | |||
"crypto/tls" | |||
"crypto/x509" | |||
"errors" | |||
"github.com/TwiN/gatus/v5/config/endpoint/mqtt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be separate from the standard library dependencies, namely, at the bottom. See other go files for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know/ping me when you resolved it 👀
Summary
#803 - Add support for MQTT testing
MQTT Endpoints are similar to DNS Endpoints in that they are recognized by the presence of an
mqtt
config block. This enables the endpoint to be configured with the required topic and the optional username/password. The check will subscribe to the topic and wait for a message to come in that contains a payload that matches the BODY. While the check is waiting for incoming messages it will public a message containing the BODY as the payload. If the subscription gets the message containing the body= before the timeout publish, CONNECTED will be set to true. Otherwise, it will be false. The body can also be a text/template with support for auuidv4
function. This enables the body to be specified likegatus check - {{ uuidv4 }}
and ensures that the subscription is getting the message that was just published.@TwiN Can you give me feedback on this PR?
Checklist
README.md
, if applicable.@zdzichu Here is an implementation of MQTT checking