Déclaration à agent1 via MQTT (agents/register) au démarrage

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-07 16:55:55 +00:00
parent 918d65cd49
commit 988caf0e24
+13
View File
@@ -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,