Feature: Add MQTT Topic monitor
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
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.
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
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 ...
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!
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 :)