From 0bc38431b9ae401d046455f9ca7b8b38e17ec69a Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Fri, 28 Aug 2026 12:58:50 -0700 Subject: [PATCH] monitoring: doorbell E2E kuma push heartbeat + systemd timer --- infra/doorbell-probe/e2e-kuma-heartbeat.sh | 41 +++++++++++++++++++ .../doorbell-e2e-kuma-heartbeat.service | 8 ++++ .../systemd/doorbell-e2e-kuma-heartbeat.timer | 10 +++++ 3 files changed, 59 insertions(+) create mode 100644 infra/doorbell-probe/e2e-kuma-heartbeat.sh create mode 100644 infra/systemd/doorbell-e2e-kuma-heartbeat.service create mode 100644 infra/systemd/doorbell-e2e-kuma-heartbeat.timer diff --git a/infra/doorbell-probe/e2e-kuma-heartbeat.sh b/infra/doorbell-probe/e2e-kuma-heartbeat.sh new file mode 100644 index 0000000..6c8f33d --- /dev/null +++ b/infra/doorbell-probe/e2e-kuma-heartbeat.sh @@ -0,0 +1,41 @@ +#!/bin/bash +set -u + +KUMA_BASE="${KUMA_BASE:-https://up.notsosm.art}" +TOKEN_FILE="${KUMA_TOKEN_FILE:-/root/nr-flow-validator/infra/.secrets/doorbell-e2e-kuma-push-token}" +NTFY_TOPIC="${NTFY_TOPIC:-ALERT_klubhaus_topic_test}" +PROBE_STATE="${PROBE_STATE:-zigbee2mqtt/DoorbellProbe}" +TIMEOUT="${TIMEOUT:-25}" + +[ -s "$TOKEN_FILE" ] || exit 1 +TOKEN="$(tr -d '[:space:]' < "$TOKEN_FILE")" + +reason="" +marker="e2e-$(date +%s)-$$" + +# 1. publish probe canary (tagged doorbell-probe -> routes to fake device) +if ! curl -fsS -m 10 -o /dev/null -X POST "https://ntfy.sh/$NTFY_TOPIC" \ + -H "Title: doorbell-probe" -H "Tags: doorbell-probe" -d "$marker" 2>/dev/null; then + reason="ntfy_publish_failed" +else + # 2. wait for the fake device to echo a TOGGLE on its state topic + if timeout "$TIMEOUT" docker exec mosquitto mosquitto_sub -h 127.0.0.1 \ + -t "$PROBE_STATE" -C 1 -W "$TIMEOUT" 2>/dev/null | grep -q TOGGLE; then + : # ok + else + reason="no_echo_within_${TIMEOUT}s" + fi +fi + +if [ -n "$reason" ]; then + status="down" + msg="doorbell-e2e: ${reason}" +else + status="up" + msg="doorbell e2e ok" +fi + +curl -fsS -m 10 -o /dev/null --get \ + --data-urlencode "status=$status" \ + --data-urlencode "msg=$msg" \ + "$KUMA_BASE/api/push/$TOKEN" diff --git a/infra/systemd/doorbell-e2e-kuma-heartbeat.service b/infra/systemd/doorbell-e2e-kuma-heartbeat.service new file mode 100644 index 0000000..b214d70 --- /dev/null +++ b/infra/systemd/doorbell-e2e-kuma-heartbeat.service @@ -0,0 +1,8 @@ +[Unit] +Description=Doorbell E2E heartbeat to Uptime Kuma +After=docker.service +Requires=docker.service + +[Service] +Type=oneshot +ExecStart=/root/nr-flow-validator/infra/doorbell-probe/e2e-kuma-heartbeat.sh diff --git a/infra/systemd/doorbell-e2e-kuma-heartbeat.timer b/infra/systemd/doorbell-e2e-kuma-heartbeat.timer new file mode 100644 index 0000000..64e561a --- /dev/null +++ b/infra/systemd/doorbell-e2e-kuma-heartbeat.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run doorbell E2E heartbeat every minute + +[Timer] +OnCalendar=*-*-* *:*:00 +AccuracySec=5s +Persistent=true + +[Install] +WantedBy=timers.target