Sync to iTop: export referentiel (environnements, domaines, zones) + serveurs
This commit is contained in:
parent
66eeff99e8
commit
1ff6b3fd4d
@ -322,9 +322,31 @@ def sync_from_itop(db, itop_url, itop_user, itop_pass):
|
||||
|
||||
|
||||
def sync_to_itop(db, itop_url, itop_user, itop_pass):
|
||||
"""Exporte les infos patching de PatchCenter vers iTop"""
|
||||
"""Exporte referentiel + serveurs de PatchCenter vers iTop"""
|
||||
client = ITopClient(itop_url, itop_user, itop_pass)
|
||||
stats = {"updated": 0, "created": 0, "errors": []}
|
||||
stats = {"updated": 0, "created": 0, "ref_created": 0, "errors": []}
|
||||
|
||||
# ─── Sync referentiel: environments, domains, zones ───
|
||||
for pc_table, itop_class in [("environments", "Environnement"), ("domains", "DomaineApplicatif"), ("zones", "Zone")]:
|
||||
# Get existing in iTop
|
||||
existing_itop = set()
|
||||
for item in client.get_all(itop_class, "name"):
|
||||
existing_itop.add(item.get("name", "").lower())
|
||||
|
||||
# Get PatchCenter values
|
||||
rows = db.execute(text(f"SELECT name FROM {pc_table} ORDER BY name")).fetchall()
|
||||
for row in rows:
|
||||
name = row.name
|
||||
if name.lower() not in existing_itop:
|
||||
r = client.create(itop_class, {
|
||||
"name": name,
|
||||
"org_id": "SELECT Organization WHERE name = 'MPCZ'",
|
||||
})
|
||||
if r.get("code") == 0:
|
||||
stats["ref_created"] += 1
|
||||
existing_itop.add(name.lower())
|
||||
else:
|
||||
stats["errors"].append(f"{itop_class} '{name}': {r.get('message', '')[:60]}")
|
||||
|
||||
# Get iTop VMs indexed by short name
|
||||
itop_vms = {}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user