Qualys sync multi-pass: filtres SRV/server/SED/SEI/EMV pour couvrir tags heterogenes
This commit is contained in:
parent
2746188f1c
commit
1a1af9e28a
@ -574,7 +574,7 @@ def _refresh_all_agents_impl(db):
|
||||
|
||||
stats = {"created": 0, "updated": 0, "errors": 0, "pages": 0}
|
||||
last_id = None
|
||||
max_pages = 20 # garde-fou
|
||||
max_pages = 30 # garde-fou par filtre (multi-pass = max_pages * nb_filtres)
|
||||
|
||||
# Autocommit sur la session courante
|
||||
try:
|
||||
@ -582,15 +582,22 @@ def _refresh_all_agents_impl(db):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
while stats["pages"] < max_pages:
|
||||
# Multi-pass : plusieurs filtres tagName CONTAINS pour couvrir la
|
||||
# nomenclature heterogene (SRV, server, SED, SEI, EMV...).
|
||||
# Doublons gere par ON CONFLICT/UPDATE sur qualys_asset_id.
|
||||
tag_filters = ["SRV", "server", "SED", "SEI", "EMV"]
|
||||
current_filter_idx = 0
|
||||
last_id = None
|
||||
|
||||
while current_filter_idx < len(tag_filters):
|
||||
tag_filter = tag_filters[current_filter_idx]
|
||||
if _refresh_cancel.is_set():
|
||||
stats["ok"] = True
|
||||
stats["cancelled"] = True
|
||||
stats["msg"] = f"Annulé après {stats['pages']} pages: {stats['created']} créés, {stats['updated']} mis à jour"
|
||||
stats["msg"] = f"Annulé apres {stats['pages']} pages (filtre={tag_filter}): {stats['created']} créés, {stats['updated']} mis à jour"
|
||||
return stats
|
||||
stats["pages"] += 1
|
||||
# CONTAINS SRV matche OS-WIN-SRV DYN / OS-LIN-SRV DYN (nomenclature SANEF v3)
|
||||
criteria = [{"field": "tagName", "operator": "CONTAINS", "value": "SRV"}]
|
||||
criteria = [{"field": "tagName", "operator": "CONTAINS", "value": tag_filter}]
|
||||
if last_id:
|
||||
criteria.append({"field": "id", "operator": "GREATER", "value": str(last_id)})
|
||||
payload = {"ServiceRequest": {
|
||||
@ -710,14 +717,15 @@ def _refresh_all_agents_impl(db):
|
||||
|
||||
db.commit()
|
||||
|
||||
if "<hasMoreRecords>true</hasMoreRecords>" not in r.text:
|
||||
break
|
||||
if new_last_id == last_id:
|
||||
break
|
||||
# Filtre actuel: page suivante OU passe au prochain filtre
|
||||
if "<hasMoreRecords>true</hasMoreRecords>" not in r.text or new_last_id == last_id:
|
||||
current_filter_idx += 1
|
||||
last_id = None
|
||||
else:
|
||||
last_id = new_last_id
|
||||
|
||||
stats["ok"] = True
|
||||
stats["msg"] = f"{stats['created']} créés, {stats['updated']} mis à jour ({stats['pages']} pages, {stats['errors']} erreurs)"
|
||||
stats["msg"] = f"{stats['created']} créés, {stats['updated']} mis à jour ({stats['pages']} pages, {stats['errors']} erreurs, {len(tag_filters)} filtres)"
|
||||
return stats
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user