{
  "name": "Websites Status Monitor",
  "nodes": [
    {
      "parameters": {
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "value": "nsZToo46ixNACYlQ",
          "mode": "list",
          "cachedResultName": "Websites to Monitor",
          "cachedResultUrl": "/projects/iLazCKgG1k9hAivR/datatables/nsZToo46ixNACYlQ"
        },
        "returnAll": true
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        -256,
        112
      ],
      "id": "9694f78d-a0fd-4b2b-bcc0-8cdc7f0a0cd8",
      "name": "Get row(s)"
    },
    {
      "parameters": {
        "url": "={{ $json.website_url }}",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true
            }
          }
        }
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -48,
        112
      ],
      "id": "ec67db4b-b43c-4a7e-86a5-91f30971f037",
      "name": "HTTP Request",
      "alwaysOutputData": true,
      "notesInFlow": true,
      "onError": "continueRegularOutput",
      "notes": "Checks website's status code"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "e091cfc1-9d22-4d71-8d2e-728510e1cdc4",
              "leftValue": "={{ $('HTTP Request').item.json.statusCode }}",
              "rightValue": 200,
              "operator": {
                "type": "number",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        736,
        -16
      ],
      "id": "2d9a7656-bcd0-4dc2-8828-9378efe2db59",
      "name": "If2",
      "notesInFlow": true,
      "notes": "Splits the workflow to 2. One handles the website coming back up, the other handles the website going down."
    },
    {
      "parameters": {
        "chatId": "-1003162705164",
        "text": "=Critical - {{ $('Get row(s)').item.json.website_url }} is down",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1024,
        128
      ],
      "id": "1148e7e0-c75a-47bf-a236-0a5164065b5e",
      "name": "Send a text message1",
      "webhookId": "a3d62eee-82ae-44ce-923c-60e435f344cb",
      "credentials": {
        "telegramApi": {
          "id": "UN3xoF0IVANIsCNo",
          "name": "Tele Tutorial Bot"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "value": "nsZToo46ixNACYlQ",
          "mode": "list",
          "cachedResultName": "Websites to Monitor",
          "cachedResultUrl": "/projects/iLazCKgG1k9hAivR/datatables/nsZToo46ixNACYlQ"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "website_url",
              "keyValue": "={{ $('Get row(s)').item.json.website_url }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "status_code": 0,
            "downtime_start": "={{ new Date().toISOString() }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "website_url",
              "displayName": "website_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "status_code",
              "displayName": "status_code",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "downtime_start",
              "displayName": "downtime_start",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1232,
        128
      ],
      "id": "20d20a6a-ee22-4d0f-a3c3-1f685a161388",
      "name": "Update row(s)",
      "notesInFlow": true,
      "notes": "Stores in the datatable that the current status of the website is down and the time. The time will allow us to calculate downtime after the website goes back online"
    },
    {
      "parameters": {
        "chatId": "-1003162705164",
        "text": "=Website Back Online - {{ $('Get row(s)').item.json.website_url }}\n\nDowntime - {{ $json.duration }}",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1232,
        -144
      ],
      "id": "03ce7413-0aff-42e3-b2c4-286d1f85897a",
      "name": "Send a text message2",
      "webhookId": "a3d62eee-82ae-44ce-923c-60e435f344cb",
      "credentials": {
        "telegramApi": {
          "id": "UN3xoF0IVANIsCNo",
          "name": "Tele Tutorial Bot"
        }
      }
    },
    {
      "parameters": {
        "operation": "update",
        "dataTableId": {
          "__rl": true,
          "value": "nsZToo46ixNACYlQ",
          "mode": "list",
          "cachedResultName": "Websites to Monitor",
          "cachedResultUrl": "/projects/iLazCKgG1k9hAivR/datatables/nsZToo46ixNACYlQ"
        },
        "filters": {
          "conditions": [
            {
              "keyName": "website_url",
              "keyValue": "={{ $('Get row(s)').item.json.website_url }}"
            }
          ]
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "status_code": 200
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "website_url",
              "displayName": "website_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "readOnly": false,
              "removed": true
            },
            {
              "id": "status_code",
              "displayName": "status_code",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "number",
              "readOnly": false,
              "removed": false
            },
            {
              "id": "downtime_start",
              "displayName": "downtime_start",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "dateTime",
              "readOnly": false,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        1440,
        -144
      ],
      "id": "214fb548-9ab9-4ce3-83a8-dfc83ca7b663",
      "name": "Update row(s)1",
      "notesInFlow": true,
      "notes": "Updates the statuscode of the website in the datatable to 200. Website is back online."
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        736,
        256
      ],
      "id": "6abed536-917e-4e06-971b-4d624506b6d1",
      "name": "No Operation, do nothing",
      "notesInFlow": true,
      "notes": "Workflow ends here if http returns the same status code as the one stored in the datatable, which means nothing changed, the website is either still down or still up"
    },
    {
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "const statusCode = $input.item.json.statusCode === 200 ? 200 : 0;\n\nreturn {\n  json: {\n    is_up: statusCode === 200,\n    statusCode: statusCode,\n  }\n};"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        192,
        112
      ],
      "id": "602124b0-d548-4bea-806e-152cc7d2b8fe",
      "name": "Code in JavaScript",
      "notesInFlow": true,
      "notes": "This handles situation where there is no status codes, like server being down or DNS issues"
    },
    {
      "parameters": {
        "jsCode": "const start = new Date($('Get row(s)').item.json.downtime_start);\nconst now = new Date();\nconst diffMs = now - start;\nconst minutes = Math.floor(diffMs / 60000);\nconst seconds = Math.floor((diffMs % 60000) / 1000);\nreturn { json: { duration: `${minutes}m ${seconds}s` } };"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1024,
        -144
      ],
      "id": "f10c30cb-7b74-464a-b551-8d4f7072f89d",
      "name": "Code in JavaScript1",
      "notesInFlow": true,
      "notes": "Calculates the duration of the downtime by subtracting current datetime with the stored datetime"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 1
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        -464,
        112
      ],
      "id": "54d45951-0071-4cb9-96e7-598859e9d85d",
      "name": "Schedule Trigger"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "7ccf51a4-4270-4f50-a24b-bdbe821e81fb",
              "leftValue": "={{ $json.statusCode }}",
              "rightValue": "={{ $('Get row(s)').item.json.status_code }}",
              "operator": {
                "type": "number",
                "operation": "notEquals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.3,
      "position": [
        416,
        112
      ],
      "id": "1cec9882-0e68-4edd-b44e-d103a7665993",
      "name": "If",
      "notesInFlow": true,
      "notes": "Checks if the status code does not match the status code in the database. If it doesn't match, then something happened, either the website was down and now  it is up, or the website was up and now its down"
    }
  ],
  "pinData": {},
  "connections": {
    "Get row(s)": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Code in JavaScript",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If2": {
      "main": [
        [
          {
            "node": "Code in JavaScript1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Send a text message1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message1": {
      "main": [
        [
          {
            "node": "Update row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send a text message2": {
      "main": [
        [
          {
            "node": "Update row(s)1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript1": {
      "main": [
        [
          {
            "node": "Send a text message2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get row(s)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "If2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": false
  },
  "versionId": "963ca16a-1c67-4c40-aa51-bcbe59427d87",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "e592fdf17e0f5e1e2d257cb5482246d085959171f9a8a3e9366dee0ceb93a8c3"
  },
  "id": "sDvjCjcRPlR7vW50",
  "tags": [
    {
      "updatedAt": "2025-09-28T06:03:19.526Z",
      "createdAt": "2025-09-28T06:03:19.526Z",
      "id": "g1yQiwxKDgmaEhhx",
      "name": "Monitoring"
    }
  ]
}