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 <noreply@anthropic.com>
This commit is contained in:
Alkatrazz 2026-06-15 21:37:13 +02:00
parent 6437df5ff7
commit e61f1c76fc

View file

@ -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/<id>` avec `{name,nodes,connections,settings}`.
---
## Configuration Ansible / k8s
- **Secrets k8s** : `kubectl get secret n8n-secret -n ai`