diff --git a/app/routers/audit_full.py b/app/routers/audit_full.py index 9bd5b57..df8e657 100644 --- a/app/routers/audit_full.py +++ b/app/routers/audit_full.py @@ -54,9 +54,12 @@ async def audit_full_list(request: Request, db=Depends(get_db)): AND id IN (SELECT DISTINCT ON (hostname) id FROM server_audit_full WHERE status = 'ok' ORDER BY hostname, audit_date DESC) """)).fetchone() - # Domaines pour le filtre + # Domaines + zones pour le filtre all_domains = db.execute(text( - "SELECT code, name FROM domains ORDER BY name" + "SELECT code, name, 'domain' as type FROM domains ORDER BY name" + )).fetchall() + all_zones = db.execute(text( + "SELECT name as code, name, 'zone' as type FROM zones ORDER BY name" )).fetchall() # Requete avec filtres @@ -84,15 +87,25 @@ async def audit_full_list(request: Request, db=Depends(get_db)): elif filtre == "uptime": audits = [a for a in audits if a.uptime and ("month" in a.uptime or "year" in a.uptime)] - # Filtre domaine + # Filtre domaine ou zone if domain: - domain_servers = {r.hostname for r in db.execute(text(""" + # D'abord chercher comme zone + zone_servers = {r.hostname for r in db.execute(text(""" SELECT s.hostname FROM servers s - JOIN domain_environments de ON s.domain_env_id = de.id - JOIN domains d ON de.domain_id = d.id - WHERE d.code = :dc - """), {"dc": domain}).fetchall()} - audits = [a for a in audits if a.hostname in domain_servers] + JOIN zones z ON s.zone_id = z.id + WHERE z.name = :name + """), {"name": domain}).fetchall()} + if zone_servers: + audits = [a for a in audits if a.hostname in zone_servers] + else: + # Sinon chercher comme domaine + domain_servers = {r.hostname for r in db.execute(text(""" + SELECT s.hostname FROM servers s + JOIN domain_environments de ON s.domain_env_id = de.id + JOIN domains d ON de.domain_id = d.id + WHERE d.code = :dc + """), {"dc": domain}).fetchall()} + audits = [a for a in audits if a.hostname in domain_servers] # Recherche hostname if search: @@ -109,7 +122,7 @@ async def audit_full_list(request: Request, db=Depends(get_db)): ctx.update({ "app_name": APP_NAME, "audits": audits_page, "kpis": kpis, "filter": filtre, "search": search, "domain": domain, - "all_domains": all_domains, + "all_domains": all_domains, "all_zones": all_zones, "page": page, "total_pages": total_pages, "total_filtered": total_filtered, "msg": request.query_params.get("msg"), }) diff --git a/app/templates/audit_full_list.html b/app/templates/audit_full_list.html index 1bd61b7..c034e9d 100644 --- a/app/templates/audit_full_list.html +++ b/app/templates/audit_full_list.html @@ -58,8 +58,13 @@ {% if filter %}{% endif %} {% if search or domain %}Reset{% endif %}