Implement DNS caching and verbose logging
All checks were successful
Build and Release / Build Windows Exe (push) Successful in 10s
All checks were successful
Build and Release / Build Windows Exe (push) Successful in 10s
This commit is contained in:
@@ -39,13 +39,20 @@ def generate_inventory(servers: Dict[str, Server], flows: List[Flow]) -> Dict[st
|
||||
# Process flows
|
||||
match_count = 0
|
||||
drop_count = 0
|
||||
total_flows = len(flows)
|
||||
|
||||
for flow in flows:
|
||||
print(f"Starting inventory generation for {total_flows} flows...")
|
||||
|
||||
for idx, flow in enumerate(flows, 1):
|
||||
if idx % 10 == 0:
|
||||
print(f"Processing flow {idx}/{total_flows}...")
|
||||
|
||||
# Find source server
|
||||
server = ip_to_server.get(flow.source_ip)
|
||||
|
||||
if not server:
|
||||
# Try DNS resolution (Public IP -> Management FQDN)
|
||||
print(f"Flow {idx}: Source {flow.source_ip} not found in map. Attempting DNS resolution...")
|
||||
mgt_dns = to_mgt_ip(flow.source_ip)
|
||||
if mgt_dns:
|
||||
# mgt_dns might be "server.ds.gc.ca".
|
||||
@@ -60,9 +67,11 @@ def generate_inventory(servers: Dict[str, Server], flows: List[Flow]) -> Dict[st
|
||||
|
||||
if not server:
|
||||
drop_count += 1
|
||||
if drop_count <= 5: # Debug spam limit
|
||||
print(f"Dropping flow {flow.flow_id}: Source {flow.source_ip} (Mgt: {mgt_dns}) not found in Servers tab.")
|
||||
if drop_count <= 10: # Increased debug spam limit
|
||||
print(f"Dropping flow {flow.flow_id} ({idx}/{total_flows}): Source {flow.source_ip} (Mgt: {mgt_dns}) resolved but not found in Servers tab.")
|
||||
continue
|
||||
else:
|
||||
print(f"Flow {idx}: Resolved {flow.source_ip} -> {server.hostname or server.reference}")
|
||||
|
||||
match_count += 1
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import socket
|
||||
from typing import Optional
|
||||
from functools import lru_cache
|
||||
|
||||
@lru_cache(maxsize=1024)
|
||||
def get_hostname(ip: str) -> Optional[str]:
|
||||
try:
|
||||
# Python's equivalent to Resolv.getname(ip)
|
||||
@@ -9,6 +11,7 @@ def get_hostname(ip: str) -> Optional[str]:
|
||||
except socket.error:
|
||||
return None
|
||||
|
||||
@lru_cache(maxsize=1024)
|
||||
def get_ip(hostname: str) -> Optional[str]:
|
||||
try:
|
||||
return socket.gethostbyname(hostname)
|
||||
|
||||
Reference in New Issue
Block a user