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

+20 -1
View File
@@ -8,7 +8,7 @@ import sqlite3
import sys
import time
from . import __version__, auth, db, web
from . import __version__, alerts, auth, db, web
from .config import load
@@ -28,6 +28,21 @@ def cmd_serve(cfg, args) -> int:
return 0
def cmd_check_alerts(cfg, args) -> int:
return int(alerts.check(cfg) > 0)
def cmd_test_alert(cfg, args) -> int:
try:
alerts.publish(cfg, "kernelwatch: test notification",
"Stale-host and reporting-recovery notifications will be delivered to this topic.")
except alerts.DeliveryError as exc:
print(f"kernelwatch: {exc}", file=sys.stderr)
return 1
print("Test notification sent.")
return 0
def cmd_add_host(cfg, args) -> int:
token = auth.new_token()
conn = _conn(cfg)
@@ -134,6 +149,10 @@ def main(argv: list[str] | None = None) -> int:
sub = parser.add_subparsers(dest="command", required=True)
sub.add_parser("serve", help="run the HTTP server").set_defaults(func=cmd_serve)
sub.add_parser("check-alerts", help="send stale-host and recovery notifications").set_defaults(
func=cmd_check_alerts)
sub.add_parser("test-alert", help="send a test notification to the configured ntfy topic").set_defaults(
func=cmd_test_alert)
for name, func, help_ in (
("add-host", cmd_add_host, "register a host and print its token"),