Files
security-alert-center/backend/app/api/v1/health.py
T
PTah c657a65970 feat: v0.2.0 branding, healthz version, SSE dashboard live
Centralize APP_VERSION 0.2.0; /health and /healthz return version;
startup log line; UI title Security Alert Center v.0.2.0;
SSE /api/v1/stream/events for live dashboard counters.
2026-05-27 13:20:39 +10:00

35 lines
882 B
Python

from fastapi import APIRouter, Depends
from sqlalchemy import text
from sqlalchemy.orm import Session
from app.database import get_db
from app.version import APP_NAME, APP_VERSION
router = APIRouter(tags=["health"])
def build_health_payload(db: Session) -> dict:
db_status = "ok"
try:
db.execute(text("SELECT 1"))
except Exception:
db_status = "error"
return {
"status": "ok" if db_status == "ok" else "degraded",
"database": db_status,
"service": "security-alert-center",
"name": APP_NAME,
"version": APP_VERSION,
}
@router.get("/health")
def health(db: Session = Depends(get_db)) -> dict:
return build_health_payload(db)
@router.get("/healthz")
def healthz(db: Session = Depends(get_db)) -> dict:
"""Kubernetes-style alias; same payload as /health."""
return build_health_payload(db)