Fix: lire Etat en priorite (Status toujours Production, inutile) + condition -> NULL
This commit is contained in:
parent
56f91ca9a8
commit
ce2ac219db
@ -116,24 +116,31 @@ def main():
|
|||||||
hostname = (r.get("Nom") or r.get("Hostname") or "").strip()
|
hostname = (r.get("Nom") or r.get("Hostname") or "").strip()
|
||||||
if not hostname or not any(c.isalpha() for c in hostname):
|
if not hostname or not any(c.isalpha() for c in hostname):
|
||||||
continue
|
continue
|
||||||
# Lit Status (lifecycle iTop) en priorite, fallback Etat
|
# Etat d'abord (lifecycle VM). Si valeur "condition" -> NULL.
|
||||||
raw = (r.get("Status") or r.get("Etat") or r.get("État") or "").strip()
|
# Status ignore (toujours 'Production' cote iTop, pas pertinent).
|
||||||
|
raw = (r.get("Etat") or r.get("État") or "").strip()
|
||||||
new_etat = norm_etat(raw)
|
new_etat = norm_etat(raw)
|
||||||
if raw and new_etat is None and raw not in ("-", "(null)"):
|
# Cas: valeur condition iTop (Nouveau, Recycle, ...) -> NULL (physique non deploye)
|
||||||
|
is_condition = raw in ("Nouveau", "Recyclé", "A récupérer", "Cassé",
|
||||||
|
"Cédé", "En panne", "Perdu", "Occasion",
|
||||||
|
"A détruire", "Volé")
|
||||||
|
if raw and new_etat is None and not is_condition and raw not in ("-", "(null)"):
|
||||||
unknown.add(raw); continue
|
unknown.add(raw); continue
|
||||||
if new_etat is None:
|
# is_condition -> force NULL ; valeur vide -> skip
|
||||||
|
if new_etat is None and not is_condition:
|
||||||
continue
|
continue
|
||||||
|
target = new_etat # None si is_condition
|
||||||
srv = conn.execute(text("SELECT id, etat FROM servers WHERE hostname=:h"),
|
srv = conn.execute(text("SELECT id, etat FROM servers WHERE hostname=:h"),
|
||||||
{"h": hostname}).fetchone()
|
{"h": hostname}).fetchone()
|
||||||
if not srv:
|
if not srv:
|
||||||
not_found += 1; continue
|
not_found += 1; continue
|
||||||
if srv.etat == new_etat:
|
if srv.etat == target:
|
||||||
unchanged += 1; continue
|
unchanged += 1; continue
|
||||||
if args.dry_run:
|
if args.dry_run:
|
||||||
print(f" DRY: {hostname} {srv.etat} -> {new_etat}")
|
print(f" DRY: {hostname} {srv.etat} -> {target or 'NULL'}")
|
||||||
else:
|
else:
|
||||||
conn.execute(text("UPDATE servers SET etat=:e WHERE id=:sid"),
|
conn.execute(text("UPDATE servers SET etat=:e WHERE id=:sid"),
|
||||||
{"e": new_etat, "sid": srv.id})
|
{"e": target, "sid": srv.id})
|
||||||
updated += 1
|
updated += 1
|
||||||
print(f"\n[DONE] Maj CSV: {updated} | Inchanges: {unchanged} | Hors base: {not_found}")
|
print(f"\n[DONE] Maj CSV: {updated} | Inchanges: {unchanged} | Hors base: {not_found}")
|
||||||
if unknown:
|
if unknown:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user