feat: drill-down filters on overview and outdated agent version highlight
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,11 +1,86 @@
|
||||
"""Hosts list API."""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from app.config import get_settings
|
||||
from app.models import Event, Host, Problem
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def host_stale_settings(monkeypatch):
|
||||
monkeypatch.setenv("SAC_HEARTBEAT_STALE_MINUTES", "60")
|
||||
get_settings.cache_clear()
|
||||
yield
|
||||
get_settings.cache_clear()
|
||||
|
||||
|
||||
def test_hosts_filter_agent_status_stale(client, db_session, jwt_headers, host_stale_settings):
|
||||
now = datetime.now(timezone.utc)
|
||||
stale_host = Host(
|
||||
hostname="stale-pc",
|
||||
os_family="windows",
|
||||
product="rdp-login-monitor",
|
||||
last_seen_at=now,
|
||||
)
|
||||
fresh_host = Host(
|
||||
hostname="fresh-pc",
|
||||
os_family="windows",
|
||||
product="rdp-login-monitor",
|
||||
last_seen_at=now,
|
||||
)
|
||||
unknown_host = Host(
|
||||
hostname="unknown-pc",
|
||||
os_family="linux",
|
||||
product="ssh-monitor",
|
||||
last_seen_at=now,
|
||||
)
|
||||
db_session.add_all([stale_host, fresh_host, unknown_host])
|
||||
db_session.flush()
|
||||
|
||||
db_session.add(
|
||||
Event(
|
||||
event_id=str(uuid.uuid4()),
|
||||
host_id=stale_host.id,
|
||||
occurred_at=now - timedelta(hours=2),
|
||||
received_at=now - timedelta(hours=2),
|
||||
category="agent",
|
||||
type="agent.heartbeat",
|
||||
severity="info",
|
||||
title="hb",
|
||||
summary="s",
|
||||
payload={},
|
||||
)
|
||||
)
|
||||
db_session.add(
|
||||
Event(
|
||||
event_id=str(uuid.uuid4()),
|
||||
host_id=fresh_host.id,
|
||||
occurred_at=now - timedelta(minutes=5),
|
||||
received_at=now - timedelta(minutes=5),
|
||||
category="agent",
|
||||
type="agent.heartbeat",
|
||||
severity="info",
|
||||
title="hb",
|
||||
summary="s",
|
||||
payload={},
|
||||
)
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
r = client.get("/api/v1/hosts?agent_status=stale", headers=jwt_headers)
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["total"] == 1
|
||||
assert body["items"][0]["hostname"] == "stale-pc"
|
||||
assert body["items"][0]["agent_status"] == "stale"
|
||||
|
||||
r_all = client.get("/api/v1/hosts", headers=jwt_headers)
|
||||
assert r_all.json()["total"] == 3
|
||||
|
||||
|
||||
def test_hosts_search_by_display_name(client, db_session, jwt_headers):
|
||||
h = Host(
|
||||
hostname="pc-01",
|
||||
|
||||
Reference in New Issue
Block a user