{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "bf2344bb-71e3-4f4a-b5c6-ec05c5dab72b",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -336,
        -320
      ],
      "parameters": {
        "width": 352,
        "height": 768,
        "content": "## Website Uptime Monitor\n\n### How it works\n1. A schedule trigger checks your website every 5 minutes\n2. The HTTP Request node hits your URL and captures the response\n3. A Code node evaluates the status code and response time\n4. If the site is down, Google Gemini diagnoses the likely cause based on the error\n5. Every check is logged to Google Sheets for uptime history\n6. Downtime triggers a Slack alert with the AI diagnosis\n7. A daily summary email goes out via Gmail\n\n### Setup steps\n1. Set your target URL in the \"Check Website\" HTTP Request node\n2. Connect Google Gemini API credentials (free tier)\n3. Create a Google Sheet called \"Uptime Log\" and connect it\n4. Connect Slack and pick your alerts channel\n5. Connect Gmail for daily reports\n\n### Customization\n- Change the schedule interval in the trigger node (default: 5 minutes)\n- Add more URLs by duplicating the HTTP Request node\n- Adjust the response time threshold in the Code node (default: 3000ms)"
      },
      "typeVersion": 1
    },
    {
      "id": "cbac54a2-1ff0-40ff-9af5-0dcf22f716b9",
      "name": "Note - Health Check",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 388,
        "content": "## Health check\nHits the target URL and evaluates response status and timing."
      },
      "typeVersion": 1
    },
    {
      "id": "5e2d74a1-690c-4796-b8e8-f60076824c38",
      "name": "Note - AI Diagnosis",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 520,
        "height": 524,
        "content": "## AI error diagnosis\nGemini analyzes the error pattern and suggests probable root causes."
      },
      "typeVersion": 1
    },
    {
      "id": "e6d00b03-a2df-40e7-9cb9-a44338eb08cb",
      "name": "Note - Notifications",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1088,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 428,
        "height": 532,
        "content": "## Logging and notifications\nLogs every check to Sheets. Sends Slack alerts for downtime and daily Gmail reports."
      },
      "typeVersion": 1
    },
    {
      "id": "68eebcd0-915e-4457-ae4a-c35f458b9a4f",
      "name": "Check Every 5 Minutes",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        80,
        -112
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "21ac396b-19bb-4f9d-847a-cb3a4948d114",
      "name": "Check Website",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        240,
        -112
      ],
      "parameters": {
        "url": "https://example.com",
        "options": {
          "timeout": 10000,
          "response": {
            "response": {
              "fullResponse": true
            }
          },
          "allowUnauthorizedCerts": true
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "7ec3b343-1860-468d-8e9f-4417c0e45cae",
      "name": "Evaluate Response",
      "type": "n8n-nodes-base.code",
      "position": [
        416,
        -112
      ],
      "parameters": {
        "jsCode": "// Evaluate website response and determine status\nconst items = $input.all();\nconst results = [];\n\nfor (const item of items) {\n  const statusCode = item.json.statusCode || 0;\n  const responseTime = item.json.responseTime || 0;\n  const headers = item.json.headers || {};\n  const error = item.json.error || null;\n  \n  let status = 'up';\n  let issue = '';\n  \n  if (statusCode === 0 || error) {\n    status = 'down';\n    issue = error ? `Connection error: ${error.message || error}` : 'No response received';\n  } else if (statusCode >= 500) {\n    status = 'down';\n    issue = `Server error: HTTP ${statusCode}`;\n  } else if (statusCode >= 400) {\n    status = 'degraded';\n    issue = `Client error: HTTP ${statusCode}`;\n  } else if (responseTime > 3000) {\n    status = 'slow';\n    issue = `Response time ${responseTime}ms exceeds 3000ms threshold`;\n  }\n  \n  results.push({\n    json: {\n      url: 'https://example.com',\n      statusCode,\n      responseTime,\n      status,\n      issue,\n      checkedAt: new Date().toISOString(),\n      needsAlert: status === 'down' || status === 'degraded'\n    }\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "248e8e6d-3478-4952-a46d-d27c7183370d",
      "name": "Site Down?",
      "type": "n8n-nodes-base.if",
      "position": [
        592,
        -112
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "down-check",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.needsAlert }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "7d8bbdad-f245-4d02-871e-a6c4423dad64",
      "name": "Diagnose Error",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        832,
        -208
      ],
      "parameters": {
        "text": "You are a website reliability engineer. A monitored website returned an error. Diagnose the likely cause.\n\n**URL:** {{ $json.url }}\n**Status Code:** {{ $json.status_code }}\n**Response Time:** {{ $json.response_time_ms }}ms\n**Error Message:** {{ $json.error_message }}\n**Timestamp:** {{ $json.checked_at }}\n\nReturn ONLY valid JSON:\n{\n  \"diagnosis\": \"Brief explanation of what likely went wrong\",\n  \"severity\": \"low/medium/high/critical\",\n  \"likely_cause\": \"server_error/dns_issue/ssl_expired/timeout/rate_limit/maintenance/unknown\",\n  \"suggested_action\": \"What to check or do next\",\n  \"is_likely_temporary\": true/false,\n  \"estimated_recovery\": \"Estimated time to recover if temporary\"\n}",
        "promptType": "define"
      },
      "typeVersion": 1.4
    },
    {
      "id": "e59faeb3-ff7a-4315-8ce0-9de539e08e99",
      "name": "Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        976,
        -64
      ],
      "parameters": {
        "options": {
          "temperature": 0.1
        },
        "modelName": "models/gemini-1.5-flash"
      },
      "typeVersion": 1
    },
    {
      "id": "6dfd4d21-59dc-4796-b249-73431ad8fce6",
      "name": "Log to Uptime Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1152,
        48
      ],
      "parameters": {
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": ""
        }
      },
      "typeVersion": 4.5
    },
    {
      "id": "b57e0410-499b-4b6a-82c9-17f06d4a4820",
      "name": "Alert Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1152,
        -208
      ],
      "parameters": {
        "text": "=\ud83d\udd34 *Website Down Alert*\n\n*URL:* {{ $('Site Down?').item.json.url }}\n*Status:* {{ $('Site Down?').item.json.status }}\n*Error:* {{ $('Site Down?').item.json.issue }}\n*Detected:* {{ $('Site Down?').item.json.checkedAt }}\n\n*AI Diagnosis:*\n{{ $json.text }}",
        "otherOptions": {}
      },
      "typeVersion": 2.2
    },
    {
      "id": "078aef20-a88b-4b9d-a201-c9412bfc6290",
      "name": "Send Daily Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1312,
        48
      ],
      "parameters": {
        "message": "=Website Uptime Check Result\n\nURL: {{ $json.url }}\nStatus: {{ $json.status }}\nStatus Code: {{ $json.statusCode }}\nResponse Time: {{ $json.responseTime }}ms\nChecked At: {{ $json.checkedAt }}\n\nThis is an automated uptime report from your n8n monitoring workflow.",
        "options": {},
        "subject": "=Daily Uptime Report - {{ new Date().toISOString().split('T')[0] }}"
      },
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "Site Down?": {
      "main": [
        [
          {
            "node": "Diagnose Error",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log to Uptime Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Alert Slack": {
      "main": [
        [
          {
            "node": "Log to Uptime Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Website": {
      "main": [
        [
          {
            "node": "Evaluate Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Diagnose Error": {
      "main": [
        [
          {
            "node": "Alert Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Evaluate Response": {
      "main": [
        [
          {
            "node": "Site Down?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Diagnose Error",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Log to Uptime Sheet": {
      "main": [
        [
          {
            "node": "Send Daily Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Every 5 Minutes": {
      "main": [
        [
          {
            "node": "Check Website",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}