feat(aiot): 边缘告警HTTP上报 + 移除配置中转层
- 新增 edge/report 端点接收边缘端HTTP告警上报 - alarm_event_service 新增 create_from_edge_report 幂等创建 - schemas 新增 EdgeAlarmReport 模型 - 移除 config_service/redis_service/yudao_aiot_config 配置中转 - MQTT 服务标记废弃,告警上报改为HTTP+COS - config 新增 COS/Redis 配置项 - requirements 新增 redis 依赖 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,9 @@ from datetime import datetime
|
||||
|
||||
from app.yudao_compat import YudaoResponse, get_current_user
|
||||
from app.services.alarm_event_service import get_alarm_event_service, AlarmEventService
|
||||
from app.services.notification_service import get_notification_service
|
||||
from app.services.oss_storage import get_oss_storage
|
||||
from app.schemas import EdgeAlarmReport
|
||||
|
||||
router = APIRouter(prefix="/admin-api/aiot/alarm", tags=["AIoT-告警"])
|
||||
|
||||
@@ -184,6 +186,38 @@ async def get_device_summary_page(
|
||||
)
|
||||
|
||||
|
||||
# ==================== 边缘端告警上报 ====================
|
||||
|
||||
@router.post("/edge/report")
|
||||
async def edge_alarm_report(
|
||||
report: EdgeAlarmReport,
|
||||
service: AlarmEventService = Depends(get_alarm_event_service),
|
||||
current_user: dict = Depends(get_current_user),
|
||||
):
|
||||
"""
|
||||
边缘端告警上报接口
|
||||
|
||||
边缘设备通过 HTTP POST 上报告警元数据,截图已预先上传到 COS。
|
||||
支持幂等:通过 alarm_id 判断是否已存在。
|
||||
"""
|
||||
alarm = service.create_from_edge_report(report.model_dump())
|
||||
|
||||
if alarm is None:
|
||||
return YudaoResponse.error(500, "告警创建失败")
|
||||
|
||||
# WebSocket 通知
|
||||
try:
|
||||
notification_svc = get_notification_service()
|
||||
notification_svc.notify_sync("new_alert", alarm.to_dict())
|
||||
except Exception:
|
||||
pass # WebSocket 通知失败不影响主流程
|
||||
|
||||
return YudaoResponse.success({
|
||||
"alarmId": alarm.alarm_id,
|
||||
"created": True,
|
||||
})
|
||||
|
||||
|
||||
# ==================== 辅助函数 ====================
|
||||
|
||||
def _get_alarm_type_name(alarm_type: Optional[str]) -> str:
|
||||
|
||||
Reference in New Issue
Block a user