717fa31456
1. 新增 feishu_service.py: 飞书自定义机器人 webhook 推送 - 支持卡片消息(interactive),按告警级别着色 - 支持签名校验(HMAC-SHA256) - 支持最低级别过滤 + 告警类型白名单 2. alert_service.create_alert 创建新告警时自动推飞书 - 仅新告警推送,去重告警不刷屏 - 推送失败不影响告警创建 3. alerts.py 新增两个接口: - GET /alerts/notify/feishu/status 查看配置状态 - POST /alerts/notify/feishu/test 发送测试告警 4. config.py + .env.example 增加 FEISHU_* 配置项 (WEBHOOK_URL / SECRET / ENABLED / MIN_SEVERITY / ALERT_TYPES)
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from pydantic_settings import BaseSettings
|
|
from typing import Optional
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# 应用配置
|
|
APP_NAME: str = "IPAM Management System"
|
|
APP_VERSION: str = "0.1.0"
|
|
DEBUG: bool = True
|
|
|
|
# 数据库配置
|
|
DATABASE_URL: str = "mysql+pymysql://ipam:***@localhost:3308/ipam"
|
|
|
|
# Redis配置
|
|
REDIS_URL: str = "redis://localhost:6379/0"
|
|
|
|
# Celery配置
|
|
CELERY_BROKER_URL: str = "redis://localhost:6379/1"
|
|
CELERY_RESULT_BACKEND: str = "redis://localhost:6379/2"
|
|
|
|
# JWT配置
|
|
SECRET_KEY: str = "your-super-secret-key-here-change-in-production"
|
|
ALGORITHM: str = "HS256"
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7
|
|
|
|
# 扫描配置
|
|
PING_TIMEOUT: int = 2
|
|
PING_RETRIES: int = 2
|
|
SCAN_CONCURRENCY: int = 50
|
|
|
|
# 飞书机器人告警通知配置
|
|
FEISHU_ENABLED: bool = False # 总开关
|
|
FEISHU_WEBHOOK_URL: str = "" # 飞书自定义机器人 webhook 地址
|
|
FEISHU_SECRET: str = "" # 可选:机器人签名校验密钥(开启签名校验时必填)
|
|
FEISHU_MIN_SEVERITY: str = "warning" # 最低告警级别:info/warning/error/critical,仅推送 >= 该级别
|
|
FEISHU_ALERT_TYPES: str = "" # 可选:逗号分隔的告警类型白名单,空=全部推送
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings()
|