|
|
|
@@ -16,6 +16,8 @@ from schemas.reslevis import ( |
|
|
|
OperatorItem, |
|
|
|
SubjectItem, |
|
|
|
AlarmItem, |
|
|
|
AlarmCoreItem, |
|
|
|
AlarmStatusUpdateItem, |
|
|
|
TrackItem, |
|
|
|
TrackHistoryItem, |
|
|
|
TrackerZoneItem, |
|
|
|
@@ -38,6 +40,7 @@ from security import get_current_user |
|
|
|
|
|
|
|
#CORE SYNC |
|
|
|
CORE_BASE_URL = config_env.CORE_API_URL.rstrip("/") |
|
|
|
ALERTS_CORE_BASE_URL = "http://localhost:1902" |
|
|
|
TRACKS_CORE_BASE_URL = "http://localhost:1902" |
|
|
|
CORE_TIMEOUT = 2.0 # secondi |
|
|
|
|
|
|
|
@@ -425,6 +428,56 @@ def removeTrack(track_id: str): |
|
|
|
return {"message": "OK"} |
|
|
|
|
|
|
|
|
|
|
|
@router.get( |
|
|
|
"/getAlarms", |
|
|
|
response_model=List[AlarmCoreItem], |
|
|
|
tags=["Reslevis"], |
|
|
|
dependencies=[Depends(get_current_user)], |
|
|
|
) |
|
|
|
async def getAlarms(): |
|
|
|
async with httpx.AsyncClient(timeout=CORE_TIMEOUT) as client: |
|
|
|
resp = await client.get(f"{ALERTS_CORE_BASE_URL}/reslevis/alerts") |
|
|
|
|
|
|
|
if resp.status_code >= 400: |
|
|
|
detail = resp.text.strip() or "CORE alerts request failed" |
|
|
|
raise HTTPException(status_code=resp.status_code, detail=detail) |
|
|
|
|
|
|
|
try: |
|
|
|
payload = resp.json() |
|
|
|
except ValueError as exc: |
|
|
|
raise HTTPException(status_code=502, detail="Invalid CORE response") from exc |
|
|
|
|
|
|
|
if not isinstance(payload, list): |
|
|
|
raise HTTPException(status_code=502, detail="Unexpected CORE response type") |
|
|
|
|
|
|
|
return payload |
|
|
|
|
|
|
|
|
|
|
|
@router.put( |
|
|
|
"/updateAlarm", |
|
|
|
tags=["Reslevis"], |
|
|
|
dependencies=[Depends(get_current_user)], |
|
|
|
) |
|
|
|
async def updateAlarm(item: AlarmStatusUpdateItem): |
|
|
|
async with httpx.AsyncClient(timeout=CORE_TIMEOUT) as client: |
|
|
|
resp = await client.patch( |
|
|
|
f"{ALERTS_CORE_BASE_URL}/reslevis/alerts/{item.id}", |
|
|
|
json={"status": item.status}, |
|
|
|
) |
|
|
|
|
|
|
|
if resp.status_code >= 400: |
|
|
|
detail = resp.text.strip() or "CORE alert update failed" |
|
|
|
raise HTTPException(status_code=resp.status_code, detail=detail) |
|
|
|
|
|
|
|
if not resp.content: |
|
|
|
return {"message": "OK"} |
|
|
|
|
|
|
|
try: |
|
|
|
return resp.json() |
|
|
|
except ValueError: |
|
|
|
return {"message": "OK"} |
|
|
|
|
|
|
|
|
|
|
|
@router.get( |
|
|
|
"/getOperators", |
|
|
|
response_model=List[OperatorItem], |
|
|
|
|