embyt / enocean-mqtt

Receives messages from an enOcean serial interface (USB) and provides selected messages to an MQTT broker.
GNU General Public License v3.0
42 stars 21 forks source link

healthcheck command line script #40

Open cnaslain opened 1 year ago

cnaslain commented 1 year ago

Hi,

Just found this interesting project to replace the direct connection between my EnOcean dongle and Home Assistant (running in a docker container). I already use a Mosquitto MQTT broker with Zigbee & Zwave. So having a similar gateway is great. My first try with enocean-mqtt works well. Thanks :-)

I have an enhancement request: Would it be possible to add an HTTP endpoint (like /health) to the python project, so it would be possible to configure an healthcheck on the enocean-mqtt container (in docker-compose)?

If not (for any good reason like lightweight, complexity etc.) how is it possible to check the health of enocean-mqtt ?

Regards

Chris

PS: I am not a python developer, but found an example in https://snyk.io/blog/best-practices-containerizing-python-docker/ (section 5). It may help and give some ideas.

romor commented 1 year ago

I am not sure whether we should introduce an additional http endpoint for health data.

However, we could introduce some mqtt heartbeat message, which gets repeatedly published?

Alternatively, we could subscribe to an mqtt topic where we listen for incoming commands. Such command could be to publish a status/health message or to publish some packet statistics?

mak-gitdev commented 1 year ago

Hi @romor and @cnaslain,

@romor, I had the idea to propose a mix of your two ideas in a kind of availibility message. It would be published OK (ON) when connected to the broker, then unavailable (OFF) once enocean-mqtt is stopped (normally or due to an exception). This would be accessible at / (may be availability as topic name).

cnaslain commented 1 year ago

Publishing a message into the MQTT broker to test the enocean-mqtt container may be an idea only if this test is executed from a script inside the enocean-mqtt container. A simple command returning 0 if it is ok, and 1 if it is not. The HTTP endpoint was just an idea, but any command line (wget/HTTP, bash script, python script) that can be executed inside the container is ok.

Simple command lines examples from my docker-compose for other services:

[...]
    healthcheck:
      test: ["CMD-SHELL", "mosquitto_sub -h 127.0.0.1 -p 1880 -t 'topic' -C 1 -E -i probe -W 3" ] # for Mosquitto
[...]
    healthcheck:
      test: ["CMD-SHELL", "curl -f http://127.0.0.1:8123"] # for HA
[...]