Network uptime monitor publishing to Home Assistant MQTT discovery.
Supports ICMP ping and DNS lookup. Sensors publishes round-trip-time, jitter and loss.
You can use this application to create multiple probes that reports to Home Assistant using MQTT. Home Assistant MQTT integration must be configured with discovery enabled (default).
A configuration file has to be created. See details below Example of minimal configuration file (default config filename is probe.yaml):
mqtt:
host: 192.168.1.10
probes:
dns:
- name: google
target-adr: 8.8.8.8
You will find the the probe as a device in MQTT integration:
You can run the application using docker.
docker run --volume=$(pwd)/probe.yaml:/app/config/probe.yaml ghcr.io/toreamun/hanetprobe:master
docker-compose.yaml example:
version: "3"
services:
probe:
container_name: ha-net-probe
image: ghcr.io/toreamun/hanetprobe:master
restart: unless-stopped
volumes:
- ./probe.yaml:/app/config/probe.yaml
Create a docker-compose.yaml file and a probe config file named probe.yaml file in the same folder. You can run docker-compose up --detach
to start the container, and docker-compose down
to stop it. Output from container can be viewed with docker-compose logs -f
. You can update docker image with docker-compose pull
.
python3 probe_app.py
DNS probes uses UDP DNS queries to monitor round-trip-time and packet loss. The probe keeps a limited history and calculates average round-trip-time, jitter and percent packet loss.
ICMP ping probes uses ICMP ping packets to monitor round-trip-time and packet loss. The probe keeps a limited history and calculates average round-trip-time, jitter and percent packet loss.
The configuration can contain multiple probes and Python logging schema can be used in configuration:
Example of two probes:
service:
id: router-probe
name: my-net-probe
log-level: INFO
mqtt:
host: 192.168.1.10
probes:
dns:
- name: google
target-adr: 8.8.8.8
- name: cloudflare
target-adr: 1.1.1.1
interval: 10
timeout: 0.5
query-names: google.com microsoft.com
history-len: 50
ping:
- name: google
target-adr: 8.8.8.8
- name: cloudflare
target-adr: 1.1.1.1
interval: 10
timeout: 0.5
history-len: 50
Example using Python logging config schema:
service:
id: router-probe
name: my-net-probe
mqtt:
host: 192.168.1.10
probes:
ping:
- name: google
target-adr: 8.8.8.8
logging:
version: 1
formatters:
simple:
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
handlers:
console:
class: logging.StreamHandler
level: DEBUG
formatter: simple
stream: ext://sys.stdout
file:
class : logging.handlers.RotatingFileHandler
formatter: simple
filename: hanetprobe.log
maxBytes: 2621440
backupCount: 3
root:
level: INFO
handlers: [console,file]
propagate: no
loggers:
ping_probe:
level: WARNING
propagate: yes
dns_probe:
level: WARNING
propagate: yes
publish:
level: INFO
propagate: yes
- id: used to generate unique device id. Defaults host name.
- name: used for Home Assistant device name.
- log-level: Can be CRITICAL, ERROR, WARNING, INFO or DEBUG. Default is INFO.
- host: MQTT server host address. Required.
- port: Optional. Defaults to 1883.
- transport: tcp or websockets. Defaults to tcp.
- username: optional.
- password: optional.
- name: probe name. Used as base for home assistant entity names.
- target-adr: IP address of dns server to monitor.
- interval: time between each DNS query. Defaults to 1.0 (1 second).
- timeout: time to wait for reply. Defaults to 1.0 (1 second).
- history-len: length of history (used to calculate jitter and averate rtt and loss). Defaults to 100.
- publish-precision: decimals in published values. Defaults to 1.
- query-names: Optional. Names (seperated by space) to use in DNS lookup. A random name is selected from the list.
- name: probe name. Used as base for home assistant entity names.
- target-adr: IP address of server to monitor.
- interval: time between each DNS query. Defaults to 1.0 (1 second).
- timeout: time to wait for reply. Defaults to 1.0 (1 second).
- history-len: length of history (used to calculate jitter and averate rtt and loss). Defaults to 100.
- publish-precision: decimals in published values. Defaults to 1.
- payload-size: ping packet size. Defaults to 56.
Uses multiple probes to change status when all are up or down.
compound:
all-down:
- name: "multiple"
probes:
- type: dns
name: cloudflare
- type: dns
name: google
See Python logging config schema.
Grafana with InfluxDB is a great way of visualizing data from the probe. Here are some examples of comparing Telia Trådløst bredbånd and Telenor Trådløst bredbånd Fixed Wireless Access 4G connectivity to Cloudflare DNS. Boths modem/antennas was located at the same place pointing at the same shared tower.