diff --git a/app/services/qualys_service.py b/app/services/qualys_service.py index 03eecd6..872b5a6 100644 --- a/app/services/qualys_service.py +++ b/app/services/qualys_service.py @@ -670,6 +670,14 @@ def _refresh_all_agents_impl(db): srv = db.execute(text("SELECT id FROM servers WHERE LOWER(hostname)=LOWER(:h)"), {"h": hostname}).fetchone() server_id = srv.id if srv else None + # Fallback : matching par IP si hostname ne match pas + if not server_id and address: + ip_match = db.execute(text( + "SELECT s.id FROM servers s JOIN server_ips si ON si.server_id=s.id " + "WHERE si.ip_address = CAST(:ip AS inet) LIMIT 1" + ), {"ip": address}).fetchone() + if ip_match: + server_id = ip_match.id if server_id and fqdn: db.execute(text("UPDATE servers SET fqdn=:fqdn WHERE id=:sid AND (fqdn IS NULL OR fqdn='')"), {"fqdn": fqdn, "sid": server_id})