fix empty null value db insert
This commit is contained in:
@@ -11,7 +11,7 @@ import subprocess
|
||||
import sys
|
||||
import threading
|
||||
from pathlib import Path
|
||||
from typing import Iterable, Optional
|
||||
from typing import Iterable, Mapping, Optional
|
||||
|
||||
from src.config import settings
|
||||
from src.utilities.packet_tracker import packet_tracker
|
||||
@@ -24,17 +24,33 @@ class BridgeTelemetryManager:
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._interfaces: set[str] = set()
|
||||
self._session_ids_by_interface: dict[str, tuple[str, ...]] = {}
|
||||
self._process: Optional[subprocess.Popen[str]] = None
|
||||
self._reader_thread: Optional[threading.Thread] = None
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def update_interfaces(self, interfaces: Iterable[str]) -> None:
|
||||
def update_sessions(self, session_interfaces: Mapping[str, Iterable[str]]) -> None:
|
||||
"""Restart the collector when the active bridge interface set changes."""
|
||||
normalized = {iface.strip() for iface in interfaces if iface and iface.strip()}
|
||||
normalized: dict[str, set[str]] = {}
|
||||
for session_id, interfaces in session_interfaces.items():
|
||||
if not session_id:
|
||||
continue
|
||||
iface_set = {iface.strip() for iface in interfaces if iface and iface.strip()}
|
||||
if iface_set:
|
||||
normalized[session_id] = iface_set
|
||||
|
||||
normalized_interfaces = sorted({iface for ifaces in normalized.values() for iface in ifaces})
|
||||
session_ids_by_interface = {
|
||||
iface: tuple(sorted(session_id for session_id, ifaces in normalized.items() if iface in ifaces))
|
||||
for iface in normalized_interfaces
|
||||
}
|
||||
|
||||
with self._lock:
|
||||
if normalized == self._interfaces:
|
||||
interfaces_changed = set(normalized_interfaces) != self._interfaces
|
||||
self._interfaces = set(normalized_interfaces)
|
||||
self._session_ids_by_interface = session_ids_by_interface
|
||||
if not interfaces_changed:
|
||||
return
|
||||
self._interfaces = normalized
|
||||
self._restart_locked()
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -123,11 +139,22 @@ class BridgeTelemetryManager:
|
||||
"skb_mark": event.get("skb_mark"),
|
||||
"capture_mode": "tc_ingress",
|
||||
}
|
||||
capture_iface = str(event.get("iface") or "")
|
||||
capture_session_id: Optional[str] = None
|
||||
with self._lock:
|
||||
session_ids = self._session_ids_by_interface.get(capture_iface, ())
|
||||
if session_ids:
|
||||
capture_session_id = session_ids[0]
|
||||
|
||||
try:
|
||||
from src.network_sniffer import parse_packet_bytes
|
||||
|
||||
parse_packet_bytes(packet_bytes, str(event.get("iface")), capture_metadata=capture_metadata)
|
||||
parse_packet_bytes(
|
||||
packet_bytes,
|
||||
capture_iface,
|
||||
capture_metadata=capture_metadata,
|
||||
capture_session_id=capture_session_id,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to process ingress raw packet event")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user