on_mqtt_register : mise à jour automatique du registre + distinction NOUVEAU/EN LIGNE
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -134,7 +134,7 @@ def on_mqtt_notification(client, userdata, msg):
|
||||
print("[MQTT] Erreur parsing notification scheduler : {}".format(e))
|
||||
|
||||
def on_mqtt_register(client, userdata, msg):
|
||||
"""Reçoit les déclarations de mise en ligne des agents."""
|
||||
"""Reçoit les déclarations de mise en ligne des agents et met à jour le registre."""
|
||||
try:
|
||||
data = json.loads(msg.payload.decode(errors="replace"))
|
||||
agent = data.get("agent", "?")
|
||||
@@ -142,9 +142,28 @@ def on_mqtt_register(client, userdata, msg):
|
||||
mqtt_inbox = data.get("mqtt_inbox", "?")
|
||||
speciality = data.get("speciality", "")
|
||||
print("[REGISTER] {} en ligne (JID: {}, inbox: {})".format(agent, jid, mqtt_inbox))
|
||||
|
||||
# Mettre à jour agents_registry.json
|
||||
registry_file = CONFIG_DIR / "agents_registry.json"
|
||||
try:
|
||||
registry = json.loads(registry_file.read_text(encoding="utf-8"))
|
||||
except Exception:
|
||||
registry = {}
|
||||
is_new = agent not in registry
|
||||
registry[agent] = {
|
||||
"jid" : jid,
|
||||
"mqtt_inbox" : mqtt_inbox,
|
||||
"mqtt_outbox": "agents/agent1/inbox",
|
||||
"speciality" : speciality,
|
||||
}
|
||||
registry_file.write_text(json.dumps(registry, indent=2, ensure_ascii=False), encoding="utf-8")
|
||||
if is_new:
|
||||
print("[REGISTER] {} ajouté au registre.".format(agent))
|
||||
|
||||
# Notifier sylvain via XMPP
|
||||
if xmpp_bot:
|
||||
notif = "[EN LIGNE] {}\n JID : {}\n MQTT : {}".format(agent, jid, mqtt_inbox)
|
||||
status = "NOUVEAU" if is_new else "EN LIGNE"
|
||||
notif = "[{}] {}\n JID : {}\n MQTT : {}".format(status, agent, jid, mqtt_inbox)
|
||||
if speciality:
|
||||
notif += "\n Rôle : {}".format(speciality)
|
||||
xmpp_bot.send_message(mto=ADMIN_JID, mbody=notif, mtype='chat')
|
||||
|
||||
+12
-12
@@ -1,20 +1,20 @@
|
||||
{
|
||||
"agent2_debian13": {
|
||||
"jid" : "agent2_debian13@xmpp.ovh",
|
||||
"mqtt_inbox" : "agents/agent2_debian13/inbox",
|
||||
"mqtt_outbox" : "agents/agent1/inbox",
|
||||
"speciality" : "Administration Debian : apt, dpkg, systemd, conteneurs LXC/Docker, KVM, réseau, sécurité système"
|
||||
"jid": "agent2_debian13@xmpp.ovh",
|
||||
"mqtt_inbox": "agents/agent2_debian13/inbox",
|
||||
"mqtt_outbox": "agents/agent1/inbox",
|
||||
"speciality": "Administration Debian : apt, dpkg, systemd, conteneurs LXC/Docker, KVM, réseau, sécurité système"
|
||||
},
|
||||
"agent2_ansible": {
|
||||
"jid" : "agent2_ansible@xmpp.ovh",
|
||||
"mqtt_inbox" : "agents/agent2_ansible/inbox",
|
||||
"mqtt_outbox" : "agents/agent1/inbox",
|
||||
"speciality" : "Automatisation infrastructure via Ansible : playbooks, commandes ad-hoc, déploiement multi-hôtes, gestion de configuration sur le réseau local"
|
||||
"jid": "agent2_ansible@xmpp.ovh",
|
||||
"mqtt_inbox": "agents/agent2_ansible/inbox",
|
||||
"mqtt_outbox": "agents/agent1/inbox",
|
||||
"speciality": "Automatisation infrastructure via Ansible : playbooks, commandes ad-hoc, déploiement multi-hôtes, gestion de configuration sur le réseau local"
|
||||
},
|
||||
"agent2_deploy": {
|
||||
"jid" : "agent2_deploy@xmpp.ovh",
|
||||
"mqtt_inbox" : "agents/agent2_deploy/inbox",
|
||||
"mqtt_outbox" : "agents/agent1/inbox",
|
||||
"speciality" : "Déploiement d'agents : installe et configure d'autres agents sur des machines distantes ou locales via SSH"
|
||||
"jid": "agent2_deploy@xmpp.ovh",
|
||||
"mqtt_inbox": "agents/agent2_deploy/inbox",
|
||||
"mqtt_outbox": "agents/agent1/inbox",
|
||||
"speciality": "Déploiement d'agents : installe et configure d'autres agents sur des machines distantes ou locales via SSH"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user