feat: drill-down filters on overview and outdated agent version highlight
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
"""Problems correlation and API smoke tests."""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from tests.test_ingest import VALID_EVENT
|
||||
from app.models import Host, Problem
|
||||
|
||||
|
||||
def _event_payload(**overrides):
|
||||
@@ -67,3 +67,101 @@ def test_new_problem_after_resolve(client, auth_headers, jwt_headers):
|
||||
assert len(open_items) == 1
|
||||
assert open_items[0]["event_count"] == 1
|
||||
assert open_items[0]["id"] != pid
|
||||
|
||||
|
||||
def test_problems_created_within_hours(client, db_session, jwt_headers):
|
||||
now = datetime.now(timezone.utc)
|
||||
h = Host(
|
||||
hostname="p-host",
|
||||
os_family="linux",
|
||||
product="ssh-monitor",
|
||||
last_seen_at=now,
|
||||
)
|
||||
db_session.add(h)
|
||||
db_session.flush()
|
||||
db_session.add(
|
||||
Problem(
|
||||
host_id=h.id,
|
||||
title="recent",
|
||||
summary="s",
|
||||
severity="warning",
|
||||
status="open",
|
||||
rule_id="rule:test",
|
||||
fingerprint="fp-recent",
|
||||
event_count=1,
|
||||
last_seen_at=now,
|
||||
created_at=now - timedelta(hours=2),
|
||||
updated_at=now - timedelta(hours=2),
|
||||
)
|
||||
)
|
||||
db_session.add(
|
||||
Problem(
|
||||
host_id=h.id,
|
||||
title="old",
|
||||
summary="s",
|
||||
severity="warning",
|
||||
status="resolved",
|
||||
rule_id="rule:test",
|
||||
fingerprint="fp-old",
|
||||
event_count=1,
|
||||
last_seen_at=now,
|
||||
created_at=now - timedelta(days=3),
|
||||
updated_at=now - timedelta(days=2),
|
||||
)
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
r = client.get("/api/v1/problems?created_within_hours=24", headers=jwt_headers)
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["total"] == 1
|
||||
assert body["items"][0]["title"] == "recent"
|
||||
|
||||
|
||||
def test_problems_resolved_within_hours(client, db_session, jwt_headers):
|
||||
now = datetime.now(timezone.utc)
|
||||
h = Host(
|
||||
hostname="r-host",
|
||||
os_family="linux",
|
||||
product="ssh-monitor",
|
||||
last_seen_at=now,
|
||||
)
|
||||
db_session.add(h)
|
||||
db_session.flush()
|
||||
db_session.add(
|
||||
Problem(
|
||||
host_id=h.id,
|
||||
title="closed today",
|
||||
summary="s",
|
||||
severity="warning",
|
||||
status="resolved",
|
||||
rule_id="rule:test",
|
||||
fingerprint="fp-closed-today",
|
||||
event_count=1,
|
||||
last_seen_at=now,
|
||||
created_at=now - timedelta(days=2),
|
||||
updated_at=now - timedelta(hours=1),
|
||||
)
|
||||
)
|
||||
db_session.add(
|
||||
Problem(
|
||||
host_id=h.id,
|
||||
title="closed long ago",
|
||||
summary="s",
|
||||
severity="warning",
|
||||
status="resolved",
|
||||
rule_id="rule:test",
|
||||
fingerprint="fp-closed-old",
|
||||
event_count=1,
|
||||
last_seen_at=now,
|
||||
created_at=now - timedelta(days=10),
|
||||
updated_at=now - timedelta(days=5),
|
||||
)
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
r = client.get("/api/v1/problems?resolved_within_hours=24", headers=jwt_headers)
|
||||
assert r.status_code == 200
|
||||
body = r.json()
|
||||
assert body["total"] == 1
|
||||
assert body["items"][0]["title"] == "closed today"
|
||||
|
||||
Reference in New Issue
Block a user