Add ntfy alerts for stale hosts and reporting recovery
CI / tests (Python 3.10) (pull_request) Successful in 19s
CI / tests (Python 3.11) (pull_request) Successful in 17s
CI / tests (Python 3.12) (pull_request) Successful in 17s
CI / tests (Python 3.13) (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 3s

This commit is contained in:
patrick committed 2026-10-24 15:15:48 -04:00
1 parent bd0db302b0
commit 47f93968e9
11 files changed
+631 -4

No files matched your search

+22
View File
@@ -30,6 +30,10 @@ CREATE TABLE IF NOT EXISTS sessions (
user TEXT NOT NULL REFERENCES users(name) ON DELETE CASCADE,
expires_at INTEGER NOT NULL
);
CREATE TABLE IF NOT EXISTS stale_alerts (
host TEXT PRIMARY KEY REFERENCES hosts(name) ON DELETE CASCADE,
last_seen INTEGER
);
"""
@@ -142,6 +146,24 @@ def host_exists(conn: sqlite3.Connection, host: str) -> bool:
return conn.execute("SELECT 1 FROM hosts WHERE name = ?", (host,)).fetchone() is not None
# --- delivered stale notifications ------------------------------------------
def stale_alerts(conn: sqlite3.Connection) -> dict[str, int | None]:
return {r["host"]: r["last_seen"] for r in conn.execute("SELECT * FROM stale_alerts")}
def record_stale_alert(conn: sqlite3.Connection, host: str, last_seen: int | None) -> None:
# The host may have been removed while the notification was in flight.
conn.execute(
"INSERT INTO stale_alerts (host, last_seen) SELECT name, ? FROM hosts WHERE name = ?",
(last_seen, host),
)
def clear_stale_alert(conn: sqlite3.Connection, host: str) -> None:
conn.execute("DELETE FROM stale_alerts WHERE host = ?", (host,))
# --- users & sessions -------------------------------------------------------
def set_user(conn: sqlite3.Connection, name: str, pw_hash: str) -> None: