fix sankey counting duplication overwrite
All checks were successful
Build and Deploy MITM Webserver / traffic_target (push) Successful in 1s
Build and Deploy MITM Webserver / build (push) Successful in 11s

This commit is contained in:
2026-03-30 23:00:37 +02:00
parent cb73cbac09
commit 84fa1d3628

View File

@@ -947,6 +947,7 @@ class DatabasePool:
"source_on_ingress_count": int(record.get("source_on_ingress_count") or 0), "source_on_ingress_count": int(record.get("source_on_ingress_count") or 0),
"destination_on_egress_count": int(record.get("destination_on_egress_count") or 0), "destination_on_egress_count": int(record.get("destination_on_egress_count") or 0),
"protocols": [], "protocols": [],
"_protocol_index": {},
} }
iface_hosts[host_key] = host_record iface_hosts[host_key] = host_record
@@ -956,22 +957,51 @@ class DatabasePool:
record.get("eth_type_raw"), record.get("eth_type_raw"),
) )
if protocol_name not in (None, ""): if protocol_name not in (None, ""):
host_record["protocols"].append( protocol_key = str(protocol_name)
{ protocol_last_seen_raw = record.get("protocol_last_seen")
"protocol": str(protocol_name), protocol_last_seen = (
"packet_count": int(record.get("protocol_packet_count") or 0), protocol_last_seen_raw.isoformat()
"last_seen": record["protocol_last_seen"].isoformat() if hasattr(protocol_last_seen_raw, "isoformat")
if hasattr(record.get("protocol_last_seen"), "isoformat") else protocol_last_seen_raw
else record.get("protocol_last_seen"),
"accept_count": int(record.get("accept_count") or 0),
"drop_count": int(record.get("drop_count") or 0),
"reject_count": int(record.get("reject_count") or 0),
"unknown_count": int(record.get("unknown_count") or 0),
}
) )
protocol_index = host_record["_protocol_index"]
protocol_record = protocol_index.get(protocol_key)
if protocol_record is None:
protocol_record = {
"protocol": protocol_key,
"packet_count": 0,
"last_seen": protocol_last_seen,
"accept_count": 0,
"drop_count": 0,
"reject_count": 0,
"unknown_count": 0,
}
protocol_index[protocol_key] = protocol_record
host_record["protocols"].append(protocol_record)
protocol_record["packet_count"] += int(record.get("protocol_packet_count") or 0)
protocol_record["accept_count"] += int(record.get("accept_count") or 0)
protocol_record["drop_count"] += int(record.get("drop_count") or 0)
protocol_record["reject_count"] += int(record.get("reject_count") or 0)
protocol_record["unknown_count"] += int(record.get("unknown_count") or 0)
if protocol_last_seen and (
protocol_record.get("last_seen") in (None, "")
or str(protocol_last_seen) > str(protocol_record.get("last_seen"))
):
protocol_record["last_seen"] = protocol_last_seen
result: List[Dict[str, Any]] = [] result: List[Dict[str, Any]] = []
for iface, hosts in sorted(grouped.items()): for iface, hosts in sorted(grouped.items()):
for host in hosts.values():
host.pop("_protocol_index", None)
host["protocols"] = sorted(
host["protocols"],
key=lambda item: (
-int(item.get("packet_count") or 0),
str(item.get("last_seen") or ""),
str(item.get("protocol") or ""),
),
)
sorted_hosts = sorted( sorted_hosts = sorted(
hosts.values(), hosts.values(),
key=lambda item: (-int(item.get("packet_count") or 0), str(item.get("last_seen") or ""), str(item.get("ip_address") or ""), str(item.get("mac_address") or "")), key=lambda item: (-int(item.get("packet_count") or 0), str(item.get("last_seen") or ""), str(item.get("ip_address") or ""), str(item.get("mac_address") or "")),