{
  "name": "Uptime check log",
  "nodes": [
    {
      "id": "3421338c-dc8d-4345-af02-bae8720b8b7c",
      "name": "Every hour",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.4,
      "position": [
        -800,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "expression": "0 * * * *",
              "field": "cronExpression"
            }
          ]
        }
      }
    },
    {
      "id": "fd633a64-c19b-40df-8db7-59c6fd48dcb4",
      "name": "Check example.com",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.5,
      "position": [
        -560,
        0
      ],
      "parameters": {
        "method": "GET",
        "options": {
          "response": {
            "response": {
              "fullResponse": true,
              "neverError": true,
              "outputPropertyName": "data",
              "responseFormat": "text"
            }
          }
        },
        "url": "https://example.com"
      }
    },
    {
      "id": "55cf0295-265a-41d9-8fc6-dc6c9000897c",
      "name": "Is it up?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.4,
      "position": [
        -320,
        0
      ],
      "parameters": {
        "conditions": {
          "combinator": "and",
          "conditions": [
            {
              "id": "a1b2c3d4-1111-4222-8333-444455556666",
              "leftValue": "={{ $json.statusCode }}",
              "operator": {
                "operation": "equals",
                "type": "number"
              },
              "rightValue": 200
            }
          ],
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 4
          }
        },
        "looseTypeValidation": false,
        "options": {
          "ignoreCase": true
        }
      }
    },
    {
      "id": "10653dfc-6c57-4913-9248-6b1646f59bad",
      "name": "Build OK line",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -80,
        -140
      ],
      "parameters": {
        "jsCode": "// One CSV line for a site that answered 200.\n// checked_at is the run time in ISO format; the URL comes from the\n// HTTP Request node's own parameters, so the line always names the\n// site that was actually checked.\nconst item = $input.first().json;\nconst esc = (v) => {\n  const s = String(v ?? '');\n  return /[\",\\n]/.test(s) ? '\"' + s.replace(/\"/g, '\"\"') + '\"' : s;\n};\nconst url = $('Check example.com').params.url;\nconst line = [$now.toISO(), url, item.statusCode, 'OK'].map(esc).join(',');\nreturn [{ json: { line: line + '\\n' } }];",
        "mode": "runOnceForAllItems"
      }
    },
    {
      "id": "8d3ed31e-3d3a-47d6-a991-39b59dbf485d",
      "name": "To text file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.2,
      "position": [
        160,
        -140
      ],
      "parameters": {
        "binaryPropertyName": "data",
        "operation": "toText",
        "options": {
          "addBOM": false,
          "fileName": "uptime.csv"
        },
        "sourceProperty": "line"
      }
    },
    {
      "id": "cb0d641a-6be4-44ee-8b82-dc1826a8fff1",
      "name": "Append OK",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [
        400,
        -140
      ],
      "parameters": {
        "dataPropertyName": "data",
        "fileName": "/home/hatch/.n8n-files/uptime.csv",
        "operation": "write",
        "options": {
          "append": true
        }
      }
    },
    {
      "id": "b0e65057-af2b-4c59-9cb1-c9eed3a65f5f",
      "name": "Build FAIL line",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -80,
        140
      ],
      "parameters": {
        "jsCode": "// One CSV line for a site that did not answer 200.\n// The status is the real code the site returned, so a 404 and a 500\n// do not look the same in the log.\nconst item = $input.first().json;\nconst esc = (v) => {\n  const s = String(v ?? '');\n  return /[\",\\n]/.test(s) ? '\"' + s.replace(/\"/g, '\"\"') + '\"' : s;\n};\nconst url = $('Check example.com').params.url;\nconst line = [$now.toISO(), url, item.statusCode, 'FAIL'].map(esc).join(',');\nreturn [{ json: { line: line + '\\n' } }];",
        "mode": "runOnceForAllItems"
      }
    },
    {
      "id": "24b22007-adb2-4b1b-ab81-519d74fb0c3f",
      "name": "To text file (FAIL)",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.2,
      "position": [
        160,
        140
      ],
      "parameters": {
        "binaryPropertyName": "data",
        "operation": "toText",
        "options": {
          "addBOM": false,
          "fileName": "uptime.csv"
        },
        "sourceProperty": "line"
      }
    },
    {
      "id": "378e2283-316b-4e12-ab1b-d417050796cd",
      "name": "Append FAIL",
      "type": "n8n-nodes-base.readWriteFile",
      "typeVersion": 1.1,
      "position": [
        400,
        140
      ],
      "parameters": {
        "dataPropertyName": "data",
        "fileName": "/home/hatch/.n8n-files/uptime.csv",
        "operation": "write",
        "options": {
          "append": true
        }
      }
    }
  ],
  "connections": {
    "Build FAIL line": {
      "main": [
        [
          {
            "index": 0,
            "node": "To text file (FAIL)",
            "type": "main"
          }
        ]
      ]
    },
    "Build OK line": {
      "main": [
        [
          {
            "index": 0,
            "node": "To text file",
            "type": "main"
          }
        ]
      ]
    },
    "Check example.com": {
      "main": [
        [
          {
            "index": 0,
            "node": "Is it up?",
            "type": "main"
          }
        ]
      ]
    },
    "Every hour": {
      "main": [
        [
          {
            "index": 0,
            "node": "Check example.com",
            "type": "main"
          }
        ]
      ]
    },
    "Is it up?": {
      "main": [
        [
          {
            "index": 0,
            "node": "Build OK line",
            "type": "main"
          }
        ],
        [
          {
            "index": 0,
            "node": "Build FAIL line",
            "type": "main"
          }
        ]
      ]
    },
    "To text file": {
      "main": [
        [
          {
            "index": 0,
            "node": "Append OK",
            "type": "main"
          }
        ]
      ]
    },
    "To text file (FAIL)": {
      "main": [
        [
          {
            "index": 0,
            "node": "Append FAIL",
            "type": "main"
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": null
}