fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -29,6 +29,7 @@ import httpx
|
||||
# Database path
|
||||
DB_PATH = os.path.join(os.path.dirname(__file__), "insightflow.db")
|
||||
|
||||
|
||||
class AlertSeverity(StrEnum):
|
||||
"""告警严重级别 P0-P3"""
|
||||
|
||||
@@ -37,6 +38,7 @@ class AlertSeverity(StrEnum):
|
||||
P2 = "p2" # 一般 - 部分功能受影响,需要4小时内处理
|
||||
P3 = "p3" # 轻微 - 非核心功能问题,24小时内处理
|
||||
|
||||
|
||||
class AlertStatus(StrEnum):
|
||||
"""告警状态"""
|
||||
|
||||
@@ -45,6 +47,7 @@ class AlertStatus(StrEnum):
|
||||
ACKNOWLEDGED = "acknowledged" # 已确认
|
||||
SUPPRESSED = "suppressed" # 已抑制
|
||||
|
||||
|
||||
class AlertChannelType(StrEnum):
|
||||
"""告警渠道类型"""
|
||||
|
||||
@@ -57,6 +60,7 @@ class AlertChannelType(StrEnum):
|
||||
SMS = "sms"
|
||||
WEBHOOK = "webhook"
|
||||
|
||||
|
||||
class AlertRuleType(StrEnum):
|
||||
"""告警规则类型"""
|
||||
|
||||
@@ -65,6 +69,7 @@ class AlertRuleType(StrEnum):
|
||||
PREDICTIVE = "predictive" # 预测性告警
|
||||
COMPOSITE = "composite" # 复合告警
|
||||
|
||||
|
||||
class ResourceType(StrEnum):
|
||||
"""资源类型"""
|
||||
|
||||
@@ -77,6 +82,7 @@ class ResourceType(StrEnum):
|
||||
CACHE = "cache"
|
||||
QUEUE = "queue"
|
||||
|
||||
|
||||
class ScalingAction(StrEnum):
|
||||
"""扩缩容动作"""
|
||||
|
||||
@@ -84,6 +90,7 @@ class ScalingAction(StrEnum):
|
||||
SCALE_DOWN = "scale_down" # 缩容
|
||||
MAINTAIN = "maintain" # 保持
|
||||
|
||||
|
||||
class HealthStatus(StrEnum):
|
||||
"""健康状态"""
|
||||
|
||||
@@ -92,6 +99,7 @@ class HealthStatus(StrEnum):
|
||||
UNHEALTHY = "unhealthy"
|
||||
UNKNOWN = "unknown"
|
||||
|
||||
|
||||
class BackupStatus(StrEnum):
|
||||
"""备份状态"""
|
||||
|
||||
@@ -101,6 +109,7 @@ class BackupStatus(StrEnum):
|
||||
FAILED = "failed"
|
||||
VERIFIED = "verified"
|
||||
|
||||
|
||||
@dataclass
|
||||
class AlertRule:
|
||||
"""告警规则"""
|
||||
@@ -124,6 +133,7 @@ class AlertRule:
|
||||
updated_at: str
|
||||
created_by: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class AlertChannel:
|
||||
"""告警渠道配置"""
|
||||
@@ -141,6 +151,7 @@ class AlertChannel:
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class Alert:
|
||||
"""告警实例"""
|
||||
@@ -164,6 +175,7 @@ class Alert:
|
||||
notification_sent: dict[str, bool] # 渠道发送状态
|
||||
suppression_count: int # 抑制计数
|
||||
|
||||
|
||||
@dataclass
|
||||
class AlertSuppressionRule:
|
||||
"""告警抑制规则"""
|
||||
@@ -177,6 +189,7 @@ class AlertSuppressionRule:
|
||||
created_at: str
|
||||
expires_at: str | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class AlertGroup:
|
||||
"""告警聚合组"""
|
||||
@@ -188,6 +201,7 @@ class AlertGroup:
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class ResourceMetric:
|
||||
"""资源指标"""
|
||||
@@ -202,6 +216,7 @@ class ResourceMetric:
|
||||
timestamp: str
|
||||
metadata: dict
|
||||
|
||||
|
||||
@dataclass
|
||||
class CapacityPlan:
|
||||
"""容量规划"""
|
||||
@@ -217,6 +232,7 @@ class CapacityPlan:
|
||||
estimated_cost: float
|
||||
created_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class AutoScalingPolicy:
|
||||
"""自动扩缩容策略"""
|
||||
@@ -237,6 +253,7 @@ class AutoScalingPolicy:
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class ScalingEvent:
|
||||
"""扩缩容事件"""
|
||||
@@ -254,6 +271,7 @@ class ScalingEvent:
|
||||
completed_at: str | None
|
||||
error_message: str | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class HealthCheck:
|
||||
"""健康检查配置"""
|
||||
@@ -274,6 +292,7 @@ class HealthCheck:
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class HealthCheckResult:
|
||||
"""健康检查结果"""
|
||||
@@ -287,6 +306,7 @@ class HealthCheckResult:
|
||||
details: dict
|
||||
checked_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class FailoverConfig:
|
||||
"""故障转移配置"""
|
||||
@@ -304,6 +324,7 @@ class FailoverConfig:
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class FailoverEvent:
|
||||
"""故障转移事件"""
|
||||
@@ -319,6 +340,7 @@ class FailoverEvent:
|
||||
completed_at: str | None
|
||||
rolled_back_at: str | None
|
||||
|
||||
|
||||
@dataclass
|
||||
class BackupJob:
|
||||
"""备份任务"""
|
||||
@@ -338,6 +360,7 @@ class BackupJob:
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class BackupRecord:
|
||||
"""备份记录"""
|
||||
@@ -354,6 +377,7 @@ class BackupRecord:
|
||||
error_message: str | None
|
||||
storage_path: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class CostReport:
|
||||
"""成本报告"""
|
||||
@@ -368,6 +392,7 @@ class CostReport:
|
||||
anomalies: list[dict] # 异常检测
|
||||
created_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class ResourceUtilization:
|
||||
"""资源利用率"""
|
||||
@@ -383,6 +408,7 @@ class ResourceUtilization:
|
||||
report_date: str
|
||||
recommendations: list[str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class IdleResource:
|
||||
"""闲置资源"""
|
||||
@@ -399,6 +425,7 @@ class IdleResource:
|
||||
recommendation: str
|
||||
detected_at: str
|
||||
|
||||
|
||||
@dataclass
|
||||
class CostOptimizationSuggestion:
|
||||
"""成本优化建议"""
|
||||
@@ -418,6 +445,7 @@ class CostOptimizationSuggestion:
|
||||
created_at: str
|
||||
applied_at: str | None
|
||||
|
||||
|
||||
class OpsManager:
|
||||
"""运维与监控管理主类"""
|
||||
|
||||
@@ -3065,9 +3093,11 @@ class OpsManager:
|
||||
applied_at=row["applied_at"],
|
||||
)
|
||||
|
||||
|
||||
# Singleton instance
|
||||
_ops_manager = None
|
||||
|
||||
|
||||
def get_ops_manager() -> OpsManager:
|
||||
global _ops_manager
|
||||
if _ops_manager is None:
|
||||
|
||||
Reference in New Issue
Block a user