fix sankey counting duplication overwrite
This commit is contained in:
@@ -947,6 +947,7 @@ class DatabasePool:
|
||||
"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),
|
||||
"protocols": [],
|
||||
"_protocol_index": {},
|
||||
}
|
||||
iface_hosts[host_key] = host_record
|
||||
|
||||
@@ -956,22 +957,51 @@ class DatabasePool:
|
||||
record.get("eth_type_raw"),
|
||||
)
|
||||
if protocol_name not in (None, ""):
|
||||
host_record["protocols"].append(
|
||||
{
|
||||
"protocol": str(protocol_name),
|
||||
"packet_count": int(record.get("protocol_packet_count") or 0),
|
||||
"last_seen": record["protocol_last_seen"].isoformat()
|
||||
if hasattr(record.get("protocol_last_seen"), "isoformat")
|
||||
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_key = str(protocol_name)
|
||||
protocol_last_seen_raw = record.get("protocol_last_seen")
|
||||
protocol_last_seen = (
|
||||
protocol_last_seen_raw.isoformat()
|
||||
if hasattr(protocol_last_seen_raw, "isoformat")
|
||||
else protocol_last_seen_raw
|
||||
)
|
||||
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]] = []
|
||||
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(
|
||||
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 "")),
|
||||
|
||||
Reference in New Issue
Block a user