Files
MobilityOps/n8n/workflows/fleet-ops-alert-receiver.json
T
NuklearRabbit a42012d9c0
MobilityOps acceptance / acceptance (pull_request) Failing after 10m16s
hygiene: prepare MobilityOps for public release
2026-09-02 23:44:03 +02:00

37 lines
3.1 KiB
JSON

{
"id": "mobilityops-alert-receiver",
"name": "Fleet Ops — Alert Receiver",
"active": false,
"nodes": [
{
"parameters": {"httpMethod": "POST", "path": "mobilityops-alerts", "authentication": "headerAuth", "responseMode": "responseNode", "options": {}},
"id": "alert-webhook", "name": "Alertmanager webhook", "type": "n8n-nodes-base.webhook", "typeVersion": 2, "position": [240, 300], "webhookId": "mobilityops-alerts",
"credentials": {"httpHeaderAuth": {"name": "Fleet Ops Webhook Trigger Token"}}
},
{
"parameters": {"jsCode": "const body = $json.body ?? $json;\nif (!['firing', 'resolved'].includes(body.status) || !Array.isArray(body.alerts)) throw new Error('Invalid Alertmanager payload');\nconst alerts = body.alerts.slice(0, 25).map(a => ({name: String(a.labels?.alertname || 'Unknown alert').slice(0, 120), severity: String(a.labels?.severity || 'unknown').slice(0, 32), summary: String(a.annotations?.summary || '').slice(0, 500)}));\nconst esc = v => String(v).replace(/[&<>\\\"']/g, c => ({'&':'&amp;','<':'&lt;','>':'&gt;','\\\"':'&quot;',\"'\":'&#39;'}[c]));\nconst resolved = body.status === 'resolved';\nreturn [{json:{subject:`[Fleet Ops] ${resolved ? 'Hersteld' : 'Alert'} — ${alerts.length} signaal/signalen`,html:`<h2>Fleet Ops ${resolved ? 'hersteld' : 'monitoringalert'}</h2><ul>${alerts.map(a => `<li><strong>${esc(a.severity)} · ${esc(a.name)}</strong><br>${esc(a.summary)}</li>`).join('')}</ul><p>Ontvangen ${esc($now.toISO())}</p>`}}];"},
"id": "validate-format", "name": "Validate and format", "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [500, 300]
},
{
"parameters": {"respondWith": "json", "responseBody": "={{ { accepted: true } }}", "options": {}},
"id": "accept", "name": "Accept alert", "type": "n8n-nodes-base.respondToWebhook", "typeVersion": 1.4, "position": [740, 300]
},
{
"parameters": {"toRecipients": "={{ $env.MOBILITYOPS_ALERT_RECIPIENT || 'alerts@example.test' }}", "subject": "={{ $('Validate and format').item.json.subject }}", "bodyContent": "={{ $('Validate and format').item.json.html }}", "additionalFields": {"from": "={{ $env.MOBILITYOPS_ALERT_SENDER || 'n8n@example.test' }}", "bodyContentType": "html"}},
"id": "email", "name": "Send owner email", "type": "n8n-nodes-base.microsoftOutlook", "typeVersion": 2, "position": [980, 300],
"credentials": {"microsoftOutlookOAuth2Api": {"id": "EDTj3sOsganaoDVL", "name": "M365 n8n Shared Mailbox"}},
"retryOnFail": true, "maxTries": 3, "waitBetweenTries": 1000
}
],
"connections": {
"Alertmanager webhook": {"main": [[{"node": "Validate and format", "type": "main", "index": 0}]]},
"Validate and format": {"main": [[{"node": "Accept alert", "type": "main", "index": 0}]]},
"Accept alert": {"main": [[{"node": "Send owner email", "type": "main", "index": 0}]]}
},
"settings": {"executionOrder": "v1", "timezone": "Europe/Brussels", "errorWorkflow": "Xppn2rAEqUuyiCJF", "executionTimeout": 120, "saveDataSuccessExecution": "none", "saveDataErrorExecution": "all"},
"staticData": null,
"meta": {"templateCredsSetupCompleted": false},
"pinData": {},
"tags": []
}