"""应用配置,通过环境变量注入,不支持 .env 文件""" from pydantic_settings import BaseSettings from typing import Optional class Settings(BaseSettings): # ---------- 数据库 ---------- DATABASE_URL: str = "sqlite+aiosqlite:///./pingwatch.db" # PostgreSQL: "postgresql+asyncpg://user:pass@localhost/pingwatch" # ---------- 企业微信 ---------- WECOM_CORP_ID: str = "" WECOM_AGENT_ID: int = 0 WECOM_APP_SECRET: str = "" # ---------- Casdoor ---------- CASDOOR_ENDPOINT: str = "https://casdoor.dhdx.fun" CASDOOR_CLIENT_ID: str = "" CASDOOR_CLIENT_SECRET: str = "" CASDOOR_CERTIFICATE: str = "" # 可选,用于验证 id_token 签名 CASDOOR_ORGANIZATION: str = "dahua" CASDOOR_APPLICATION: str = "PingWatch" CASDOOR_REDIRECT_URI: str = "http://10.10.10.7:5173/login" # 前端回调地址 # ---------- Ping 引擎 ---------- PING_INTERVAL_SECONDS: int = 30 PING_TIMEOUT_SECONDS: float = 5.0 DEFAULT_ALERT_THRESHOLD: int = 5 PING_CONCURRENCY: int = 50 FPING_PATH: str = "/usr/bin/fping" # ---------- 上游心跳 ---------- UPSTREAM_PING_TARGET: str = "114.114.114.114" UPSTREAM_PING_THRESHOLD: int = 2 OFFLINE_SUPPRESS_RATIO: float = 0.9 # ---------- 数据保留 ---------- PING_RECORD_RETENTION_DAYS: int = 90 ALERT_RETENTION_DAYS: int = 365 # ---------- JWT ---------- SECRET_KEY: str = "change-me-to-a-long-random-string" ACCESS_TOKEN_EXPIRE_MINUTES: int = 480 # ---------- LogHive ---------- LOGHIVE_ENDPOINT: str = "http://10.10.10.14:8000" LOGHIVE_PROJECT: str = "PingWatch" LOGHIVE_API_KEY: str = "" # ---------- CORS ---------- CORS_ORIGINS: str = "http://localhost:5173,http://10.10.10.7:5173,http://10.10.10.7" model_config = {"env_file": ".env", "env_file_encoding": "utf-8"} settings = Settings()