Add pagination to event queries, input validation, daily event purge
- get_active_events() now takes limit/offset (default 200) to cap unbounded queries - count_active_events() added to return total for pagination display - /api/events supports ?limit=, ?offset=, ?status= query params (max 1000) - /api/status includes total_active count alongside paginated events list - index() route passes total_active to template for server-side truncation notice - Show "Showing X of Y" notice in dashboard when events are truncated - Suppression POST validates: reason ≤500 chars, target_name/detail ≤255 chars - _purge_old_jobs_loop runs purge_old_resolved_events(90d) once per day Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
16
db.py
16
db.py
@@ -153,7 +153,7 @@ def set_ticket_id(event_id: int, ticket_id: str) -> None:
|
||||
)
|
||||
|
||||
|
||||
def get_active_events() -> list:
|
||||
def get_active_events(limit: int = 200, offset: int = 0) -> list:
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
@@ -161,7 +161,9 @@ def get_active_events() -> list:
|
||||
WHERE resolved_at IS NULL
|
||||
ORDER BY
|
||||
FIELD(severity,'critical','warning','info'),
|
||||
first_seen DESC"""
|
||||
first_seen DESC
|
||||
LIMIT %s OFFSET %s""",
|
||||
(limit, offset),
|
||||
)
|
||||
rows = cur.fetchall()
|
||||
for r in rows:
|
||||
@@ -171,6 +173,16 @@ def get_active_events() -> list:
|
||||
return rows
|
||||
|
||||
|
||||
def count_active_events() -> int:
|
||||
"""Return count of all unresolved events (for pagination)."""
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
"SELECT COUNT(*) AS n FROM network_events WHERE resolved_at IS NULL"
|
||||
)
|
||||
return cur.fetchone()['n']
|
||||
|
||||
|
||||
def get_recent_resolved(hours: int = 24, limit: int = 50) -> list:
|
||||
with get_conn() as conn:
|
||||
with conn.cursor() as cur:
|
||||
|
||||
Reference in New Issue
Block a user