8
n8n 中文网amn8n.com

旅行供应商监控:自动跟踪 API 健康状态、运行时间与 SLA 合规性

中级

这是一个DevOps领域的自动化工作流,包含 14 个节点。主要使用 If, Code, WhatsApp, DebugHelper, HttpRequest 等节点。 监控 Amadeus 和 Booking.com API 健康状态并通过 WhatsApp 发送 SLA 告警

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "T3nT9lGG91jxyLsK",
  "meta": {
    "instanceId": "dd69efaf8212c74ad206700d104739d3329588a6f3f8381a46a481f34c9cc281",
    "templateCredsSetupCompleted": true
  },
  "name": "旅行供应商监控:自动跟踪 API 健康状态、运行时间与 SLA 合规性",
  "tags": [],
  "nodes": [
    {
      "id": "2a498c6b-abc3-46dd-8acc-5ee0c24570d3",
      "name": "监控计划",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1740,
        -380
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 10
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "677cb112-dc2f-43e6-b1ee-68728d8ae773",
      "name": "Amadeus Flight API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1520,
        -480
      ],
      "parameters": {
        "url": "https://api.amadeus.com/v1/reference-data/airlines",
        "options": {
          "timeout": 8000,
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "json"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "TravelMonitor/1.0"
            }
          ]
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "d4fc7dbe-d36d-49cb-bab0-25bce07ea6be",
      "name": "Booking Hotel API",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -1520,
        -280
      ],
      "parameters": {
        "url": "https://distribution-xml.booking.com/",
        "options": {
          "timeout": 8000,
          "response": {
            "response": {
              "fullResponse": true,
              "responseFormat": "json"
            }
          }
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "TravelMonitor/1.0"
            }
          ]
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "ffe8eb40-5fa7-4d7c-8055-2c6aa780d209",
      "name": "计算健康度与 SLA",
      "type": "n8n-nodes-base.code",
      "position": [
        -1300,
        -380
      ],
      "parameters": {
        "jsCode": "const items = $input.all();\nconst timestamp = new Date().toISOString();\nconst results = [];\n\n// Supplier configurations\nconst suppliers = [\n  { name: 'Amadeus', type: 'Flight API', slaTarget: 99.5 },\n  { name: 'Booking.com', type: 'Hotel API', slaTarget: 99.0 }\n];\n\nfor (let i = 0; i < items.length; i++) {\n  const item = items[i].json;\n  const supplier = suppliers[i];\n  const statusCode = item.statusCode || 0;\n  const isHealthy = statusCode >= 200 && statusCode < 300;\n  const responseTime = item.headers ? 200 : 5000; // Simulated\n  \n  // Calculate uptime percentage (simplified)\n  const uptimePercentage = isHealthy ? 100 : 0;\n  \n  // SLA compliance check\n  const slaCompliant = uptimePercentage >= supplier.slaTarget;\n  const slaStatus = slaCompliant ? '✅ COMPLIANT' : '❌ BREACH';\n  \n  // Health status\n  const healthStatus = isHealthy ? '🟢 HEALTHY' : '🔴 DOWN';\n  \n  // Performance rating\n  let performance;\n  if (responseTime < 500 && isHealthy) performance = '⚡ EXCELLENT';\n  else if (responseTime < 2000 && isHealthy) performance = '✅ GOOD';\n  else if (responseTime < 5000 && isHealthy) performance = '⚠️ AVERAGE';\n  else performance = '❌ POOR';\n  \n  results.push({\n    supplier_name: supplier.name,\n    api_type: supplier.type,\n    timestamp: timestamp,\n    status_code: statusCode,\n    health_status: healthStatus,\n    is_healthy: isHealthy,\n    response_time_ms: responseTime,\n    uptime_percentage: uptimePercentage,\n    sla_target: supplier.slaTarget,\n    sla_status: slaStatus,\n    sla_compliant: slaCompliant,\n    performance_rating: performance,\n    alert_required: !slaCompliant\n  });\n}\n\nreturn results;"
      },
      "typeVersion": 2
    },
    {
      "id": "9959f0f0-1954-4e0d-951b-e927c76f1105",
      "name": "警报检查",
      "type": "n8n-nodes-base.if",
      "position": [
        -1080,
        -380
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "condition1",
              "operator": {
                "type": "boolean",
                "operation": "true"
              },
              "leftValue": "={{ $json.alert_required }}",
              "rightValue": true
            }
          ]
        }
      },
      "typeVersion": 2
    },
    {
      "id": "264ce28a-d467-4c86-8e61-1bc9df4e3083",
      "name": "SLA 违规警报",
      "type": "n8n-nodes-base.debugHelper",
      "position": [
        -860,
        -480
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "50c22357-03a5-480e-9577-642056a97aaa",
      "name": "正常状态日志",
      "type": "n8n-nodes-base.debugHelper",
      "position": [
        -860,
        -280
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "25b1db91-172f-44fc-aee7-b156ae64d486",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1765,
        -480
      ],
      "parameters": {
        "color": 3,
        "width": 150,
        "height": 260,
        "content": "每 10 分钟自动运行一次"
      },
      "typeVersion": 1
    },
    {
      "id": "f4710764-e7a0-4775-b09e-d8f67babd434",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1105,
        -480
      ],
      "parameters": {
        "color": 4,
        "width": 150,
        "height": 260,
        "content": "根据违规状态路由到相应响应"
      },
      "typeVersion": 1
    },
    {
      "id": "0f7024e0-bddd-4433-a2f9-c83d53c25fba",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1325,
        -480
      ],
      "parameters": {
        "color": 5,
        "width": 150,
        "height": 260,
        "content": "处理健康度、运行时间和 SLA 数据"
      },
      "typeVersion": 1
    },
    {
      "id": "efbc2758-2168-4f75-aeed-6036281a4bfd",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -885,
        -660
      ],
      "parameters": {
        "color": 2,
        "width": 150,
        "height": 540,
        "content": "记录结果,违规时发送警报,健康状态时记录正常日志"
      },
      "typeVersion": 1
    },
    {
      "id": "09e1b313-1b20-456c-818a-a4523a443fb3",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1545,
        -660
      ],
      "parameters": {
        "width": 150,
        "height": 540,
        "content": "同时测试 Amadeus Flight API 和 Booking.com Hotel API"
      },
      "typeVersion": 1
    },
    {
      "id": "d21648ba-de83-47fc-bc79-f6c1e87440c5",
      "name": "发送消息",
      "type": "n8n-nodes-base.whatsApp",
      "position": [
        -640,
        -380
      ],
      "webhookId": "8a315367-f3a0-4c84-903a-5a1f708960a7",
      "parameters": {
        "textBody": "{{json.logs}}",
        "operation": "send",
        "phoneNumberId": "=+91999876667877",
        "additionalFields": {},
        "recipientPhoneNumber": "+919886242228"
      },
      "credentials": {
        "whatsAppApi": {
          "id": "b0PxTDPdWzznWnfG",
          "name": "WhatsApp-test "
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f9e4e3f9-2cdf-406e-aed1-1bd4358852cb",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -660,
        -480
      ],
      "parameters": {
        "color": 6,
        "width": 150,
        "height": 260,
        "content": "通过 WhatsApp 发送违规警报"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d4c14b4f-2bee-4cae-a443-49a0f6a2fff6",
  "connections": {
    "Alert Check": {
      "main": [
        [
          {
            "node": "SLA Breach Alert",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Normal Status Log",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Monitor Schedule": {
      "main": [
        [
          {
            "node": "Amadeus Flight API",
            "type": "main",
            "index": 0
          },
          {
            "node": "Booking Hotel API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SLA Breach Alert": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Booking Hotel API": {
      "main": [
        [
          {
            "node": "Calculate Health & SLA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normal Status Log": {
      "main": [
        [
          {
            "node": "Send message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Amadeus Flight API": {
      "main": [
        [
          {
            "node": "Calculate Health & SLA",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Health & SLA": {
      "main": [
        [
          {
            "node": "Alert Check",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 开发运维

需要付费吗?

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

工作流信息
难度等级
中级
节点数量14
分类1
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
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 查看

分享此工作流