Close P22 maintenance retention rollup
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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.api.maintenance import get_maintenance_summary
|
||||
|
||||
|
||||
def main(env=None) -> int:
|
||||
env = os.environ if env is None else env
|
||||
payload = get_maintenance_summary(
|
||||
instrument_id=int(env.get("MAINTENANCE_SUMMARY_INSTRUMENT_ID", "1")),
|
||||
alert_limit=int(env.get("MAINTENANCE_SUMMARY_ALERT_LIMIT", "50")),
|
||||
visual_limit=int(env.get("MAINTENANCE_SUMMARY_VISUAL_LIMIT", "50")),
|
||||
incident_limit=int(env.get("MAINTENANCE_SUMMARY_INCIDENT_LIMIT", "50")),
|
||||
)
|
||||
if _get_bool(env, "MAINTENANCE_SUMMARY_OUTPUT_JSON", False):
|
||||
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
||||
else:
|
||||
print(f"Maintenance summary status: {payload.get('status', 'unknown')}")
|
||||
print(f"Blockers: {', '.join(payload.get('blockers') or []) or 'none'}")
|
||||
print(f"Warnings: {', '.join(payload.get('warnings') or []) or 'none'}")
|
||||
actions = dict(payload.get("maintenance_actions") or {})
|
||||
print(f"Automatic actions: {', '.join(actions.get('automatic_actions') or []) or 'none'}")
|
||||
print(f"Operator actions: {', '.join(actions.get('operator_actions') or []) or 'none'}")
|
||||
return 0 if not payload.get("blockers") else 2
|
||||
|
||||
|
||||
def _get_bool(env, key: str, default: bool) -> 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())
|
||||
Reference in New Issue
Block a user