{
  "name": "Website Uptime Monitoring workflow",
  "nodes": [
    {
      "parameters": {
        "url": "https://microagencia.com",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "n8n-monitor/1.0"
            }
          ]
        },
        "options": {
          "redirect": {
            "redirect": {
              "maxRedirects": 5
            }
          },
          "timeout": 15000
        }
      },
      "id": "b5f1e6a7-c77e-460d-bb58-6dbf926b666e",
      "name": "1. Get Website Content",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -60,
        220
      ],
      "typeVersion": 4.1
    },
    {
      "parameters": {
        "jsCode": "function cleanHtml(content) {\n  if (!content || typeof content !== 'string') return '';\n\n  // Elimina todo <script>...</script>, <style>...</style>, <head>...</head>, <meta ...>\n  content = content\n    .replace(/<script[\\s\\S]*?>[\\s\\S]*?<\\/script>/gi, '')\n    .replace(/<style[\\s\\S]*?>[\\s\\S]*?<\\/style>/gi, '')\n    .replace(/<head[\\s\\S]*?>[\\s\\S]*?<\\/head>/gi, '')\n    .replace(/<meta[\\s\\S]*?>/gi, '');\n\n  // Elimina todos los atributos inline (tipo style, onclick, etc.)\n  content = content.replace(/(<[^>]+)(\\s+(?:style|onclick|onerror|onload)=\"[^\"]*\")/gi, '$1');\n\n  // Elimina todas las etiquetas HTML dejando solo el texto\n  content = content.replace(/<\\/?[^>]+(>|$)/g, '');\n\n  // Normaliza espacios, quita múltiples espacios y saltos de línea\n  content = content.replace(/\\s+/g, ' ').trim();\n\n  // Convierte todo a minúsculas para las validaciones posteriores\n  return content.toLowerCase();\n}\n\nconst inputData = $input.all();\nconst results = [];\n\nfor (const item of inputData) {\n  results.push({\n    json: {\n      cleanedContent: cleanHtml(item.json.data),\n      originalBody: item.json.data,\n      url: item.json.url || 'https://microagencia.com',\n      statusCode: item.json.statusCode,\n    }\n  });\n}\n\nreturn results;\n"
      },
      "id": "25548a42-21da-43b4-a8e9-53f6900d5ea7",
      "name": "3. Content Cleaner",
      "type": "n8n-nodes-base.code",
      "position": [
        480,
        480
      ],
      "typeVersion": 2,
      "alwaysOutputData": true,
      "notesInFlow": true
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "content-validation-check",
              "leftValue": "={{ $json.passed }}",
              "rightValue": false,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "5b14aee5-71c2-4bba-8799-cebac6b3a31e",
      "name": "5. Content Validation Check",
      "type": "n8n-nodes-base.if",
      "position": [
        920,
        460
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "fromEmail": "microagenciaia@gmail.com",
        "toEmail": "microagenciaia@gmail.com",
        "subject": "⚠️ WARNING: Website Health Issue - microagencia.com",
        "text": "=🔥 The website https://microagencia.com is responding but has health issues.\n\nValidation Details:\n- URL: {{$json[\"url\"]}}\n- Keyword: {{ $json.validations.keywordsChecked }}\n- Content is Not Empty: {{$json[\"validations\"][\"isNotEmpty\"]}}\n- Timestamp: {{$json[\"timestamp\"]}}\n",
        "options": {}
      },
      "id": "d7959fd6-1237-475c-b052-e7a8fda177d8",
      "name": "Send WARNING Alert - Health Issue",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        1160,
        300
      ],
      "typeVersion": 2,
      "webhookId": "32b48807-29a4-4cd9-ada5-e979c4699719",
      "credentials": {
        "smtp": {
          "id": "nA5LptwOB94wlSjH",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "microagenciaia@gmail.com",
        "toEmail": "microagenciaia@gmail.com",
        "subject": "🚨 CRITICAL: Website DOWN - microagencia.com",
        "text": "🔥 The website https://microagencia.com is completely down or not returning a 200 OK status.\n\nHTTP Status Code: {{ $json.statusCode }}\nTimestamp: {{ new Date().toISOString() }}",
        "options": {}
      },
      "id": "183495ad-430b-4895-993f-12e3c612bd21",
      "name": "Send CRITICAL Alert - Site DOWN",
      "type": "n8n-nodes-base.emailSend",
      "position": [
        500,
        60
      ],
      "typeVersion": 2,
      "webhookId": "9bfc80f7-74a3-4216-b225-d58efcd292bb",
      "credentials": {
        "smtp": {
          "id": "nA5LptwOB94wlSjH",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Validación multi-keywords sin duplicar nodos.\nconst keywords = ['microagencia', 'contacto', 'servicios']; // <-- Edita aquí\n\nconst output = [];\n\nfor (const item of $input.all()) {\n  try {\n    const json = item.json;\n    if (!json) throw new Error('No input data received');\n\n    const content = String(json.cleanedContent || '');\n    const url     = String(json.url || '');\n\n    // Detecta keywords faltantes\n    const missing = keywords.filter(k => !content.includes(k));\n\n    const validationResults = {\n      keywordsChecked: keywords,\n      missingKeywords: missing,\n      contentLength: content.length,\n      isNotEmpty: content.length > 100\n    };\n\n    // Pasa sólo si NO faltan keywords y el contenido no está vacío\n    const passed = validationResults.isNotEmpty && missing.length === 0;\n\n    output.push({\n      json: {\n        url,\n        statusCode: json.statusCode,\n        validations: validationResults,\n        passed,\n        checkedKeywords: keywords.join(', '),\n        timestamp: new Date().toISOString(),\n        debug: {\n          contentPreview: content.substring(0, 250) + '...',\n          shouldSendAlert: !passed\n        }\n      }\n    });\n  } catch (error) {\n    output.push({\n      json: {\n        error: error.message,\n        passed: false,\n        timestamp: new Date().toISOString()\n      }\n    });\n  }\n}\n\nreturn output;"
      },
      "id": "9f089809-cb63-4007-910b-da478771b67b",
      "name": "4. Dynamic Content Validator1",
      "type": "n8n-nodes-base.code",
      "position": [
        700,
        480
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "content": "## Keyword to search\nInsert search word here",
        "height": 340,
        "width": 180
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        320
      ],
      "typeVersion": 1,
      "id": "3e721084-8189-4779-9696-b4dffd958b2e",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "content": "## URL to search\nInsert URL ",
        "height": 280,
        "width": 220
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        120
      ],
      "typeVersion": 1,
      "id": "4658ee91-6ec0-4532-bc62-ddcc391cd56c",
      "name": "Sticky Note3"
    },
    {
      "parameters": {
        "content": "## Gmail\nInsert email address and credentials",
        "height": 340,
        "width": 220,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1100,
        160
      ],
      "typeVersion": 1,
      "id": "f5df8bca-5389-4f6b-b585-6eb29a4b5e6b",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "content": "## Gmail\nInsert email address and credentials",
        "height": 340,
        "width": 220,
        "color": 3
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        -100
      ],
      "typeVersion": 1,
      "id": "3684b816-4d8a-45d5-9f32-c137ab795cde",
      "name": "Sticky Note2"
    },
    {
      "parameters": {
        "content": "## Cleaner\nLowercase + clean code",
        "height": 340,
        "width": 180
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        320
      ],
      "typeVersion": 1,
      "id": "97fcaa41-a33c-4ee6-8107-b16ea61420d6",
      "name": "Sticky Note4"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "231ad6e7-e99b-808e-a8f1-e20df15ba338",
          "mode": "list",
          "cachedResultName": "Website Monitoring",
          "cachedResultUrl": "https://www.notion.so/231ad6e7e99b808ea8f1e20df15ba338"
        },
        "title": "tabla de monitoreo",
        "simple": false,
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Nombre|title",
              "title": "microagencia"
            },
            {
              "key": "URL|url",
              "urlValue": "={{ $json.url }}"
            },
            {
              "key": "keyword|rich_text",
              "textContent": "={{ $json.validations.keywordsChecked[0] }}, {{ $json.validations.keywordsChecked[1] }}, {{ $json.validations.keywordsChecked[2] }}"
            },
            {
              "key": "passed|checkbox",
              "checkboxValue": true
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1160,
        700
      ],
      "id": "197c53f8-a9c6-4ca2-9ef2-a1aa8cb2d9f0",
      "name": "Create a database page",
      "credentials": {
        "notionApi": {
          "id": "93W7o4OgWgAyVX7k",
          "name": "Notion account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Notion log\nInsert Notion credentials & database",
        "height": 340,
        "width": 220,
        "color": 4
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1100,
        560
      ],
      "typeVersion": 1,
      "id": "7de2ea66-42d0-4ff3-a88b-7f0b022535c4",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "status-check",
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": "200",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c30ce3e5-4414-4960-bc9f-ba5173271a46",
      "name": "2. Is Site DOWN?",
      "type": "n8n-nodes-base.if",
      "position": [
        180,
        220
      ],
      "typeVersion": 2
    },
    {
      "parameters": {
        "content": "# Microagencia",
        "width": 300,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -120,
        -100
      ],
      "typeVersion": 1,
      "id": "c9d277d5-06a4-4e56-8139-b79f653dc34b",
      "name": "Sticky Note12"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 240
            }
          ]
        }
      },
      "id": "87341e82-1c93-4c56-a4a6-29c215908dff",
      "name": "Schedule Check Every 5 Minutes2",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -400,
        -40
      ],
      "typeVersion": 1.1
    },
    {
      "parameters": {
        "content": "# New version\n\n",
        "height": 1260,
        "width": 1940,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -460,
        -300
      ],
      "typeVersion": 1,
      "id": "46bbc681-6bc9-434b-92c1-fc4f88831671",
      "name": "Sticky Note56"
    }
  ],
  "pinData": {},
  "connections": {
    "1. Get Website Content": {
      "main": [
        [
          {
            "node": "2. Is Site DOWN?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3. Content Cleaner": {
      "main": [
        [
          {
            "node": "4. Dynamic Content Validator1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "5. Content Validation Check": {
      "main": [
        [
          {
            "node": "Send WARNING Alert - Health Issue",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create a database page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "4. Dynamic Content Validator1": {
      "main": [
        [
          {
            "node": "5. Content Validation Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2. Is Site DOWN?": {
      "main": [
        [
          {
            "node": "Send CRITICAL Alert - Site DOWN",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "3. Content Cleaner",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Check Every 5 Minutes2": {
      "main": [
        [
          {
            "node": "1. Get Website Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "afc06d72-d4a8-482b-9fcb-a34bbf4c1c46",
  "meta": {
    "instanceId": "558d88703fb65b2d0e44613bc35916258b0f0bf983c5d4730c00c424b77ca36a"
  },
  "id": "GuMIRKoAyWAC5RRT",
  "tags": [
    {
      "createdAt": "2025-07-15T20:12:03.179Z",
      "updatedAt": "2025-07-15T20:12:03.179Z",
      "id": "wn4br9zVRcCP3ywP",
      "name": "monitoring"
    },
    {
      "createdAt": "2025-07-15T20:12:06.103Z",
      "updatedAt": "2025-07-15T20:12:06.103Z",
      "id": "7kObZ0auI8maQoGJ",
      "name": "tool"
    }
  ]
}