feat(qualys/duplicates): filtre serveurs uniquement (exclut Win 10/11/7/8/XP postes)

This commit is contained in:
Pierre & Lumière 2026-04-25 10:23:14 +00:00
parent 3d043af194
commit e832381b68

View File

@ -1142,6 +1142,7 @@ def fetch_all_qualys_assets(db, with_progress=False):
aid = (parse_xml(block, "id") or [""])[0] aid = (parse_xml(block, "id") or [""])[0]
name = (parse_xml(block, "name") or [""])[0] name = (parse_xml(block, "name") or [""])[0]
addr = (parse_xml(block, "address") or [""])[0] addr = (parse_xml(block, "address") or [""])[0]
os_str = (parse_xml(block, "os") or [""])[0]
last_check = "" last_check = ""
if "<lastCheckedIn>" in block: if "<lastCheckedIn>" in block:
last_check = (parse_xml(block, "lastCheckedIn") or [""])[0] last_check = (parse_xml(block, "lastCheckedIn") or [""])[0]
@ -1149,7 +1150,7 @@ def fetch_all_qualys_assets(db, with_progress=False):
if "<agentInfo>" in block: if "<agentInfo>" in block:
agent_status = (parse_xml(block, "status") or [""])[0] agent_status = (parse_xml(block, "status") or [""])[0]
if aid and aid.isdigit(): if aid and aid.isdigit():
batch.append({"id": int(aid), "name": name, "ip": addr, batch.append({"id": int(aid), "name": name, "ip": addr, "os": os_str,
"last_check": last_check, "agent_status": agent_status}) "last_check": last_check, "agent_status": agent_status})
if not batch: if not batch:
break break
@ -1170,6 +1171,16 @@ def find_duplicate_hostnames(db, force_refresh=False):
from collections import defaultdict from collections import defaultdict
assets = fetch_all_qualys_assets(db) assets = fetch_all_qualys_assets(db)
# Filtrer les workstations (Windows 10/11/7/8/XP, MacOS Desktop) - on veut serveurs uniquement
WKS_PATTERNS = ("Windows 10", "Windows 11", "Windows 7", "Windows 8", "Windows XP",
"Windows Vista", "macOS")
def is_workstation(os_str):
if not os_str:
return False
# Server est explicite, sinon les patterns workstation
if "Server" in os_str:
return False
return any(p in os_str for p in WKS_PATTERNS)
groups = defaultdict(list) groups = defaultdict(list)
for a in assets: for a in assets:
shortname = a["name"].split(".")[0].lower() if a["name"] else "" shortname = a["name"].split(".")[0].lower() if a["name"] else ""
@ -1178,6 +1189,9 @@ def find_duplicate_hostnames(db, force_refresh=False):
# Filtrer les hostnames qui sont des IP (ex: "192", "10") # Filtrer les hostnames qui sont des IP (ex: "192", "10")
if shortname.replace(".", "").isdigit(): if shortname.replace(".", "").isdigit():
continue continue
# Filtrer les workstations
if is_workstation(a.get("os", "")):
continue
groups[shortname].append(a) groups[shortname].append(a)
dupes = [] dupes = []