From e61f1c76fc0edefee51d767edd93356d5d30b4e2 Mon Sep 17 00:00:00 2001 From: Alkatrazz Date: Mon, 15 Jun 2026 21:37:13 +0200 Subject: [PATCH] docs(n8n): fix parsing webhook alertes (0 alerte/unknown) + filtre anti-bruit Le noeud Format Alertes lisait body.alerts/body.status au lieu de body.body.* -> tous les mails affichaient 0 alerte/unknown meme en cas de vraie alerte. Correctif applique au workflow (live) + filtre Watchdog/InfoInhibitor/severity none. Co-Authored-By: Claude Opus 4.8 --- admin/k8s/n8n.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/admin/k8s/n8n.md b/admin/k8s/n8n.md index 22865e4..252cd1d 100644 --- a/admin/k8s/n8n.md +++ b/admin/k8s/n8n.md @@ -289,6 +289,35 @@ curl -s "http://n8n.lab.local/api/v1/executions?limit=5" \ --- +## Workflow « Alertes Prometheus → Résumé LLM → Gmail » — parsing du webhook + +> ⚠️ **Piège corrigé le 2026-06-15.** Le nœud Webhook n8n imbrique le payload HTTP sous +> `.body` (`$input.first().json` = `{ headers, params, query, body }`). Le nœud **« Format Alertes »** +> lisait `body.alerts` / `body.status` **au mauvais niveau** → toujours `[]` et `'unknown'`. +> Résultat : **tous** les mails affichaient « 0 alerte(s) — unknown » sans détail, **même lors d'une vraie alerte** (pipeline d'alerte aveugle). + +Correctif appliqué dans le code du nœud « Format Alertes » : + +```js +const root = $input.first().json; +const payload = root.body || root; // <-- lit le payload imbriqué (repli si format plat) +const groupStatus = payload.status || 'unknown'; +const allAlerts = payload.alerts || []; +// Anti-bruit : exclure Watchdog / InfoInhibitor et severity none/info +const alerts = allAlerts.filter(a => { + const sev = (a.labels?.severity || '').toLowerCase(); + const name = a.labels?.alertname || ''; + return !['none','info',''].includes(sev) && !['Watchdog','InfoInhibitor'].includes(name); +}); +if (alerts.length === 0) { return []; } // aucune vraie alerte -> pas d'email (stoppe le workflow) +``` + +- AlertManager reçoit toujours son `HTTP 200` (nœud « Respond 200 » en branche parallèle, indépendant). +- Test sans email : `curl -XPOST http://n8n.lab.local/webhook/alerts -d '{"status":"firing","alerts":[{"labels":{"alertname":"Watchdog","severity":"none"}}]}'` → doit produire **0 item** au nœud « Format Alertes », **pas d'email**. +- Workflow non versionné (vit dans la base n8n) ; édition via l'API : `PUT /api/v1/workflows/` avec `{name,nodes,connections,settings}`. + +--- + ## Configuration Ansible / k8s - **Secrets k8s** : `kubectl get secret n8n-secret -n ai`