fix(servers/edit): retire le push iTop sur changement application (etait bloquant 10s+ si iTop injoignable) - update local seulement, push iTop dedie via endpoint async a faire si besoin

This commit is contained in:
Pierre & Lumière 2026-05-05 15:50:13 +02:00
parent 4b2a4cb8f2
commit c19309fec2
2 changed files with 6 additions and 25 deletions

View File

@ -176,39 +176,20 @@ async def server_update(request: Request, server_id: int, db=Depends(get_db),
} }
update_server(db, server_id, data, user.get("sub")) update_server(db, server_id, data, user.get("sub"))
# Application (changement manuel SecOps) — update + push iTop # Application (changement manuel SecOps) — update local seulement.
# Le push iTop est désactivé ici (peut bloquer 10s si iTop injoignable).
# Si besoin de pousser vers iTop, utiliser un endpoint dédié async.
if application_id is not None: if application_id is not None:
app_id_val = int(application_id) if application_id and application_id.strip().isdigit() else None app_id_val = int(application_id) if application_id and application_id.strip().isdigit() else None
app_itop_id = None
app_name = None app_name = None
if app_id_val: if app_id_val:
row = db.execute(text("SELECT itop_id, nom_court FROM applications WHERE id=:id"), row = db.execute(text("SELECT nom_court FROM applications WHERE id=:id"),
{"id": app_id_val}).fetchone() {"id": app_id_val}).fetchone()
if row: if row:
app_itop_id = row.itop_id
app_name = row.nom_court app_name = row.nom_court
db.execute(text("""UPDATE servers SET application_id=:aid, application_name=:an, updated_at=NOW() db.execute(text("""UPDATE servers SET application_id=:aid, application_name=:an, updated_at=NOW()
WHERE id=:sid"""), {"aid": app_id_val, "an": app_name, "sid": server_id}) WHERE id=:sid"""), {"aid": app_id_val, "an": app_name, "sid": server_id})
db.commit() db.commit()
# Push iTop (best effort)
try:
from ..services.itop_service import ITopClient
from ..services.secrets_service import get_secret
srv_row = db.execute(text("SELECT hostname FROM servers WHERE id=:id"), {"id": server_id}).fetchone()
if srv_row:
url = get_secret(db, "itop_url")
u = get_secret(db, "itop_user")
p = get_secret(db, "itop_pass")
if url and u and p:
client = ITopClient(url, u, p)
r = client._call("core/get", **{"class": "VirtualMachine",
"key": f'SELECT VirtualMachine WHERE name = "{srv_row.hostname}"', "output_fields": "name"})
if r.get("objects"):
vm_id = list(r["objects"].values())[0]["key"]
new_list = [{"applicationsolution_id": int(app_itop_id)}] if app_itop_id else []
client.update("VirtualMachine", vm_id, {"applicationsolution_list": new_list})
except Exception as e:
logger.warning(f"Erreur non bloquante: {e}")
s = get_server_full(db, server_id) s = get_server_full(db, server_id)
tags = get_server_tags(db, s.qid) tags = get_server_tags(db, s.qid)

View File

@ -71,7 +71,7 @@
</select> </select>
</div> </div>
<div> <div>
<label class="text-xs text-gray-500">Solution applicative (iTop) <span class="text-gray-600">— modifie aussi iTop</span></label> <label class="text-xs text-gray-500">Solution applicative <span class="text-gray-600">— modif locale uniquement</span></label>
<select name="application_id" class="w-full"> <select name="application_id" class="w-full">
<option value="">-- Aucune --</option> <option value="">-- Aucune --</option>
{% for a in applications %}<option value="{{ a.id }}" {% if a.id == s.application_id %}selected{% endif %}>{{ a.nom_court }}</option>{% endfor %} {% for a in applications %}<option value="{{ a.id }}" {% if a.id == s.application_id %}selected{% endif %}>{{ a.nom_court }}</option>{% endfor %}
@ -114,7 +114,7 @@
<button type="button" class="btn-sm bg-cyber-border text-gray-300 px-4 py-2" hx-get="/servers/{{ s.id }}/detail" hx-target="#detail-panel" hx-swap="innerHTML">Annuler</button> <button type="button" class="btn-sm bg-cyber-border text-gray-300 px-4 py-2" hx-get="/servers/{{ s.id }}/detail" hx-target="#detail-panel" hx-swap="innerHTML">Annuler</button>
</div> </div>
<div id="edit-indicator" class="htmx-indicator text-xs text-cyber-yellow pt-1"> <div id="edit-indicator" class="htmx-indicator text-xs text-cyber-yellow pt-1">
⏳ Sauvegarde en cours… (push iTop possible jusqu'à ~10s si réseau lent) ⏳ Sauvegarde en cours…
</div> </div>
</form> </form>
</div> </div>