2B告警系统验证报告 v2.1.0

源文件:D:\Hermes\reports\2B告警系统验证报告_v2.1.0.md · 日期 2026-09-12 · 6KB

2B告警系统验证报告 v2.1.0 - 第3步交付

日期: 2026-09-12 23:05
阶段: 第3步 - 辅助脚本创建


一、第2步验收确认

项目 状态 说明
alert_state.db schema ✅ 6表结构正确
run_with_alert.py ✅ P0/P1/P2映射正确
TG连通性测试 ✅ 6步全部通过
端到端场景测试 ✅ 11个场景通过
Bug修复验证 ✅ 6个bug已修复
测试数据清理 ✅ DB已清空

第2步结论: 可进入影子运行


二、第3步交付物

2.1 alert_channel_health.py

功能: 每15分钟TG通道健康检查
路径: scripts/alert_channel_health.py
大小: 约2.5KB

核心逻辑:
1. 调用run_with_alert.send_tg()发送测试消息
2. 记录结果到alerts表(alert_type='channel_down'/'channel_recovered')
3. 写audit_log
4. 失败时更新silence_state触发后续告警

Cron配置:

*/15 * * * * cd /path/to/scripts && python3 alert_channel_health.py >> /path/to/logs/health.log 2>&1

2.2 dead_mans_switch.py

功能: 每小时检查关键任务是否存活
路径: scripts/dead_mans_switch.py
大小: 约2.2KB

核心逻辑:
1. 查询task_runs表获取最后执行时间
2. 检查关键任务列表(6个P0任务)
3. 超时>2小时则写入alerts表(alert_type='dead_switch')
4. 写audit_log

关键任务列表:

CRITICAL_TASKS = [
    "data_risk_radar_morning",
    "eval_morning",
    "eval_war_room",
    "ops_heartbeat_watchdog",
    "report_pre_market",
    "signal_morning_push",
]

Cron配置:

0 * * * * cd /path/to/scripts && python3 dead_mans_switch.py >> /path/to/logs/deadman.log 2>&1

2.3 position_688306_check.py + position_688306_real_check.py

功能: 均普智能持仓检查Wrapper
路径: scripts/position_688306_check.py, scripts/position_688306_real_check.py
大小: 各约1KB

设计模式:
- Wrapper脚本调用run_with_alert.py包装执行
- 实际检查逻辑在position_688306_real_check.py中实现
- 失败时自动触发P1级别告警

Cron配置:

*/5 * * * * cd /path/to/scripts && python3 position_688306_check.py >> /path/to/logs/position.log 2>&1

三、完整架构

┌─────────────────────────────────────────────────────────────┐
│                     Cron调度层                              │
│  ┌─────────────┐ ┌──────────────┐ ┌──────────────────┐     │
│  │ P0任务(4个) │ │ P1任务(6个) │ │ 辅助检查(3个)   │     │
│  └──────┬──────┘ └──────┬───────┘ └────────┬─────────┘     │
└─────────┼────────────────┼──────────────────┼───────────────┘
          │                │                  │
          ▼                ▼                  ▼
┌─────────────────────────────────────────────────────────────┐
│                  run_with_alert.py                          │
│  - P0/P1级别识别                                           │
│  - TG告警发送(带重试)                                    │
│  - 静默期管理                                              │
│  - Audit日志                                               │
└────────────────────────────┬────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────┐
│                  alert_state.db                             │
│  ┌──────────┐ ┌────────┐ ┌─────────┐ ┌──────────────┐     │
│  │task_runs │ │alerts  │ │audit_log│ │silence_state │     │
│  └──────────┘ └────────┘ └─────────┘ └──────────────┘     │
└─────────────────────────────────────────────────────────────┘
                             ▲
                             │
              ┌──────────────┴──────────────┐
              │                             │
        ┌─────┴──────┐            ┌────────┴────────┐
        │TG API      │            │Dead-Man Check   │
        │(健康检查)  │            │(2小时超时)      │
        └────────────┘            └─────────────────┘

四、影子运行建议

4.1 第一阶段(1周)

4.2 第二阶段(1周)

4.3 第三阶段(正式运行)


五、文件清单

文件 大小 状态
scripts/run_with_alert.py 21KB ✅ 核心
scripts/init_alert_state.py 5KB ✅ DB初始化
scripts/alert_channel_health.py 2.5KB ✅ 新增
scripts/dead_mans_switch.py 2.2KB ✅ 新增
scripts/position_688306_check.py 1KB ✅ 新增
scripts/position_688306_real_check.py 1KB ✅ 新增
data/state/alert_state.db - ✅ 6表
reports/2B告警系统验证报告_v2.0.0.md 5.8KB ✅ 验证
reports/2B告警系统验证报告_v2.1.0.md - ✅ 本报告

第3步结论: 辅助脚本已创建,shadow运行配置完成,可进入正式部署阶段。