Site checker with Telegram warning

Every now and then I need to make sure my site is online. This workflow checks the status code and sends a message if something changed.

To keep the previous status, it uses a text file. If you run n8n with docker, make sure you have the data/ folder in a Volume.

{
  "nodes": [
    {
      "parameters": {
        "command": "wget --spider -S \"https://DOMAIN.TLD\" 2>&1 | grep \"HTTP/\" | awk '{print $2}'"
      },
      "name": "Execute Command",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        340,
        240
      ]
    },
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "mode": "custom",
              "cronExpression": "=* * * * *"
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        140,
        460
      ]
    },
    {
      "parameters": {
        "chatId": "48263287",
        "text": "={{$node[\"Execute Command\"].data[\"stdout\"]}}",
        "additionalFields": {}
      },
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1130,
        490
      ],
      "credentials": {
        "telegramApi": "Johnny Five"
      }
    },
    {
      "parameters": {
        "conditions": {
          "number": [
            {
              "value1": "={{$node[\"Set1\"].data[\"oldStatus\"]}}",
              "operation": "equal",
              "value2": "={{$node[\"Set\"].data[\"newStatus\"]}}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        830,
        480
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1140,
        280
      ]
    },
    {
      "parameters": {
        "command": "cat /data/status"
      },
      "name": "Execute Command1",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        340,
        760
      ]
    },
    {
      "parameters": {
        "command": "=> /data/status; echo '{{$node[\"Set\"].data[\"newStatus\"]}}' >> /data/status"
      },
      "name": "Execute Command2",
      "type": "n8n-nodes-base.executeCommand",
      "typeVersion": 1,
      "position": [
        1130,
        720
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "newStatus",
              "value": "={{$node[\"Execute Command\"].data[\"stdout\"]}}"
            }
          ]
        }
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        670,
        250
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "oldStatus",
              "value": "={{$node[\"Execute Command1\"].data[\"stdout\"]}}"
            }
          ]
        }
      },
      "name": "Set1",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        670,
        760
      ]
    }
  ],
  "connections": {
    "Execute Command": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cron": {
      "main": [
        [
          {
            "node": "Execute Command",
            "type": "main",
            "index": 0
          },
          {
            "node": "Execute Command1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          },
          {
            "node": "Execute Command2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Command1": {
      "main": [
        [
          {
            "node": "Set1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set1": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes