64 lines
2.4 KiB
Python
64 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.services.alerts import OperatorDigestService
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
instrument_id = int(env.get("OPERATOR_DIGEST_INSTRUMENT_ID", "1"))
|
|
alert_limit = int(env.get("OPERATOR_DIGEST_LIMIT", "50"))
|
|
visual_limit = int(env.get("OPERATOR_DIGEST_VISUAL_LIMIT", "50"))
|
|
top_limit = int(env.get("OPERATOR_DIGEST_TOP_LIMIT", "10"))
|
|
output_json = _get_bool(env, "OPERATOR_DIGEST_OUTPUT_JSON", False)
|
|
payload = OperatorDigestService().build_digest(
|
|
instrument_id=instrument_id,
|
|
alert_limit=alert_limit,
|
|
visual_review_limit=visual_limit,
|
|
top_limit=top_limit,
|
|
)
|
|
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
else:
|
|
counts = dict(payload.get("summary_counts") or {})
|
|
print(f"Operator digest status: {payload.get('status', 'unknown')}")
|
|
print(payload.get("operator_summary") or "Operator digest unavailable.")
|
|
print(
|
|
"Alerts / suppressed / failed-retry / visual mismatches / pending feedback: "
|
|
f"{counts.get('recent_alert_count', 0)} / "
|
|
f"{counts.get('suppressed_delivery_count', 0)} / "
|
|
f"{counts.get('failed_or_retry_delivery_count', 0)} / "
|
|
f"{counts.get('visual_mismatch_count', 0)} / "
|
|
f"{counts.get('pending_feedback_count', 0)}"
|
|
)
|
|
print(f"Review queue items: {len(payload.get('review_queue') or [])}")
|
|
for item in payload.get("review_queue") or []:
|
|
print(
|
|
f"- {item.get('priority', 'unknown')} {item.get('queue_type', 'unknown')} "
|
|
f"alert={item.get('alert_id', 'n/a')} review={item.get('visual_review_id', 'n/a')} "
|
|
f"reason={item.get('reason', 'n/a')}"
|
|
)
|
|
if payload.get("warnings"):
|
|
print(f"Warnings: {', '.join(payload.get('warnings') or [])}")
|
|
return 0
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool = False) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|