Fix sync iTop: champs corrects (patch_window, contacts.role, ssh_method constraint, rollback)
This commit is contained in:
parent
be6c5158b8
commit
322fa71324
@ -48,6 +48,12 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
stats = {"contacts": 0, "domains": 0, "environments": 0, "zones": 0,
|
||||
"servers_created": 0, "servers_updated": 0, "errors": []}
|
||||
|
||||
# Reset any failed transaction
|
||||
try:
|
||||
db.rollback()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# ─── 1. Contacts (Person) ───
|
||||
persons = client.get_all("Person", "name,first_name,email,phone,org_name,function")
|
||||
for p in persons:
|
||||
@ -55,14 +61,15 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
existing = db.execute(text("SELECT id FROM contacts WHERE LOWER(email) = LOWER(:e)"),
|
||||
{"e": p.get("email", "")}).fetchone()
|
||||
if existing:
|
||||
db.execute(text("UPDATE contacts SET nom=:n, telephone=:t, updated_at=NOW() WHERE id=:id"),
|
||||
{"id": existing.id, "n": fullname, "t": p.get("phone", "")})
|
||||
db.execute(text("UPDATE contacts SET name=:n, updated_at=NOW() WHERE id=:id"),
|
||||
{"id": existing.id, "n": fullname})
|
||||
else:
|
||||
try:
|
||||
db.execute(text("INSERT INTO contacts (nom, email, telephone) VALUES (:n, :e, :t)"),
|
||||
{"n": fullname, "e": p.get("email", ""), "t": p.get("phone", "")})
|
||||
db.execute(text("INSERT INTO contacts (name, email, role) VALUES (:n, :e, 'referent_technique')"),
|
||||
{"n": fullname, "e": p.get("email", "")})
|
||||
stats["contacts"] += 1
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
stats["errors"].append(f"Contact {fullname}: {e}")
|
||||
|
||||
# ─── 2. Domaines applicatifs (typology via VMs) ───
|
||||
@ -70,12 +77,12 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
"name,description,status,managementip,osfamily_id_friendlyname,"
|
||||
"osversion_id_friendlyname,organization_name,cpu,ram,"
|
||||
"responsable_serveur_name,responsable_domaine_name,"
|
||||
"environnement,environnement_name,"
|
||||
"environnement_name,"
|
||||
"domaine_applicatif_name,zone_name,"
|
||||
"applicationsolution_list,contacts_list,"
|
||||
"contacts_list,"
|
||||
"virtualhost_name,business_criticity,"
|
||||
"tier_name,connexion_method_name,ssh_user_name,"
|
||||
"patch_frequency_name,pref_patch_jour_name,pref_patch_heure_name,"
|
||||
"patch_frequency_name,pref_patch_jour_name,patch_window,"
|
||||
"patch_excludes,domain_ldap_name,last_patch_date")
|
||||
|
||||
# Also get physical Servers
|
||||
@ -190,7 +197,7 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
|
||||
# Map pref_patch_jour/heure
|
||||
pref_jour = (v.get("pref_patch_jour_name", "") or "").lower() or "indifferent"
|
||||
pref_heure = v.get("pref_patch_heure_name", "") or "indifferent"
|
||||
pref_heure = v.get("patch_window", "") or "indifferent"
|
||||
|
||||
vals = {
|
||||
"hostname": hostname,
|
||||
@ -248,6 +255,7 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
"""), vals)
|
||||
stats["servers_created"] += 1
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
stats["errors"].append(f"Server {hostname}: {e}")
|
||||
|
||||
# ─── 8. Insert physical servers ───
|
||||
@ -274,6 +282,7 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
})
|
||||
stats["servers_created"] += 1
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
stats["errors"].append(f"Physical {hostname}: {e}")
|
||||
|
||||
db.commit()
|
||||
|
||||
@ -439,7 +439,7 @@
|
||||
<button @click="open = open === 'itop' ? '' : 'itop'" class="w-full flex items-center justify-between p-4 hover:bg-cyber-border/20 transition-colors">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-gray-400 font-bold">iTop CMDB</span>
|
||||
<span class="badge badge-gray">En attente</span>
|
||||
<span class="badge badge-green">Configuré</span>
|
||||
</div>
|
||||
<span class="text-gray-500 text-lg" x-text="open === 'itop' ? '▼' : '▶'"></span>
|
||||
</button>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user