features:
- script periodically pings hosts in parallel
- sends multiple packets, only reports host down on 100% packet loss
- compares host availability with previous value
- sends simple message to local MQTT broker if host state change is detected
- to topic:
host-monitor/$HOSTNAME
- payload:
{"online": "0"}
(or1
)
- to topic:
- wrapped in Docker as i run most things in Docker on my server
missing features:
- should report host down on all monitored hosts when stopping the script
- should support some external configuration file: monitored hosts, mqtt credentials, etc.
- should distribute it as a ready-to-use docker container on dockerhub
i personally to use this to monitor if my internet provider is down while im away (e.g. 8.8.8.8 is reachable) and also my devices on my personal VPN (check out Tailscale!)
these MQTT messages are then processed by a Node-RED instance, which in turn pushes the data to an InfluxDB, so then i can visualize the historical data in Grafana
example output:
tries=5 interval=30 timeout=5 | starting host-monitor
ip=100.94.190.72 name=important-host | start monitoring
ip=100.94.190.72 name=important-host | checking host
ip=8.8.8.8 name=ISP | start monitoring
ip=8.8.8.8 name=ISP | checking host
ip=8.8.8.8 name=ISP | results 0% packet loss
ip=8.8.8.8 name=ISP | comparing prev=-1 isonline=1
ip=8.8.8.8 name=ISP | state changed, sending to mqtt
ip=8.8.8.8 name=ISP | waiting a bit before next check
ip=100.94.190.72 name=important-host | results 0% packet loss
ip=100.94.190.72 name=important-host | comparing prev=-1 isonline=1
ip=100.94.190.72 name=important-host | state changed, sending to mqtt
ip=100.94.190.72 name=important-host | waiting a bit before next check
ip=8.8.8.8 name=ISP | checking host
ip=100.94.190.72 name=important-host | checking host
ip=8.8.8.8 name=ISP | results 0% packet loss
ip=8.8.8.8 name=ISP | comparing prev=1 isonline=1
ip=8.8.8.8 name=ISP | waiting a bit before next check
ip=100.94.190.72 name=important-host | results 0% packet loss
ip=100.94.190.72 name=important-host | comparing prev=1 isonline=1
ip=100.94.190.72 name=important-host | waiting a bit before next check
...
host previous state prev=-1
on script start is to force it to report the host state to mqtt no matter if its down or up