Some checks failed
Use-case regression gate / usecase-regressions (push) Failing after 6m16s
Assistant: codex Assistant-Model: gpt-6-astra Assistant-Session: 01a18e2d-f513-7742-b8e7-12af0b744ff3
51 lines
2.3 KiB
Python
51 lines
2.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Queue/replay backup alerts through State Hub and the reviewed email route."""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from backup_alerts import drain
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--execute", action="store_true")
|
|
parser.add_argument("--state-dir", type=Path, required=True)
|
|
parser.add_argument("--hub-base", required=True)
|
|
parser.add_argument("--alertmanager-base", required=True)
|
|
parser.add_argument("--event-id")
|
|
parser.add_argument("--condition", choices=["backup_failed", "pending_backup", "backup_stale"])
|
|
parser.add_argument("--test", action="store_true")
|
|
parser.add_argument("--resolve")
|
|
parser.add_argument("--failed-unit", choices=["coulomb-social-paired-backup.service",
|
|
"coulomb-social-backup-freshness.service"])
|
|
args = parser.parse_args()
|
|
if args.failed_unit:
|
|
if (args.event_id or args.condition or args.test or args.resolve
|
|
or os.environ.get("MONITOR_UNIT") != args.failed_unit
|
|
or not os.environ.get("MONITOR_INVOCATION_ID")
|
|
or os.environ.get("MONITOR_SERVICE_RESULT") in (None, "success")):
|
|
parser.error("A matching failed systemd invocation is required")
|
|
args.event_id = os.environ["MONITOR_INVOCATION_ID"]
|
|
args.condition = "backup_failed"
|
|
if bool(args.event_id) != bool(args.condition) or (args.test and not args.event_id):
|
|
parser.error("event-id and condition are required together; test requires an event")
|
|
if not args.execute:
|
|
print(json.dumps({"status": "prepared_only", "notification_sent": False}))
|
|
return 0
|
|
event = {"event_id": args.event_id, "condition": args.condition,
|
|
"test": args.test} if args.event_id else None
|
|
try:
|
|
result = drain(args.state_dir, args.hub_base, args.alertmanager_base,
|
|
event=event, resolve=args.resolve)
|
|
except Exception as error:
|
|
result = {"status": "alert_delivery_requires_review", "failure_type": type(error).__name__,
|
|
"email_delivery_proven": False}
|
|
print(json.dumps(result))
|
|
return int(result["status"] != "channel_handoffs_verified")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|