8
n8n 中文网amn8n.com

自动化API正常运行时间监控与即时停机警报

高级

这是一个DevOps领域的自动化工作流,包含 17 个节点。主要使用 If, Code, Wait, WhatsApp, HttpRequest 等节点。 API正常运行时间监控,含WhatsApp警报和Google表格管理

前置要求
  • 可能需要目标 API 的认证凭证
  • Google Sheets API 凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "pc2HHg8DLhcpoMg5",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
    "templateCredsSetupCompleted": true
  },
  "name": "自动化 API 正常运行时间监控与即时停机警报",
  "tags": [],
  "nodes": [
    {
      "id": "6050fae8-e86d-481f-bcf5-98461f796b5f",
      "name": "读取 API 列表",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        -2640,
        260
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VKlDZSHicdZhhj-fl-vIIH0mC6VDwdCS4-LqaDIeyw0/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1VKlDZSHicdZhhj-fl-vIIH0mC6VDwdCS4-LqaDIeyw0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1VKlDZSHicdZhhj-fl-vIIH0mC6VDwdCS4-LqaDIeyw0/edit?usp=drivesdk",
          "cachedResultName": "URL For Status Check"
        },
        "combineFilters": "AND"
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "rgIk6EXVdPbmPYAl",
          "name": "Google Sheets account"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "68940a15-d216-4366-8673-71b71305084d",
      "name": "初始化重试计数器",
      "type": "n8n-nodes-base.code",
      "position": [
        -2200,
        185
      ],
      "parameters": {
        "jsCode": "// Initialize retry counter for each API\nconst apiData = $json;\nif (!apiData.retryCount) {\n  apiData.retryCount = 0;\n}\nreturn apiData;"
      },
      "typeVersion": 2
    },
    {
      "id": "06b0731a-81c3-449f-b302-0e9f5e2f9b0d",
      "name": "测试 API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1980,
        185
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "method": "={{ $json.method }}",
        "options": {
          "timeout": 10000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "continueOnFail": true
    },
    {
      "id": "f4450c0b-48fe-40d2-9b68-c54b12980a01",
      "name": "检查响应",
      "type": "n8n-nodes-base.code",
      "position": [
        -1760,
        185
      ],
      "parameters": {
        "jsCode": "// Check if API responded\nconst response = $json;\nconst apiData = $('Init Retry Counter').first().json;\n\nlet hasResponse = response && typeof response === 'object' && Object.keys(response).length > 0;\n\nreturn {\n  ...apiData,\n  hasResponse: hasResponse\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "886d69dd-e847-4cf7-badb-5d5a02e8cfcd",
      "name": "如果无响应",
      "type": "n8n-nodes-base.if",
      "position": [
        -1540,
        185
      ],
      "parameters": {
        "options": {
          "looseTypeValidation": true
        },
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "no-response",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.hasResponse }}",
              "rightValue": "=false"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "be9792e7-be19-47e3-9621-613f1cc8d611",
      "name": "等待 10 分钟",
      "type": "n8n-nodes-base.wait",
      "position": [
        -1320,
        110
      ],
      "webhookId": "b89a5cda-2fa5-40ad-b534-ed607a47c847",
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "4fdd9d39-af72-42d7-9d81-0e878920709b",
      "name": "增加重试",
      "type": "n8n-nodes-base.code",
      "position": [
        -1100,
        35
      ],
      "parameters": {
        "jsCode": "// Increment retry count\nconst data = $json;\ndata.retryCount = (data.retryCount || 0) + 1;\nreturn data;"
      },
      "typeVersion": 2
    },
    {
      "id": "c71871bb-7416-4a58-b5b6-d0c326856c62",
      "name": "重试 API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -880,
        35
      ],
      "parameters": {
        "url": "={{ $json.url }}",
        "method": "={{ $json.method }}",
        "options": {
          "timeout": 10000
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2,
      "continueOnFail": true
    },
    {
      "id": "5567bff2-495e-4b96-adbc-9d5aa290398a",
      "name": "检查重试响应",
      "type": "n8n-nodes-base.code",
      "position": [
        -660,
        35
      ],
      "parameters": {
        "jsCode": "// Check retry response\nconst response = $json;\nconst apiData = $('Increment Retry').first().json;\n\nlet hasResponse = response && typeof response === 'object' && Object.keys(response).length > 0;\n\nreturn {\n  ...apiData,\n  hasResponse: hasResponse\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "56590da0-6e35-430b-b380-066322cdb528",
      "name": "如果仍然无响应",
      "type": "n8n-nodes-base.if",
      "position": [
        -440,
        35
      ],
      "parameters": {
        "options": {
          "looseTypeValidation": true
        },
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "still-no-response",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.expectedStatusCode === null || $json.expectedStatusCode === undefined || $json.expectedStatusCode === '' }}",
              "rightValue": "=false"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "1c206215-fe56-48f6-87f0-e1875e664d80",
      "name": "格式化停机警报",
      "type": "n8n-nodes-base.code",
      "position": [
        0,
        -40
      ],
      "parameters": {
        "jsCode": "// Create down alert message\nconst api = $json;\n\nconst alertMessage = `🚨 API DOWN ALERT\\n\\n📋 ${api.name}\\n🌐 ${api.url}\\n⏰ ${new Date().toISOString()}`;\n\nreturn {\n  ...api,\n  alertMessage: alertMessage\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "96024d21-5201-4629-9eef-547c49994d4f",
      "name": "发送 WhatsApp 警报",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        220,
        -40
      ],
      "webhookId": "b8bca051-44db-4578-a849-6fdf7559609d",
      "parameters": {
        "textBody": "={{ $json.alertMessage }}",
        "operation": "send",
        "phoneNumberId": "550325331503475",
        "additionalFields": {},
        "recipientPhoneNumber": "+919974388925"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "3hy4gzpVJrY1sFcR",
          "name": "WhatsApp account API"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "42753397-1223-4fc5-8df0-a340a64fc731",
      "name": "继续下一个 API",
      "type": "n8n-nodes-base.code",
      "position": [
        440,
        260
      ],
      "parameters": {
        "jsCode": "// Continue to next API\nconst data = $json;\nif (data.hasResponse) {\n  data.retryCount = 0;\n}\nreturn data;"
      },
      "typeVersion": 2
    },
    {
      "id": "1f5c7218-68d3-4878-a238-36ca0ad31764",
      "name": "处理每个 API1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -2420,
        260
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "0b1af6a3-bf8e-4398-917e-f2526449ad6b",
      "name": "如果仍然无重试 > 4",
      "type": "n8n-nodes-base.if",
      "position": [
        -220,
        -40
      ],
      "parameters": {
        "options": {
          "looseTypeValidation": true
        },
        "conditions": {
          "options": {
            "version": 1,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "loose"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "still-no-response",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.retryCount >= 4}}",
              "rightValue": "=false"
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d2bb51d4-2ace-4a9c-8a7c-25c588de3063",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -2860,
        260
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 15
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "3fda8d5d-5311-4804-afef-4ec25ed3c92f",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2420,
        -340
      ],
      "parameters": {
        "color": 4,
        "width": 1220,
        "height": 340,
        "content": "## 工作原理"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2eee3704-de38-4436-9d22-57252c0ff118",
  "connections": {
    "Test API": {
      "main": [
        [
          {
            "node": "Check Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Retry API": {
      "main": [
        [
          {
            "node": "Check Retry Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait 10 Min": {
      "main": [
        [
          {
            "node": "Increment Retry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read API List": {
      "main": [
        [
          {
            "node": "Process Each API1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Response": {
      "main": [
        [
          {
            "node": "If No Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If No Response": {
      "main": [
        [
          {
            "node": "Wait 10 Min",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Continue Next API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Increment Retry": {
      "main": [
        [
          {
            "node": "Retry API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Read API List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Continue Next API": {
      "main": [
        [
          {
            "node": "Process Each API1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Down Alert": {
      "main": [
        [
          {
            "node": "Send WhatsApp Alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process Each API1": {
      "main": [
        [],
        [
          {
            "node": "Init Retry Counter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Init Retry Counter": {
      "main": [
        [
          {
            "node": "Test API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send WhatsApp Alert": {
      "main": [
        [
          {
            "node": "Continue Next API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Retry Response": {
      "main": [
        [
          {
            "node": "If Still No Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Still No Response": {
      "main": [
        [
          {
            "node": "If Still No Retry > 4",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Continue Next API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If Still No Retry > 4": {
      "main": [
        [
          {
            "node": "Format Down Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait 10 Min",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 开发运维

需要付费吗?

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

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

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

作者
Oneclick AI Squad

Oneclick AI Squad

@oneclick-ai

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

外部链接
在 n8n.io 查看

分享此工作流