feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新: 1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持 2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储 3. 新增插件分类字段支持,用于场景库分组管理 4. 优化 xq0034/0037/0048 等插件的功能及描述 5. 修复控制面响应兼容问题,支持新旧版本数据格式 6. 新增 xq0033 插件的状态存储模块,用于历史记录管理 7. 优化 CRM 登录窗口模式,支持全屏置顶
This commit is contained in:
@@ -9,12 +9,13 @@ import json
|
||||
import secrets
|
||||
import time
|
||||
|
||||
from fastapi import APIRouter, Header, HTTPException, Query
|
||||
from fastapi import APIRouter, Header, HTTPException, Query, Request
|
||||
from fastapi.responses import FileResponse
|
||||
|
||||
from controlplane import config, crypto, schemas
|
||||
from controlplane.core.auth import _check_token, _cloud_account
|
||||
from controlplane.core.db import _audit, _db, _now
|
||||
from controlplane.core.logstore import append_shell_log, store_run_log
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -221,6 +222,49 @@ def runtime_report(b: schemas.RuntimeReportIn,
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.post("/api/runtime/logs")
|
||||
def runtime_logs(b: schemas.RunLogIn,
|
||||
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
|
||||
"""接收部署端回传的一次运行完整日志(按 run_id 幂等 upsert,离线补报安全)。
|
||||
|
||||
运行日志正文(JSON 数组)存 run_logs 表 logs 列,供管理端「运行日志」集中排查,
|
||||
无需再去执行机本机翻日志。
|
||||
"""
|
||||
_check_token(x_api_token)
|
||||
payload = b.model_dump()
|
||||
store_run_log(payload)
|
||||
return {"ok": True, "run_id": b.run_id}
|
||||
|
||||
|
||||
@router.post("/api/runtime/shell-log")
|
||||
async def runtime_shell_log(request: Request,
|
||||
device_id: str = Query(...),
|
||||
account: str = Query(default=""),
|
||||
hostname: str = Query(default=""),
|
||||
client_version: str = Query(default=""),
|
||||
reset: int = Query(default=0),
|
||||
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
|
||||
"""接收部署端壳日志增量回传(原始字节体,O_APPEND 追加落盘 logs/shell/<device_id>.log)。
|
||||
|
||||
reset=1 表示客户端日志已轮转,先截断文件再写入(避免旧内容残留重复)。
|
||||
单次体积上限 SHELL_LOG_CHUNK_MAX,防止恶意灌爆。
|
||||
"""
|
||||
_check_token(x_api_token)
|
||||
device_id = (device_id or "").strip()
|
||||
if not device_id:
|
||||
raise HTTPException(400, "device_id 不能为空")
|
||||
body = await request.body()
|
||||
if len(body) > config.SHELL_LOG_CHUNK_MAX:
|
||||
raise HTTPException(413, f"单次回传超过大小上限({config.SHELL_LOG_CHUNK_MAX // (1024 * 1024)}MB)")
|
||||
try:
|
||||
result = append_shell_log(device_id, body, account=account or "",
|
||||
hostname=hostname or "", client_version=client_version or "",
|
||||
reset=bool(reset))
|
||||
except ValueError as e:
|
||||
raise HTTPException(400, str(e))
|
||||
return {"ok": True, "device_id": result["device_id"], "size_bytes": result["size_bytes"]}
|
||||
|
||||
|
||||
@router.post("/api/device/report")
|
||||
def device_report(b: schemas.DeviceReportIn,
|
||||
x_api_token: str = Header(default="", alias="X-API-Token")) -> dict:
|
||||
|
||||
Reference in New Issue
Block a user