Skip to content
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

Feature: Add MQTT Topic monitor #1512

Open
aikitori opened this issue Dec 2, 2024 · 5 comments
Open

Feature: Add MQTT Topic monitor #1512

aikitori opened this issue Dec 2, 2024 · 5 comments

Comments

@aikitori
Copy link
Contributor

aikitori commented Dec 2, 2024

Hi!

A MQTT monitor would be awesome ;)

Maybe use some kinde of regex like the http monitor for evaluating?

Paho seems the one to go:
https://pypi.org/project/paho-mqtt/
https://eclipse.dev/paho/
Github repo: https://github.com/eclipse-paho/paho.mqtt.python

Here a a list of other python clients:
https://www.emqx.com/en/blog/comparision-of-python-mqtt-client

@jamesoff
Copy link
Owner

jamesoff commented Dec 9, 2024

Can you describe how you'd like it to work? Like subscribe to a topic and alert based on the messages posted? I'm not super-familiar with MQTT. There's a logger which posts to it which I think uses Paho already, which was contributed by someone else.

@aikitori
Copy link
Contributor Author

aikitori commented Dec 16, 2024

i have e.g. an shellyplus1, which report via it's last will on the topic shellys/shellyplus1-cde/online ether true or false.
So a success is "true" , everything else is a fail.

Questions:
Config for the monitor.conf?

  • host / ip
  • port
  • username
  • password
  • tls
  • [server ca]
  • [client cert]
  • [client key]

Config for the monitors.conf?

  • topic
  • success match (string/regex)

On startup, you start listening to all topics in the monitors.conf. On every intervall, you check the saved responses.

i don't know how to handle the listing part to the different topics. you need something like the Listener class in the network logger.

edit:
Another posibilty could be to save all the mqtt client infos in the monitors.ini

@aikitori
Copy link
Contributor Author

aikitori commented Dec 16, 2024

I created a little example:
https://github.com/aikitori/simplemonitor/blob/mqtt-monitor/simplemonitor/Monitors/mqtt.py

You need a running mqtt server on localhost:

$ /etc/mosquitto/conf.d/local.conf
listener 1883
allow_anonymous true

and mqtt client like mosquitto_client or http://mqtt-explorer.com/ for testing

Whats your opinion?
Dont know how to handle the credentials ...

@aikitori
Copy link
Contributor Author

I added a Manager for the mqtt connections to limit them to 1/broker.
I testet the tls option with my mosquitto broker with a lets's encryp cert. The ca option is untested ...
Added some doku, but im propably not finished.
https://github.com/aikitori/simplemonitor/tree/mqtt-monitor

Happy Holidays!

@jamesoff
Copy link
Owner

Thanks, this is looking good (and better than I'd have known to do!)

Let me know when you think it's about done, or feel free to open a PR for it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants