main
py 123 lines 2.96 KB
Raw
1 from datetime import datetime
2 from typing import Any
3 from typing import Dict
4 from typing import List
5 from typing import Optional
6
7 from pydantic import BaseModel
8 from pydantic import ConfigDict
9 from pydantic import Field
10
11 # ── Template browsing (read from disk) ───────────────────────────
12
13
14 class DashboardPanel(BaseModel):
15 id: str
16 title: str
17 type: str
18 w: int
19 h: int
20 lucene: str
21 field: Optional[str] = None
22 size: Optional[int] = None
23
24
25 class DashboardTemplate(BaseModel):
26 id: str
27 title: str
28 description: str
29 panels: List[DashboardPanel]
30
31
32 class DashboardCategory(BaseModel):
33 id: str
34 title: str
35 description: str
36 vendor: str
37 product: str
38 event_type: str
39 tags: List[str]
40 color: str
41 icon: str
42
43
44 class DashboardCategoryWithTemplates(DashboardCategory):
45 templates: List[DashboardTemplate]
46
47
48 class DashboardCategoriesListResponse(BaseModel):
49 categories: List[DashboardCategory]
50 success: bool
51 message: str
52
53
54 class DashboardCategoryDetailResponse(BaseModel):
55 category: DashboardCategoryWithTemplates
56 success: bool
57 message: str
58
59
60 # ── Enabled dashboards (DB-backed, per customer) ────────────────
61
62
63 class EnableDashboardRequest(BaseModel):
64 customer_code: str = Field(..., max_length=50)
65 event_source_id: int
66 library_card: str = Field(..., max_length=255, description="Category id, e.g. 'wazuh_edr'")
67 template_id: str = Field(..., max_length=255, description="Template id, e.g. 'EDR_OVERVIEW'")
68 display_name: str = Field(..., max_length=255)
69
70
71 class EnabledDashboardResponse(BaseModel):
72 id: int
73 customer_code: str
74 event_source_id: int
75 library_card: str
76 template_id: str
77 display_name: str
78 created_at: datetime
79 model_config = ConfigDict(from_attributes=True)
80
81
82 class EnabledDashboardsListResponse(BaseModel):
83 enabled_dashboards: List[EnabledDashboardResponse]
84 success: bool
85 message: str
86
87
88 class EnabledDashboardOperationResponse(BaseModel):
89 enabled_dashboard: Optional[EnabledDashboardResponse] = None
90 success: bool
91 message: str
92
93
94 class DisableDashboardResponse(BaseModel):
95 success: bool
96 message: str
97
98
99 # ── Panel data (for rendering dashboards) ────────────────────────
100
101
102 class PanelDataRequest(BaseModel):
103 dashboard_id: int
104 timerange: str = Field("24h", description="Time range (e.g. '1h', '6h', '24h', '7d', '30d')")
105
106
107 class PanelResult(BaseModel):
108 type: str
109 value: Optional[int] = None # stat panels
110 labels: Optional[List[str]] = None # chart panels
111 data: Optional[List[Any]] = None # chart panels
112 error: Optional[str] = None
113
114
115 class PanelDataResponse(BaseModel):
116 panels: Dict[str, PanelResult]
117 template: DashboardTemplate
118 dashboard_id: int
119 customer_code: str
120 source_name: str
121 accent_color: str = "#38bdf8"
122 success: bool
123 message: str