ForcePilot/backend/package/yuxi/channel/extensions/generic_webhook/status.py

32 lines
996 B
Python
Raw Normal View History

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,
}