feat(alerts): 添加微信告警、WebSocket实时推送和地图功能

- 新增微信告警服务(wechat_service)和告警任务(alert_tasks)
- 新增 WebSocket 实时推送端点
- 新增监控管理模块(monitor)
- 增强统计仪表板:趋势图、区域分布、光功率历史
- 设备管理:添加坐标信息、标签系统、复合索引优化
- 前端:重构Dashboard/Charts页面,新增业务组件
- 新增5个数据库迁移(坐标、复合索引、标签、光功率历史、显示名)
- 更新部署配置和脚本
- 新增测试框架基础结构
This commit is contained in:
2026-06-11 15:16:29 +08:00
parent 3453441754
commit b2c20ec43d
45 changed files with 2089 additions and 107 deletions
+24 -6
View File
@@ -1,4 +1,5 @@
"""设备状态检查服务"""
import time
from typing import List, Dict, Optional
from sqlalchemy.orm import Session
from app.services.ssh_service import SSHService
@@ -6,6 +7,26 @@ from app.models.device import OLTDevice, ONUDevice, DeviceStatusHistory, Duplica
from datetime import datetime
import re
# SSH 连接池缓存,TTL 5 分钟
_conn_pool: Dict[int, tuple[SSHService, float]] = {}
_POOL_TTL = 300
def _get_cached_ssh(olt_ip: str, olt_user: str, olt_pass: str, olt_id: int) -> SSHService:
"""获取缓存的 SSH 连接,过期自动重连"""
entry = _conn_pool.get(olt_id)
if entry:
ssh, ts = entry
if time.time() - ts < _POOL_TTL:
return ssh
try:
ssh.close()
except Exception:
pass
ssh = SSHService(olt_ip, olt_user, olt_pass)
ssh.connect()
_conn_pool[olt_id] = (ssh, time.time())
return ssh
def parse_distance(distance_str: Optional[str]) -> Optional[int]:
"""将距离字符串转为整数,如 '<1000' -> 1000, '1234' -> 1234"""
@@ -29,9 +50,8 @@ class CheckService:
if not olt:
raise Exception(f"OLT 设备不存在: {olt_id}")
ssh = SSHService(olt.ip_address, olt.username, olt.password)
ssh = _get_cached_ssh(olt.ip_address, olt.username, olt.password, olt_id)
try:
ssh.connect()
output = ssh.execute_command(olt.slot_command)
onu_info_dict, _ = ssh.parse_onu_info(output)
@@ -160,9 +180,8 @@ class CheckService:
if not olt:
raise Exception(f"OLT 设备不存在: {olt_id}")
ssh = SSHService(olt.ip_address, olt.username, olt.password)
ssh = _get_cached_ssh(olt.ip_address, olt.username, olt.password, olt_id)
try:
ssh.connect()
output = ssh.execute_command(olt.slot_command)
onu_info_dict, duplicate_dict = ssh.parse_onu_info(output)
@@ -241,9 +260,8 @@ class CheckService:
if not olt:
raise Exception(f"OLT 设备不存在: {olt_id}")
ssh = SSHService(olt.ip_address, olt.username, olt.password)
ssh = _get_cached_ssh(olt.ip_address, olt.username, olt.password, olt_id)
try:
ssh.connect()
output = ssh.execute_command(olt.slot_command)
onu_info_dict, duplicate_dict = ssh.parse_onu_info(output)