fix visu error api
This commit is contained in:
@@ -95,7 +95,7 @@ async def analysis_interface_hosts(
|
|||||||
try:
|
try:
|
||||||
rows = await db.infer_interface_hosts(since=since, limit_per_interface=limit_per_interface)
|
rows = await db.infer_interface_hosts(since=since, limit_per_interface=limit_per_interface)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail="Failed to infer interface host mapping") from exc
|
raise HTTPException(status_code=500, detail=f"Failed to infer interface host mapping: {exc}") from exc
|
||||||
|
|
||||||
interfaces = [InterfaceAttachment(**row) for row in rows]
|
interfaces = [InterfaceAttachment(**row) for row in rows]
|
||||||
return InterfaceHostAnalysisResponse(since=since, interfaces=interfaces)
|
return InterfaceHostAnalysisResponse(since=since, interfaces=interfaces)
|
||||||
@@ -138,7 +138,7 @@ async def analysis_interface_host_protocols(
|
|||||||
limit_protocols_per_host=limit_protocols_per_host,
|
limit_protocols_per_host=limit_protocols_per_host,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
raise HTTPException(status_code=500, detail="Failed to infer interface host protocol mapping") from exc
|
raise HTTPException(status_code=500, detail=f"Failed to infer interface host protocol mapping: {exc}") from exc
|
||||||
|
|
||||||
interfaces = [InterfaceProtocolAttachment(**row) for row in rows]
|
interfaces = [InterfaceProtocolAttachment(**row) for row in rows]
|
||||||
return InterfaceHostProtocolAnalysisResponse(since=since, interfaces=interfaces)
|
return InterfaceHostProtocolAnalysisResponse(since=since, interfaces=interfaces)
|
||||||
|
|||||||
@@ -642,9 +642,10 @@ class DatabasePool:
|
|||||||
if self._pool is None:
|
if self._pool is None:
|
||||||
await self.init_pool()
|
await self.init_pool()
|
||||||
|
|
||||||
async with self._pool.acquire() as conn:
|
try:
|
||||||
rows = await conn.fetch(
|
async with self._pool.acquire() as conn:
|
||||||
"""
|
rows = await conn.fetch(
|
||||||
|
"""
|
||||||
WITH observations AS (
|
WITH observations AS (
|
||||||
SELECT
|
SELECT
|
||||||
ingress_if AS iface,
|
ingress_if AS iface,
|
||||||
@@ -713,9 +714,12 @@ class DatabasePool:
|
|||||||
WHERE row_num <= $2
|
WHERE row_num <= $2
|
||||||
ORDER BY iface, packet_count DESC, last_seen DESC, ip_address, mac_address
|
ORDER BY iface, packet_count DESC, last_seen DESC, ip_address, mac_address
|
||||||
""",
|
""",
|
||||||
since,
|
since,
|
||||||
limit_per_interface,
|
limit_per_interface,
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("DB interface-host analysis failed")
|
||||||
|
raise
|
||||||
|
|
||||||
grouped: Dict[str, List[Dict[str, Any]]] = {}
|
grouped: Dict[str, List[Dict[str, Any]]] = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
@@ -744,16 +748,17 @@ class DatabasePool:
|
|||||||
if self._pool is None:
|
if self._pool is None:
|
||||||
await self.init_pool()
|
await self.init_pool()
|
||||||
|
|
||||||
async with self._pool.acquire() as conn:
|
try:
|
||||||
rows = await conn.fetch(
|
async with self._pool.acquire() as conn:
|
||||||
"""
|
rows = await conn.fetch(
|
||||||
|
"""
|
||||||
WITH observations AS (
|
WITH observations AS (
|
||||||
SELECT
|
SELECT
|
||||||
ingress_if AS iface,
|
ingress_if AS iface,
|
||||||
src_ip::text AS ip_address,
|
src_ip::text AS ip_address,
|
||||||
src_mac::text AS mac_address,
|
src_mac::text AS mac_address,
|
||||||
COALESCE(NULLIF(app_protocol, ''), NULLIF(app_master_protocol, ''), NULLIF(ip_proto, ''), NULLIF(eth_type, ''), 'UNKNOWN') AS protocol_name,
|
COALESCE(NULLIF(app_protocol::text, ''), NULLIF(app_master_protocol::text, ''), NULLIF(ip_proto::text, ''), NULLIF(eth_type::text, ''), 'UNKNOWN') AS protocol_name,
|
||||||
COALESCE(NULLIF(verdict, ''), 'unknown') AS verdict_name,
|
COALESCE(NULLIF(verdict::text, ''), 'unknown') AS verdict_name,
|
||||||
timestamp,
|
timestamp,
|
||||||
'source_on_ingress' AS evidence
|
'source_on_ingress' AS evidence
|
||||||
FROM packets
|
FROM packets
|
||||||
@@ -767,8 +772,8 @@ class DatabasePool:
|
|||||||
egress_if AS iface,
|
egress_if AS iface,
|
||||||
dst_ip::text AS ip_address,
|
dst_ip::text AS ip_address,
|
||||||
dst_mac::text AS mac_address,
|
dst_mac::text AS mac_address,
|
||||||
COALESCE(NULLIF(app_protocol, ''), NULLIF(app_master_protocol, ''), NULLIF(ip_proto, ''), NULLIF(eth_type, ''), 'UNKNOWN') AS protocol_name,
|
COALESCE(NULLIF(app_protocol::text, ''), NULLIF(app_master_protocol::text, ''), NULLIF(ip_proto::text, ''), NULLIF(eth_type::text, ''), 'UNKNOWN') AS protocol_name,
|
||||||
COALESCE(NULLIF(verdict, ''), 'unknown') AS verdict_name,
|
COALESCE(NULLIF(verdict::text, ''), 'unknown') AS verdict_name,
|
||||||
timestamp,
|
timestamp,
|
||||||
'destination_on_egress' AS evidence
|
'destination_on_egress' AS evidence
|
||||||
FROM packets
|
FROM packets
|
||||||
@@ -872,11 +877,14 @@ class DatabasePool:
|
|||||||
ranked_protocols.packet_count DESC NULLS LAST,
|
ranked_protocols.packet_count DESC NULLS LAST,
|
||||||
ranked_protocols.last_seen DESC NULLS LAST,
|
ranked_protocols.last_seen DESC NULLS LAST,
|
||||||
ranked_protocols.protocol_name
|
ranked_protocols.protocol_name
|
||||||
""",
|
""",
|
||||||
since,
|
since,
|
||||||
limit_per_interface,
|
limit_per_interface,
|
||||||
limit_protocols_per_host,
|
limit_protocols_per_host,
|
||||||
)
|
)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("DB interface-host-protocol analysis failed")
|
||||||
|
raise
|
||||||
|
|
||||||
grouped: Dict[str, Dict[str, Dict[str, Any]]] = {}
|
grouped: Dict[str, Dict[str, Dict[str, Any]]] = {}
|
||||||
for row in rows:
|
for row in rows:
|
||||||
|
|||||||
Reference in New Issue
Block a user