Initial commit from Martins Github

This commit is contained in:
Jake Kasper
2026-04-23 13:50:31 -05:00
parent 488a0d01ef
commit 3228db3097
30 changed files with 4377 additions and 1 deletions

0
app/routers/__init__.py Normal file
View File

16
app/routers/actions.py Normal file
View File

@@ -0,0 +1,16 @@
from fastapi import APIRouter
from app.services import log_analyzer
router = APIRouter()
@router.get("/actions")
async def get_actions():
"""Return current action analysis: categorised issues from logs + Prometheus + Alertmanager."""
return await log_analyzer.analyze_logs()
@router.get("/actions/history")
async def get_actions_history():
"""Return the in-memory history ring-buffer for the time-series chart."""
return {"history": log_analyzer.get_history()}

11
app/routers/alerts.py Normal file
View File

@@ -0,0 +1,11 @@
from fastapi import APIRouter
from app.services import alertmanager
router = APIRouter()
@router.get("/alerts")
async def get_alerts():
alerts = await alertmanager.get_alerts()
critical = sum(1 for a in alerts if a.get("severity") == "critical")
return {"alerts": alerts, "total": len(alerts), "critical": critical}

View File

@@ -0,0 +1,20 @@
import asyncio
from fastapi import APIRouter, HTTPException
from app.services import ueransim
router = APIRouter()
@router.post("/emulated-session/start")
async def start_emulated_session():
task_id = ueransim.create_task()
asyncio.create_task(ueransim.run_test(task_id))
return {"task_id": task_id}
@router.get("/emulated-session/status/{task_id}")
async def get_emulated_session_status(task_id: str):
task = ueransim.get_task(task_id)
if task is None:
raise HTTPException(status_code=404, detail="Task not found")
return task

12
app/routers/network.py Normal file
View File

@@ -0,0 +1,12 @@
from fastapi import APIRouter
from app.services import prometheus
router = APIRouter()
@router.get("/network/status")
async def network_status():
nfs = await prometheus.get_nf_status()
up = sum(1 for n in nfs if n["state"] == "up")
down = sum(1 for n in nfs if n["state"] == "down")
return {"nfs": nfs, "summary": {"up": up, "down": down, "total": len(nfs)}}

24
app/routers/query.py Normal file
View File

@@ -0,0 +1,24 @@
from fastapi import APIRouter
from pydantic import BaseModel
from app.services import prometheus, alertmanager, ai
router = APIRouter()
class QueryRequest(BaseModel):
query: str
@router.post("/query")
async def query(req: QueryRequest):
network_state, alerts = await _gather(req.query)
response = await ai.answer(req.query, network_state, alerts)
return {"response": response, "network_state": network_state, "alerts": alerts}
async def _gather(query_text: str):
import asyncio
nfs_task = asyncio.create_task(prometheus.get_nf_status())
alerts_task = asyncio.create_task(alertmanager.get_alerts())
nfs, alerts = await asyncio.gather(nfs_task, alerts_task)
return {"nfs": nfs}, alerts