8
n8n 中文网amn8n.com

网站可用性监控与Gmail警报

高级

这是一个DevOps领域的自动化工作流,包含 18 个节点。主要使用 Set, Wait, Gmail, Merge, Switch 等节点。 通过Gmail警报监控网站可用性

前置要求
  • Google 账号和 Gmail API 凭证
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "c8c9ba5d3eb26ae47a06d24ff164a01c0d73ed4753a74903c2bb609d434a0f6b",
    "templateId": "2327",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "472ecaf7-5a7b-4183-962d-25c983983948",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        760,
        500
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7239b102-b4dd-4276-a25c-99b761ad74e9",
      "name": "计算状态",
      "type": "n8n-nodes-base.set",
      "position": [
        2040,
        500
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b0cbcff5-bfcf-46a5-a386-65c4dd56c42f",
              "name": "date",
              "type": "string",
              "value": "={{ $json.headers.date }}"
            },
            {
              "id": "8c4155e4-bcc6-41dd-9582-346a57a7b997",
              "name": "website",
              "type": "string",
              "value": "={{ $('Split Out').item.json.Websites }}"
            },
            {
              "id": "9af72278-5b29-406a-b4c5-f47f3d805063",
              "name": "IS_UP",
              "type": "boolean",
              "value": "={{ $json.statusCode <= 400  }}"
            }
          ]
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "3eed99d5-13dd-4767-b139-d3140c0bec90",
      "name": "发送邮件警报",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1540,
        1060
      ],
      "webhookId": "0b8b6c5a-1097-4d68-a241-6ca1a1f32929",
      "parameters": {
        "sendTo": "={{ $('Config').item.json.alert_email }}",
        "message": "=From: n8n uptime\nDate: {{ $('Calculate Status').item.json[\"date\"] }}\n\n{{ $('Calculate Status').item.json.website }} is DOWN.",
        "options": {
          "senderName": "n8n uptime",
          "appendAttribution": false
        },
        "subject": "=n8n uptime: {{ $('Calculate Status').item.json.website }} is DOWN.",
        "emailType": "text"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "E3alb5H7xlfxfBur",
          "name": "Jim Halpert"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "7ba3adb6-7348-4a60-a8f3-b3177f757294",
      "name": "执行站点测试",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        1540,
        500
      ],
      "parameters": {
        "url": "={{ $json.Websites }}",
        "options": {
          "batching": {
            "batch": {}
          },
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": true
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1a638f2b-da10-41a4-bc13-4280f108c091",
      "name": "状态路由器",
      "type": "n8n-nodes-base.switch",
      "position": [
        2280,
        500
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "UP",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7191e7cb-f2e1-4288-aa68-21f6efefafc5",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.IS_UP }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "DOWN",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e07edddc-70be-46ed-9f5c-7fba0ed52bc3",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.IS_UP }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "9930468f-d6b5-4555-abc2-58a2079d1734",
      "name": "拆分输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1360,
        500
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "Websites"
      },
      "typeVersion": 1
    },
    {
      "id": "a61137b7-eb31-492f-83ee-bb5a5f640025",
      "name": "配置",
      "type": "n8n-nodes-base.set",
      "position": [
        960,
        500
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "72b729c6-e0af-46f0-955f-c649e9d397bc",
              "name": "Websites",
              "type": "string",
              "value": "=https://smoothwork.ai\nhttps://bad.url\nhttps://smoothwork.ai/notfound\n"
            },
            {
              "id": "25457f32-6440-404d-8e99-eb772e552982",
              "name": "wait_secs",
              "type": "number",
              "value": 5
            },
            {
              "id": "3977a803-b90d-4cea-b995-730a76b2a567",
              "name": "alert_email",
              "type": "string",
              "value": "your_email@gmail.com"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c6f609de-0665-4edd-8f5c-9f29755df675",
      "name": "计算状态1",
      "type": "n8n-nodes-base.set",
      "position": [
        2040,
        760
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "b0cbcff5-bfcf-46a5-a386-65c4dd56c42f",
              "name": "date",
              "type": "string",
              "value": "={{ $json.headers.date }}"
            },
            {
              "id": "8c4155e4-bcc6-41dd-9582-346a57a7b997",
              "name": "website",
              "type": "string",
              "value": "={{ $('Split Out').item.json.Websites }}"
            },
            {
              "id": "9af72278-5b29-406a-b4c5-f47f3d805063",
              "name": "IS_UP",
              "type": "boolean",
              "value": "={{ $json.statusCode <= 400  }}"
            }
          ]
        }
      },
      "typeVersion": 3.3
    },
    {
      "id": "99b6c3a6-d874-4dad-ab5c-f2191158508a",
      "name": "执行站点测试1",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueErrorOutput",
      "position": [
        1540,
        760
      ],
      "parameters": {
        "url": "={{ $json.Websites }}",
        "options": {
          "batching": {
            "batch": {}
          },
          "response": {
            "response": {
              "neverError": true,
              "fullResponse": true
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "33584ca6-caf9-4059-b008-1fd8131207e3",
      "name": "状态路由器1",
      "type": "n8n-nodes-base.switch",
      "position": [
        2220,
        760
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "UP",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7191e7cb-f2e1-4288-aa68-21f6efefafc5",
                    "operator": {
                      "type": "boolean",
                      "operation": "true",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.IS_UP }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "DOWN",
              "conditions": {
                "options": {
                  "version": 1,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "e07edddc-70be-46ed-9f5c-7fba0ed52bc3",
                    "operator": {
                      "type": "boolean",
                      "operation": "false",
                      "singleValue": true
                    },
                    "leftValue": "={{ $json.IS_UP }}",
                    "rightValue": ""
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "33fe7424-fab8-4c48-8165-ed81cc3a676f",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        780,
        680
      ],
      "parameters": {
        "width": 360,
        "height": 280,
        "content": "# 如果网站宕机,获取通知"
      },
      "typeVersion": 1
    },
    {
      "id": "4cc57d3a-c91e-490c-9f13-663cc4aa172f",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        780,
        960
      ],
      "parameters": {
        "width": 360,
        "height": 200,
        "content": "# 说明"
      },
      "typeVersion": 1
    },
    {
      "id": "79b8d891-c24c-48db-b059-150fe7f833a8",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        900,
        400
      ],
      "parameters": {
        "color": 3,
        "content": "## 👇👇 在此处添加您的网站"
      },
      "typeVersion": 1
    },
    {
      "id": "da29d998-597c-40ca-b13d-18f80557ed6a",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        400
      ],
      "parameters": {
        "color": 3,
        "content": "## 👇👇 编辑计划"
      },
      "typeVersion": 1
    },
    {
      "id": "139dca56-a9aa-41a9-93b3-19651b647a41",
      "name": "网站转数组",
      "type": "n8n-nodes-base.set",
      "position": [
        1160,
        500
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "ce076f11-d745-43a9-8069-a55759ceb0c9",
              "name": "Websites",
              "type": "array",
              "value": "={{\n  // we split by line, and only keep non-empty lines\n  $json.Websites.split('\\n').filter((url) => url)\n}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "3ea70e14-f2e6-4879-a5bb-bece6e487a92",
      "name": "合并错误与成功",
      "type": "n8n-nodes-base.merge",
      "position": [
        1820,
        500
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "8b214988-91c5-48d1-ad4d-3b23e846f33a",
      "name": "合并错误与成功1",
      "type": "n8n-nodes-base.merge",
      "position": [
        1820,
        760
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "eb077379-89e7-46b2-bd92-6450b4e895d5",
      "name": "第二次尝试前等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        2540,
        520
      ],
      "webhookId": "f66ae3bf-225b-40f3-a091-b0d765bc35b7",
      "parameters": {
        "amount": "={{ $('Config').item.json.wait_secs }}"
      },
      "typeVersion": 1.1
    }
  ],
  "pinData": {},
  "connections": {
    "Config": {
      "main": [
        [
          {
            "node": "Websites to Array",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Perform Site Test",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Router": {
      "main": [
        [],
        [
          {
            "node": "Wait before Second Attempt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Router1": {
      "main": [
        [],
        [
          {
            "node": "Send Email Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Status": {
      "main": [
        [
          {
            "node": "Status Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Email Alert": {
      "main": [
        []
      ]
    },
    "Calculate Status1": {
      "main": [
        [
          {
            "node": "Status Router1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Perform Site Test": {
      "main": [
        [
          {
            "node": "Merge Error & Success",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge Error & Success",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Websites to Array": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Perform Site Test1": {
      "main": [
        [
          {
            "node": "Merge Error & Success1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Merge Error & Success1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Merge Error & Success": {
      "main": [
        [
          {
            "node": "Calculate Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge Error & Success1": {
      "main": [
        [
          {
            "node": "Calculate Status1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait before Second Attempt": {
      "main": [
        [
          {
            "node": "Perform Site Test1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 开发运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量18
分类1
节点类型9
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Milan Vasarhelyi - SmoothWork

Milan Vasarhelyi - SmoothWork

@vasarmilan

We help you eliminate the busywork by building compact business tools tailored to your processes. 📞: https://smoothwork.ai/book-a-call ▶️: https://www.youtube.com/@vasarmilan

外部链接
在 n8n.io 查看

分享此工作流