louislam / uptime-kuma

A fancy self-hosted monitoring tool
https://uptime.kuma.pet
MIT License
57.77k stars 5.22k forks source link

Add MQTT monitor type #664

Closed matthew-larner closed 2 years ago

matthew-larner commented 3 years ago

Describe the solution you'd like It would be great to have a MQTT monitor type. It would listen on a MQTT topic for an online/available message. This would be perfect for monitoring of smart home systems.

Additional context MQTT LWT docs here: https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/

srgvg commented 3 years ago

I second this. Highly useful.

matthew-larner commented 3 years ago

@louislam I'm happy to get this built if you'd support the pull request?

louislam commented 3 years ago

@louislam I'm happy to get this built if you'd support the pull request?

Welcome!

Here is a good example of how to implement a notification:

https://github.com/louislam/uptime-kuma/pull/650/files

srgvg commented 3 years ago

@louislam I believe @matthew-larner wanted to implement an mqtt monitor, not a notification. (That latter also being interesting, but not the current scope, I believe.)

louislam commented 3 years ago

@louislam I believe @matthew-larner wanted to implement an mqtt monitor, not a notification. (That latter also being interesting, but not the current scope, I believe.)

Oh, thanks. I saw the term MQTT in Apprise, I thought it is a notification.

It is pretty new to me. Could it check with "TCP Port"?

srgvg commented 3 years ago

You could monitor the basic service with TCP - just like you could monitor a web server with TCP.

MQTT is a messagebus, and testing on the application layer would involve sending a message and verifying you receive it back (probably best asynchronously, in a separate process.)

matthew-larner commented 3 years ago

Yep, I was referring to a MQTT monitor. A TCP monitor wouldn't work unfortunately. @louislam would you support a pull request if I arranged for this new monitor to be added?

The way I'd expect this to work would be to listen on a MQTT topic and listen for messages. On non-'online' message, the service can be flagged as down.

mindlesstux commented 3 years ago

Side note, I think to get MQTT notification via apprise there needs to be one more package installed via pip in the docker image.

https://openbase.com/python/apprise/versions - Looking at 0.9.5.1

MQTT Support added. (#443) Note that the MQTT Plugin depends on paho-mqtt having been pre-installed: pip install paho-mqtt Also reinforced via: https://github.com/caronc/apprise/wiki/Notify_mqtt

Quick testing: Environment is an install without docker. Sent test notification, looked successful but no message in MQTT. Found that update for the apprise version and wiki page, did a quick pip3 install paho-mqtt, retested the notification and got the MQTT message. Tried the same test on the 1.8.0 docker image, looks like it passes but really is a silent failure to me.

louislam commented 3 years ago

Yep, I was referring to a MQTT monitor. A TCP monitor wouldn't work unfortunately. @louislam would you support a pull request if I arranged for this new monitor to be added?

The way I'd expect this to work would be to listen on a MQTT topic and listen for messages. On non-'online' message, the service can be flagged as down.

It is OK, but I probably need one more reviewer who is familiar MQTT to verify your pull request.

srgvg commented 3 years ago

I probably need one more reviewer who is familiar MQTT to verify your pull request.

I can do that, keep me posted.

Vartkat commented 2 years ago

I've experienced the TCP monitor on my MQTT broker on port 1883 (default mqtt port) and this makes the broker logs report many connection attemps refused. Not sure but this seems to overload the borker which seems to refuse legit connection.

We have to sort out two things here : 1- Monitoring the broker health 2- Using the broker to monitor its clients health

Not the same

V.