main
py 119 lines 3.4 KB
Raw
1 from datetime import datetime
2 from enum import Enum
3 from typing import Optional
4
5 from pydantic import BaseModel
6 from pydantic import ConfigDict
7 from pydantic import Field
8
9
10 class SeverityFilter(str, Enum):
11 """Severity levels for filtering"""
12
13 OK = "ok"
14 WARNING = "warning"
15 ERROR = "error"
16 CRITICAL = "critical"
17
18
19 class AlertStatus(str, Enum):
20 """Alert status"""
21
22 ACTIVE = "active"
23 CLEARED = "cleared"
24 ALL = "all"
25
26
27 class GetInfluxDBAlertQueryParams(BaseModel):
28 """
29 Query parameters for getting InfluxDB alerts with filtering
30 """
31
32 days: int = Field(default=7, ge=1, le=90, description="Number of days to look back")
33 severity: Optional[list[SeverityFilter]] = Field(default=None, description="Filter by severity levels (can specify multiple)")
34 check_name: Optional[str] = Field(default=None, description="Filter by specific check name")
35 sensor_type: Optional[str] = Field(default=None, description="Filter by sensor type")
36 status: AlertStatus = Field(default=AlertStatus.ALL, description="Filter by alert status (active/cleared/all)")
37 latest_only: bool = Field(default=False, description="Return only the latest alert per check")
38 exclude_ok: bool = Field(default=False, description="Exclude alerts with 'ok' status")
39 limit: Optional[int] = Field(default=500, ge=1, le=1000, description="Limit the number of returned alerts")
40
41
42 class InfluxDBAlert(BaseModel):
43 """
44 Single InfluxDB alert
45 """
46
47 time: datetime
48 check_name: str
49 sensor_type: str
50 severity: str
51 message: str
52 status: Optional[str] = None # active or cleared
53 check_id: Optional[str] = None # For internal filtering
54 model_config = ConfigDict(from_attributes=True)
55
56
57 class InfluxDBAlertResponse(BaseModel):
58 """
59 Response for InfluxDB alerts query
60 """
61
62 success: bool
63 message: str
64 alerts: list[InfluxDBAlert]
65 total_count: int
66 filtered_count: int
67 active_alerts_count: int = 0
68 cleared_alerts_count: int = 0
69 model_config = ConfigDict(
70 from_attributes=True,
71 json_schema_extra={
72 "example": {
73 "success": True,
74 "message": "Successfully retrieved alerts",
75 "alerts": [
76 {
77 "time": "2025-12-01T10:30:00Z",
78 "check_name": "CPU CHECK",
79 "sensor_type": "CPU",
80 "severity": "warning",
81 "message": "CPU usage high",
82 "status": "active",
83 },
84 ],
85 "total_count": 150,
86 "filtered_count": 25,
87 "active_alerts_count": 5,
88 "cleared_alerts_count": 20,
89 },
90 },
91 )
92
93
94 class InfluxDBAlertsResponse(BaseModel):
95 alerts: list[InfluxDBAlert]
96 success: bool
97 message: str
98
99
100 class InfluxDBCheckNamesResponse(BaseModel):
101 """
102 Response for available check names query
103 """
104
105 success: bool
106 message: str
107 check_names: list[str]
108 total_count: int
109 model_config = ConfigDict(
110 from_attributes=True,
111 json_schema_extra={
112 "example": {
113 "success": True,
114 "message": "Successfully retrieved check names",
115 "check_names": ["CPU CHECK", "Host Offline", "Memory Usage", "Disk Space"],
116 "total_count": 4,
117 },
118 },
119 )