42 lines
1.2 KiB
Bash
42 lines
1.2 KiB
Bash
#!/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"
|