From 988caf0e24ad26987dd87b1287d09e19283ab2d0 Mon Sep 17 00:00:00 2001 From: sylvain Date: Sat, 7 Mar 2026 16:55:55 +0000 Subject: [PATCH] =?UTF-8?q?D=C3=A9claration=20=C3=A0=20agent1=20via=20MQTT?= =?UTF-8?q?=20(agents/register)=20au=20d=C3=A9marrage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- agent2_ansible.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/agent2_ansible.py b/agent2_ansible.py index 3137edb..1b9e384 100644 --- a/agent2_ansible.py +++ b/agent2_ansible.py @@ -85,6 +85,18 @@ def mqtt_publish(topic: str, message: str): if mqtt_publish_client: mqtt_publish_client.publish(topic, message) +def register_to_agent1(): + """Publie une déclaration de mise en ligne sur agents/register.""" + import json as _json + payload = _json.dumps({ + "agent" : MQTT_CLIENT, + "jid" : XMPP_JID, + "mqtt_inbox": MQTT_INBOX, + "speciality": "Automatisation infrastructure via Ansible : playbooks, commandes ad-hoc, déploiement multi-hôtes, gestion de configuration sur le réseau local", + }) + mqtt_publish("agents/register", payload) + print("[REGISTER] Déclaration envoyée à agent1.") + def on_mqtt_message(client, userdata, msg): task = msg.payload.decode(errors="replace") print(f"[MQTT] Tâche reçue d'agent1 : {task[:100]}") @@ -102,6 +114,7 @@ def start_mqtt_listener(): client_id=MQTT_CLIENT + "_pub") mqtt_publish_client.connect(MQTT_HOST, MQTT_PORT) mqtt_publish_client.loop_start() + register_to_agent1() # Client dédié à la souscription sub_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2,