{
  "name": "Vorlux AI | Workflow Health Dashboard",
  "nodes": [
    {
      "id": "c6d7f80a-7f86-4d3d-bf30-ebf128708bbd",
      "name": "Every 30min",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        220,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 30
            }
          ]
        }
      }
    },
    {
      "id": "6a858520-aaab-471c-9ac3-6fc68e696608",
      "name": "Fetch Metrics",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const hubUrl = .VORLUX_HUB_URL || 'http://localhost:3010';\ntry {\n  const [cronRes, wfRes, healthRes] = await Promise.all([\n    fetch(hubUrl + '/api/cron/tick').then(r => r.json()).catch(() => ({})),\n    fetch(hubUrl + '/api/workflows/stats').then(r => r.json()).catch(() => ({})),\n    fetch(hubUrl + '/api/health').then(r => r.json()).catch(() => ({}))\n  ]);\n  const cronSuccess = cronRes.executedCount || 0;\n  const wfActive = wfRes.data?.active || 0;\n  const systemOk = healthRes.status === 'ok';\n  return [{json: {cronSuccess, wfActive, systemOk, timestamp: new Date().toISOString()}}];\n} catch(e) {\n  return [{json: {error: String(e), timestamp: new Date().toISOString()}}];\n}"
      },
      "notes": "Aggregates cron, workflow, and system health metrics"
    },
    {
      "id": "03952597-8cb8-49cb-959d-cc333e8d787b",
      "name": "Save Metrics",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        700,
        200
      ],
      "parameters": {
        "method": "POST",
        "url": "={{.VORLUX_HUB_URL}}/api/analytics/workflow-health",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify() }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "dfeb8dac-9f80-408a-ae0d-4ca11da170cb",
      "name": "Check Alerts",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        700,
        400
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const d = .first().json;\nconst alerts = [];\nif (!d.systemOk) alerts.push('System health check failed');\nif (d.cronSuccess === 0) alerts.push('No cron tasks executed recently');\nif (d.error) alerts.push('Metrics fetch error: ' + d.error);\nreturn [{json: {...d, alerts, hasAlerts: alerts.length > 0}}];"
      }
    },
    {
      "id": "6c0a6d7c-0d59-4d5c-bfea-0093a1531de4",
      "name": "Has Alerts?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        940,
        400
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "leftValue": "={{ .hasAlerts }}",
              "rightValue": "true",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "94dcaebb-1c8e-4dcf-baef-699b10280f88",
      "name": "Alert",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1180,
        400
      ],
      "parameters": {
        "method": "POST",
        "url": "={{.DISCORD_OPS_WEBHOOK}}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\"embeds\":[{\"title\":\"\u26a0\ufe0f Workflow Health Alert\",\"description\":\"{{ .alerts.join(\"\\n\") }}\",\"color\":15158332}]}",
        "options": {
          "timeout": 10000
        }
      }
    }
  ],
  "connections": {
    "Every 30min": {
      "main": [
        [
          {
            "node": "Fetch Metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Metrics": {
      "main": [
        [
          {
            "node": "Save Metrics",
            "type": "main",
            "index": 0
          },
          {
            "node": "Check Alerts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Alerts": {
      "main": [
        [
          {
            "node": "Has Alerts?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Alerts?": {
      "main": [
        [
          {
            "node": "Alert",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveExecutionProgress": true
  }
}