{
  "name": "Logixb2b — Healthcheck n8n en Docker",
  "meta": {
    "templateCredsSetupCompleted": false,
    "description": "Schedule cada 5 min: GET healthz de tu n8n Docker y alerta Slack solo si cae. Ejecutar en instancia distinta a la monitorizada."
  },
  "settings": {
    "executionOrder": "v1",
    "timezone": "Europe/Madrid"
  },
  "active": false,
  "pinData": {},
  "tags": [
    {
      "name": "Logixb2b"
    },
    {
      "name": "recursos"
    },
    {
      "name": "docker"
    },
    {
      "name": "ops"
    }
  ],
  "nodes": [
    {
      "id": "sticky-instrucciones-logix",
      "name": "INSTRUCCIONES (conectar + VPS)",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        40
      ],
      "parameters": {
        "content": "## INSTRUCCIONES — Healthcheck n8n en Docker\n\n**Recurso:** `/recursos/docker-n8n-healthcheck`\n**Guía:** /como-instalar-n8n-con-docker-paso-a-paso\n**Zona:** Europe/Madrid · `active: false` al importar (tú lo activas).\n\n### 1) Importar\n1. n8n → ⋯ → **Import from File** → este JSON.\n2. El flujo llega **inactive**. No pegues secretos en el lienzo ni en el archivo.\n\n### 2) Credenciales y configuración por nodo\n- **Cada 5 minutos** (`schedule`): sin credencial. Revisa expresión cron / intervalo y zona **Europe/Madrid** (settings del workflow). Solo dispara si n8n está **Active** 24/7.\n- **Config healthcheck** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **GET healthz n8n** (`HTTP Request` health): URL de `/healthz` o login de tu n8n. Si la instancia es privada, usa Header Auth / Basic desde Credentials.\n- **Unir estado + config** (`Set` Config): **no lleva credencial**. Aquí van URLs/placeholders (`REEMPLAZA_*`, `example.com`, `TU-CRM`). Sustituye todos antes de Active.\n- **¿n8n caído?** (`IF`): sin credencial. Comprueba la condición (email, umbral, over_limit, etc.) con datos reales de prueba.\n- **Alerta Slack (caída)** (`HTTP Request` → Slack/Teams): crea Incoming Webhook en Slack (o Adaptive Card URL en Teams). Pega la URL en **Config** o en este nodo. Auth: none (la URL ya es secreta).\n\n### 3) Orden recomendado de puesta en marcha\n1. Rellena el nodo **Config** (URLs reales, umbrales, webhooks de Slack).\n2. Crea Credentials en n8n (candado de cada nodo HTTP / Sheets / OpenAI) y **enlázalas**.\n3. Ejecuta **una vez** (Manual / Test URL del Webhook / \"Execute workflow\").\n4. Verifica CRM + Slack/Sheets (y que la IA no escriba en producción sin HITL).\n5. Solo entonces: interruptor **Active**.\n\n### 4) Producción 24/7 en VPS (UE)\nImportar en localhost no basta: webhooks y cron necesitan n8n encendido.\n\n1. VPS en UE (Hetzner/OVH/IONOS…) + Docker Compose + **Postgres** + HTTPS (Caddy/Nginx).\n2. Variables mínimas: `GENERIC_TIMEZONE=Europe/Madrid`, `WEBHOOK_URL=https://n8n.tudominio.com/`, `N8N_ENCRYPTION_KEY`, `N8N_HOST` / `N8N_PROTOCOL=https`.\n3. Firewall: solo 80/443 (+ SSH). Backups del volumen Postgres + export de workflows.\n4. Importa este JSON en la instancia de producción, vuelve a crear Credentials (no se copian solas), actualiza URLs del Config al dominio real.\n5. Pon **Active**. Prueba el Webhook de producción o espera el próximo cron.\n6. Alternativa: **n8n Cloud** (mismo JSON; Credentials en la UI Cloud).\n\n### 5) RGPD + EU AI Act (resumen)\nSi hay nodos IA sois **deployers** (Reglamento UE 2024/1689). Art. 4 alfabetización. **HITL** antes de outreach, scores masivos o pausas de cuenta. Minimiza PII en Slack/logs. Informativo — no es asesoramiento legal. /uso-responsable-de-ia-y-transparencia\n",
        "height": 1500,
        "width": 580,
        "color": 4
      }
    },
    {
      "id": "trigger-schedule",
      "name": "Cada 5 minutos",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 5
            }
          ]
        }
      }
    },
    {
      "id": "set-config",
      "name": "Config healthcheck",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        300,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "c1",
              "name": "n8nHealthUrl",
              "value": "https://TU-N8N.ejemplo/healthz",
              "type": "string"
            },
            {
              "id": "c2",
              "name": "instanceLabel",
              "value": "n8n-prod-docker",
              "type": "string"
            },
            {
              "id": "c3",
              "name": "slackWebhookUrl",
              "value": "https://example.com/aviso-equipo-slack",
              "type": "string"
            },
            {
              "id": "c4",
              "name": "checkedAt",
              "value": "={{ $now.toISO() }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "http-health",
      "name": "GET healthz n8n",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        600,
        300
      ],
      "parameters": {
        "method": "GET",
        "url": "={{ $json.n8nHealthUrl }}",
        "options": {
          "timeout": 10000,
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      }
    },
    {
      "id": "merge-status",
      "name": "Unir estado + config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        900,
        300
      ],
      "parameters": {
        "mode": "manual",
        "duplicateItem": false,
        "assignments": {
          "assignments": [
            {
              "id": "m1",
              "name": "statusCode",
              "value": "={{ $json.statusCode }}",
              "type": "number"
            },
            {
              "id": "m2",
              "name": "isUp",
              "value": "={{ Number($json.statusCode) >= 200 && Number($json.statusCode) < 400 }}",
              "type": "boolean"
            },
            {
              "id": "m3",
              "name": "n8nHealthUrl",
              "value": "={{ $('Config healthcheck').item.json.n8nHealthUrl }}",
              "type": "string"
            },
            {
              "id": "m4",
              "name": "instanceLabel",
              "value": "={{ $('Config healthcheck').item.json.instanceLabel }}",
              "type": "string"
            },
            {
              "id": "m5",
              "name": "slackWebhookUrl",
              "value": "={{ $('Config healthcheck').item.json.slackWebhookUrl }}",
              "type": "string"
            },
            {
              "id": "m6",
              "name": "checkedAt",
              "value": "={{ $('Config healthcheck').item.json.checkedAt }}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "id": "if-down",
      "name": "¿n8n caído?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1200,
        300
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "cond-down",
              "leftValue": "={{ $json.isUp }}",
              "rightValue": false,
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        }
      }
    },
    {
      "id": "slack-alert",
      "name": "Alerta Slack (caída)",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1500,
        40
      ],
      "parameters": {
        "method": "POST",
        "url": "={{ $json.slackWebhookUrl }}",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify({ text: $json.slackText || 'Actualización Logixb2b' }) }}",
        "options": {
          "timeout": 10000
        }
      }
    },
    {
      "id": "noop-ok",
      "name": "OK — sin alerta",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1500,
        560
      ],
      "parameters": {}
    }
  ],
  "connections": {
    "Cada 5 minutos": {
      "main": [
        [
          {
            "node": "Config healthcheck",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config healthcheck": {
      "main": [
        [
          {
            "node": "GET healthz n8n",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GET healthz n8n": {
      "main": [
        [
          {
            "node": "Unir estado + config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Unir estado + config": {
      "main": [
        [
          {
            "node": "¿n8n caído?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "¿n8n caído?": {
      "main": [
        [
          {
            "node": "Alerta Slack (caída)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "OK — sin alerta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
