feat(qualys/duplicates): filtre serveurs uniquement (exclut Win 10/11/7/8/XP postes)
This commit is contained in:
parent
3d043af194
commit
e832381b68
@ -1142,6 +1142,7 @@ def fetch_all_qualys_assets(db, with_progress=False):
|
||||
aid = (parse_xml(block, "id") or [""])[0]
|
||||
name = (parse_xml(block, "name") or [""])[0]
|
||||
addr = (parse_xml(block, "address") or [""])[0]
|
||||
os_str = (parse_xml(block, "os") or [""])[0]
|
||||
last_check = ""
|
||||
if "<lastCheckedIn>" in block:
|
||||
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:
|
||||
agent_status = (parse_xml(block, "status") or [""])[0]
|
||||
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})
|
||||
if not batch:
|
||||
break
|
||||
@ -1170,6 +1171,16 @@ def find_duplicate_hostnames(db, force_refresh=False):
|
||||
|
||||
from collections import defaultdict
|
||||
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)
|
||||
for a in assets:
|
||||
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")
|
||||
if shortname.replace(".", "").isdigit():
|
||||
continue
|
||||
# Filtrer les workstations
|
||||
if is_workstation(a.get("os", "")):
|
||||
continue
|
||||
groups[shortname].append(a)
|
||||
|
||||
dupes = []
|
||||
|
||||
Loading…
Reference in New Issue
Block a user