Qualys sync: fallback matching par IP integrer si hostname ne match pas
This commit is contained in:
parent
36c638c8ce
commit
55f81de986
@ -670,6 +670,14 @@ def _refresh_all_agents_impl(db):
|
|||||||
srv = db.execute(text("SELECT id FROM servers WHERE LOWER(hostname)=LOWER(:h)"),
|
srv = db.execute(text("SELECT id FROM servers WHERE LOWER(hostname)=LOWER(:h)"),
|
||||||
{"h": hostname}).fetchone()
|
{"h": hostname}).fetchone()
|
||||||
server_id = srv.id if srv else None
|
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:
|
if server_id and fqdn:
|
||||||
db.execute(text("UPDATE servers SET fqdn=:fqdn WHERE id=:sid AND (fqdn IS NULL OR fqdn='')"),
|
db.execute(text("UPDATE servers SET fqdn=:fqdn WHERE id=:sid AND (fqdn IS NULL OR fqdn='')"),
|
||||||
{"fqdn": fqdn, "sid": server_id})
|
{"fqdn": fqdn, "sid": server_id})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user