audit realtime: FQDN base = retour direct (plus de check port 22), boucle suffixes uniquement en fallback
This commit is contained in:
parent
09e92c8b70
commit
9b3840bfa6
@ -97,27 +97,20 @@ def _ordered_suffixes(hostname):
|
|||||||
|
|
||||||
|
|
||||||
def _resolve(hostname):
|
def _resolve(hostname):
|
||||||
# 1. Essaie d'abord le FQDN stocké en base (issu de Qualys ou iTop)
|
# 1. FQDN stocke en base - retour direct sans check port (rapide)
|
||||||
try:
|
try:
|
||||||
from .secrets_service import get_secret # noqa
|
|
||||||
from ..database import SessionLocal
|
from ..database import SessionLocal
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
row = db.execute(text("SELECT fqdn FROM servers WHERE LOWER(hostname)=LOWER(:h) AND fqdn IS NOT NULL AND fqdn != ''"),
|
row = db.execute(text(
|
||||||
{"h": hostname}).fetchone()
|
"SELECT fqdn FROM servers WHERE LOWER(hostname)=LOWER(:h) "
|
||||||
|
"AND fqdn IS NOT NULL AND fqdn != ''"
|
||||||
|
), {"h": hostname}).fetchone()
|
||||||
db.close()
|
db.close()
|
||||||
if row and row.fqdn:
|
if row and row.fqdn:
|
||||||
try:
|
return row.fqdn
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
sock.settimeout(2)
|
|
||||||
r = sock.connect_ex((row.fqdn, 22))
|
|
||||||
sock.close()
|
|
||||||
if r == 0:
|
|
||||||
return row.fqdn
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
# 2. Fallback : boucle sur les suffixes DNS
|
# 2. Fallback : boucle suffixes DNS (si FQDN manquant en base)
|
||||||
for suffix in _ordered_suffixes(hostname):
|
for suffix in _ordered_suffixes(hostname):
|
||||||
target = hostname + suffix
|
target = hostname + suffix
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user