fix(monitor): harden server delete and remove challenge docs
- Delete server state before monitored server to avoid FK 500s - Keep legacy cleanup for obsolete challenge tables - Rewrite monitor docs to API key-only flow
This commit is contained in:
@@ -1,68 +1,76 @@
|
||||
# OpenClaw Monitor Agent Plugin 开发计划(草案)
|
||||
# HarborForge Monitor / OpenClaw Plugin Connector Plan
|
||||
|
||||
## 目标
|
||||
让被监测服务器通过 WebSocket 主动接入 HarborForge Backend,并持续上报:
|
||||
- OpenClaw 版本
|
||||
- agent 列表
|
||||
- 每 5 分钟主机指标(CPU/MEM/DISK/SWAP)
|
||||
- agent 状态变更事件
|
||||
|
||||
## 握手流程
|
||||
1. Admin 在 HarborForge 后台添加 server identifier
|
||||
2. Admin 生成 challenge(10 分钟有效)
|
||||
3. 插件请求 `GET /monitor/public/server-public-key` 获取公钥
|
||||
4. 插件构造 payload:
|
||||
- `identifier`
|
||||
- `challenge_uuid`
|
||||
- `nonce`(随机)
|
||||
- `ts`(ISO8601)
|
||||
5. 使用 RSA-OAEP(SHA256) 公钥加密,base64 后作为 `encrypted_payload` 发给 `WS /monitor/server/ws`
|
||||
6. 握手成功后进入事件上报通道
|
||||
使用 **API Key + HTTP heartbeat** 连接 HarborForge Monitor 与远程 OpenClaw 节点。
|
||||
|
||||
## 插件事件协议
|
||||
### server.hello
|
||||
## 认证方式
|
||||
|
||||
- 管理员为服务器生成 API Key
|
||||
- 插件通过 `X-API-Key` 调用 heartbeat 接口
|
||||
- 不再使用 challenge / RSA 公钥 / WebSocket 握手
|
||||
|
||||
## 上报接口
|
||||
|
||||
`POST /monitor/server/heartbeat-v2`
|
||||
|
||||
### Headers
|
||||
- `X-API-Key: <server-api-key>`
|
||||
|
||||
### Payload
|
||||
```json
|
||||
{
|
||||
"event": "server.hello",
|
||||
"payload": {
|
||||
"openclaw_version": "x.y.z",
|
||||
"agents": [{"id": "a1", "name": "agent-1", "status": "idle"}]
|
||||
"identifier": "vps.t1",
|
||||
"openclaw_version": "OpenClaw 2026.3.13 (61d171a)",
|
||||
"plugin_version": "0.1.0",
|
||||
"agents": [
|
||||
{ "id": "agent-bot1", "name": "agent-bot1", "status": "configured" }
|
||||
],
|
||||
"cpu_pct": 12.3,
|
||||
"mem_pct": 45.6,
|
||||
"disk_pct": 78.9,
|
||||
"swap_pct": 0,
|
||||
"load_avg": [0.12, 0.08, 0.03],
|
||||
"uptime_seconds": 12345
|
||||
}
|
||||
```
|
||||
|
||||
## 语义
|
||||
|
||||
- `openclaw_version`: 远程主机上的 OpenClaw 版本
|
||||
- `plugin_version`: harborforge-monitor 插件版本
|
||||
|
||||
## 插件生命周期
|
||||
|
||||
- 插件注册到 Gateway
|
||||
- 在 `gateway_start` 启动 `server/telemetry.mjs`
|
||||
- 在 `gateway_stop` 停止 sidecar
|
||||
|
||||
## 配置位置
|
||||
|
||||
`~/.openclaw/openclaw.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"plugins": {
|
||||
"entries": {
|
||||
"harborforge-monitor": {
|
||||
"enabled": true,
|
||||
"config": {
|
||||
"enabled": true,
|
||||
"backendUrl": "http://127.0.0.1:8000",
|
||||
"identifier": "vps.t1",
|
||||
"apiKey": "your-api-key"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### server.metrics(每 5 分钟)
|
||||
```json
|
||||
{
|
||||
"event": "server.metrics",
|
||||
"payload": {
|
||||
"cpu_pct": 21.3,
|
||||
"mem_pct": 42.1,
|
||||
"disk_pct": 55.9,
|
||||
"swap_pct": 0.0,
|
||||
"agents": [{"id": "a1", "name": "agent-1", "status": "busy"}]
|
||||
}
|
||||
}
|
||||
```
|
||||
## 已废弃
|
||||
|
||||
### agent.status_changed(可选)
|
||||
```json
|
||||
{
|
||||
"event": "agent.status_changed",
|
||||
"payload": {
|
||||
"agents": [{"id": "a1", "name": "agent-1", "status": "focus"}]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 实施里程碑
|
||||
- M1: Node/Python CLI 插件最小握手联通
|
||||
- M2: 指标采集 + 周期上报
|
||||
- M3: agent 状态采集与变更事件
|
||||
- M4: 守护化(systemd)+ 断线重连 + 本地日志
|
||||
|
||||
## 风险与注意事项
|
||||
- 时钟漂移会导致 `ts` 校验失败(建议 NTP)
|
||||
- challenge 仅一次可用,重复使用会被拒绝
|
||||
- nonce 重放会被拒绝
|
||||
- 需要保证插件本地安全保存 identifier/challenge(短期)
|
||||
- challenge UUID
|
||||
- server public key
|
||||
- WebSocket telemetry
|
||||
- encrypted handshake payload
|
||||
|
||||
Reference in New Issue
Block a user