monitoring: doorbell E2E kuma push heartbeat + systemd timer
This commit is contained in:
@@ -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"
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=Run doorbell E2E heartbeat every minute
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=*-*-* *:*:00
|
||||||
|
AccuracySec=5s
|
||||||
|
Persistent=true
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
Reference in New Issue
Block a user