feat: drill-down filters on overview and outdated agent version highlight
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,10 +8,12 @@ from app.config import get_settings
|
||||
from app.database import get_db
|
||||
from app.models import Event, Host
|
||||
from app.schemas.list_models import HostDetail, HostListResponse, HostSummary
|
||||
from app.services.agent_version import latest_agent_versions_by_product
|
||||
from app.services.host_delete import delete_host_and_related
|
||||
from app.services.host_health import (
|
||||
HEARTBEAT_TYPE,
|
||||
agent_status,
|
||||
agent_status as compute_agent_status,
|
||||
apply_agent_status_host_filter,
|
||||
max_daily_report_time_by_host,
|
||||
max_event_time_by_host,
|
||||
)
|
||||
@@ -25,6 +27,7 @@ def list_hosts(
|
||||
page_size: int = Query(50, ge=1, le=200),
|
||||
product: str | None = None,
|
||||
hostname: str | None = None,
|
||||
agent_status: str | None = Query(None, pattern="^(online|stale|unknown)$"),
|
||||
db: Session = Depends(get_db),
|
||||
_user: str = Depends(get_current_user),
|
||||
) -> HostListResponse:
|
||||
@@ -40,6 +43,15 @@ def list_hosts(
|
||||
stmt = stmt.where(host_match)
|
||||
count_stmt = count_stmt.where(host_match)
|
||||
|
||||
settings = get_settings()
|
||||
if agent_status:
|
||||
stmt, count_stmt = apply_agent_status_host_filter(
|
||||
stmt,
|
||||
count_stmt,
|
||||
agent_status,
|
||||
stale_minutes=settings.sac_heartbeat_stale_minutes,
|
||||
)
|
||||
|
||||
total = db.scalar(count_stmt) or 0
|
||||
rows = db.scalars(
|
||||
stmt.order_by(Host.last_seen_at.desc())
|
||||
@@ -47,7 +59,6 @@ def list_hosts(
|
||||
.limit(page_size)
|
||||
).all()
|
||||
|
||||
settings = get_settings()
|
||||
hb_map = max_event_time_by_host(db, HEARTBEAT_TYPE)
|
||||
report_map = max_daily_report_time_by_host(db)
|
||||
|
||||
@@ -72,13 +83,19 @@ def list_hosts(
|
||||
last_heartbeat_at=last_hb,
|
||||
last_daily_report_at=report_map.get(host.id),
|
||||
last_inventory_at=host.inventory_updated_at,
|
||||
agent_status=agent_status(
|
||||
agent_status=compute_agent_status(
|
||||
last_hb, stale_minutes=settings.sac_heartbeat_stale_minutes
|
||||
),
|
||||
)
|
||||
)
|
||||
|
||||
return HostListResponse(items=items, total=total, page=page, page_size=page_size)
|
||||
return HostListResponse(
|
||||
items=items,
|
||||
total=total,
|
||||
page=page,
|
||||
page_size=page_size,
|
||||
latest_agent_versions=latest_agent_versions_by_product(db),
|
||||
)
|
||||
|
||||
|
||||
def _host_detail_from_model(
|
||||
@@ -108,7 +125,7 @@ def _host_detail_from_model(
|
||||
last_heartbeat_at=last_hb,
|
||||
last_daily_report_at=report_map.get(host.id),
|
||||
last_inventory_at=host.inventory_updated_at,
|
||||
agent_status=agent_status(last_hb, stale_minutes=settings.sac_heartbeat_stale_minutes),
|
||||
agent_status=compute_agent_status(last_hb, stale_minutes=settings.sac_heartbeat_stale_minutes),
|
||||
agent_instance_id=host.agent_instance_id,
|
||||
tags=host.tags if isinstance(host.tags, list) else [],
|
||||
use_sac_mode=host.use_sac_mode,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
|
||||
|
||||
@@ -156,6 +156,10 @@ def list_problems(
|
||||
|
||||
hostname: str | None = Query(None),
|
||||
|
||||
created_within_hours: int | None = Query(None, ge=1, le=8760),
|
||||
|
||||
resolved_within_hours: int | None = Query(None, ge=1, le=8760),
|
||||
|
||||
db: Session = Depends(get_db),
|
||||
|
||||
_user: str = Depends(get_current_user),
|
||||
@@ -194,6 +198,22 @@ def list_problems(
|
||||
|
||||
count_stmt = count_stmt.where(Host.hostname.ilike(like) | Host.display_name.ilike(like))
|
||||
|
||||
if created_within_hours is not None:
|
||||
|
||||
since = datetime.now(timezone.utc) - timedelta(hours=created_within_hours)
|
||||
|
||||
stmt = stmt.where(Problem.created_at >= since)
|
||||
|
||||
count_stmt = count_stmt.where(Problem.created_at >= since)
|
||||
|
||||
if resolved_within_hours is not None:
|
||||
|
||||
since = datetime.now(timezone.utc) - timedelta(hours=resolved_within_hours)
|
||||
|
||||
stmt = stmt.where(Problem.status == "resolved", Problem.updated_at >= since)
|
||||
|
||||
count_stmt = count_stmt.where(Problem.status == "resolved", Problem.updated_at >= since)
|
||||
|
||||
|
||||
|
||||
total = db.scalar(count_stmt) or 0
|
||||
|
||||
Reference in New Issue
Block a user