ForcePilot/backend/package/yuxi/channel/extensions/generic_webhook/status.py
Kris 71e90075e2 feat(generic-webhook): 新增通用Webhook管道插件
实现了完整的通用Webhook通道插件,支持入站请求接收、JSONPath字段映射、多种认证方式、出站Webhook推送,以及端点配置管理、去重、安全校验等功能
2026-05-21 10:47:58 +08:00

32 lines
996 B
Python

import logging
import httpx
logger = logging.getLogger("yuxi.channel.generic_webhook.status")
class GenericWebhookStatus:
def __init__(self, config_mgr):
self._config_mgr = config_mgr
async def probe_endpoint(self, endpoint_id: str) -> bool:
endpoint = self._config_mgr.get_endpoint(endpoint_id)
if not endpoint or not endpoint.outbound or not endpoint.outbound.url:
return True
try:
async with httpx.AsyncClient(timeout=5.0) as client:
resp = await client.head(endpoint.outbound.url)
return resp.status_code < 500
except Exception as e:
logger.debug("端点 %s 探活失败: %s", endpoint_id, e)
return False
def build_summary(self) -> dict:
endpoints = self._config_mgr.list_endpoint_ids()
return {
"channel_type": "generic-webhook",
"endpoints_count": len(endpoints),
"endpoints": endpoints,
}