| 1 | from typing import List |
| 2 | from typing import Optional |
| 3 | |
| 4 | from pydantic import BaseModel |
| 5 | from pydantic import ConfigDict |
| 6 | from pydantic import Field |
| 7 | |
| 8 | |
| 9 | class WazuhOSInfo(BaseModel): |
| 10 | arch: Optional[str] = Field( |
| 11 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 12 | description="The architecture of the Wazuh Agent.", |
| 13 | ) |
| 14 | codename: Optional[str] = Field( |
| 15 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 16 | description="The codename of the Wazuh Agent.", |
| 17 | ) |
| 18 | major: Optional[str] = Field( |
| 19 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 20 | description="The major version of the Wazuh Agent.", |
| 21 | ) |
| 22 | minor: Optional[str] = Field( |
| 23 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 24 | description="The minor version of the Wazuh Agent.", |
| 25 | ) |
| 26 | name: Optional[str] = Field( |
| 27 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 28 | description="The name of the Wazuh Agent.", |
| 29 | ) |
| 30 | platform: Optional[str] = Field( |
| 31 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 32 | description="The platform of the Wazuh Agent.", |
| 33 | ) |
| 34 | uname: Optional[str] = Field( |
| 35 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 36 | description="The uname of the Wazuh Agent.", |
| 37 | ) |
| 38 | version: Optional[str] = Field( |
| 39 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 40 | description="The version of the Wazuh Agent.", |
| 41 | ) |
| 42 | |
| 43 | |
| 44 | class WazuhAgent(BaseModel): |
| 45 | os: Optional[WazuhOSInfo] = Field( |
| 46 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 47 | description="The OS info of the Wazuh Agent.", |
| 48 | ) |
| 49 | lastKeepAlive: Optional[str] = Field( |
| 50 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 51 | description="The last keep alive of the Wazuh Agent.", |
| 52 | ) |
| 53 | id: str |
| 54 | dateAdd: str |
| 55 | configSum: Optional[str] = Field( |
| 56 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 57 | description="The config sum of the Wazuh Agent.", |
| 58 | ) |
| 59 | manager: Optional[str] = Field( |
| 60 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 61 | description="The manager of the Wazuh Agent.", |
| 62 | ) |
| 63 | group: Optional[List[str]] = Field( |
| 64 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 65 | description="The group of the Wazuh Agent.", |
| 66 | ) |
| 67 | registerIP: str |
| 68 | ip: str |
| 69 | name: str |
| 70 | status: str |
| 71 | mergedSum: Optional[str] = Field( |
| 72 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 73 | description="The merged sum of the Wazuh Agent.", |
| 74 | ) |
| 75 | version: Optional[str] = Field( |
| 76 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 77 | description="The version of the Wazuh Agent.", |
| 78 | ) |
| 79 | node_name: str |
| 80 | group_config_status: str |
| 81 | |
| 82 | |
| 83 | class WazuhAffectedItems(BaseModel): |
| 84 | affected_items: List[WazuhAgent] |
| 85 | total_affected_items: int |
| 86 | total_failed_items: int |
| 87 | failed_items: List |
| 88 | |
| 89 | |
| 90 | class WazuhResponseData(BaseModel): |
| 91 | data: WazuhAffectedItems |
| 92 | |
| 93 | |
| 94 | class WazuhAgentResponse(BaseModel): |
| 95 | data: Optional[WazuhResponseData] = Field( |
| 96 | None, |
| 97 | description="The Wazuh API response data.", |
| 98 | ) |
| 99 | message: Optional[str] = Field( |
| 100 | "Not Available - Make sure the Wazuh Agent is connected to the Manager.", |
| 101 | description="The Wazuh API response message.", |
| 102 | ) |
| 103 | success: Optional[bool] = Field( |
| 104 | False, |
| 105 | description="The Wazuh API response success.", |
| 106 | ) |
| 107 | |
| 108 | |
| 109 | class WazuhSocketPayload(BaseModel): |
| 110 | integration: str = Field( |
| 111 | ..., |
| 112 | description="The integration name.", |
| 113 | examples="sublime", |
| 114 | ) |
| 115 | model_config = ConfigDict(extra="allow") |
| 116 | |
| 117 | def to_dict(self): |
| 118 | return self.model_dump(exclude_none=True) |
| 119 | |
| 120 | |
| 121 | ############################### ! Sublime ! ############################### |
| 122 | class WazuhSublimeSocketPayload(WazuhSocketPayload): |
| 123 | sender: str = Field( |
| 124 | ..., |
| 125 | description="The sender's email address.", |
| 126 | examples="info@socfortress.co", |
| 127 | ) |
| 128 | display_name: str = Field( |
| 129 | ..., |
| 130 | description="The sender's display name.", |
| 131 | examples="SOCFortress", |
| 132 | ) |
| 133 | subject: str = Field( |
| 134 | ..., |
| 135 | description="The subject of the email.", |
| 136 | examples="Test Email", |
| 137 | ) |
| 138 | canonical_id: str = Field( |
| 139 | ..., |
| 140 | description="The canonical ID of the email.", |
| 141 | examples="123456789", |
| 142 | ) |
| 143 | rule_names: str = Field( |
| 144 | ..., |
| 145 | description="The rule names that were triggered.", |
| 146 | examples="test rule, test rule 2", |
| 147 | ) |
| 148 | recipients: str = Field( |
| 149 | ..., |
| 150 | description="The recipients of the email.", |
| 151 | examples="info@socfortress.co", |
| 152 | ) |
| 153 | |
| 154 | def to_dict(self): |
| 155 | # If `display_name` is an empty string, set it to `None`. |
| 156 | if self.display_name == "": |
| 157 | self.display_name = None |
| 158 | return self.model_dump(exclude_none=True) |
| 159 | |
| 160 | |
| 161 | ######### ! SEND TO SHUFFLE PAYLOAD ! ######### |
| 162 | class ShufflePayload(BaseModel): |
| 163 | alert_id: str = Field( |
| 164 | ..., |
| 165 | description="The alert ID.", |
| 166 | examples="123456789", |
| 167 | ) |
| 168 | customer: str = Field( |
| 169 | ..., |
| 170 | description="The customer name.", |
| 171 | examples="SOCFortress", |
| 172 | ) |
| 173 | customer_code: str = Field( |
| 174 | ..., |
| 175 | description="The customer code.", |
| 176 | examples="socfortress", |
| 177 | ) |
| 178 | alert_source_link: str = Field( |
| 179 | ..., |
| 180 | description="The alert source link.", |
| 181 | examples="https://app.socfortress.co/alerts/123456789", |
| 182 | ) |
| 183 | rule_description: str = Field( |
| 184 | ..., |
| 185 | description="The rule description.", |
| 186 | examples="Test rule", |
| 187 | ) |
| 188 | hostname: str = Field( |
| 189 | ..., |
| 190 | description="The hostname of the affected asset.", |
| 191 | examples="test-hostname", |
| 192 | ) |
| 193 | model_config = ConfigDict(extra="allow") |
| 194 | |
| 195 | def to_dict(self): |
| 196 | return self.model_dump(exclude_none=True) |
| 197 | |
| 198 | |
| 199 | ######### ! SEND TO EVENT SHIPPER ! ######### |
| 200 | class EventShipperPayload(BaseModel): |
| 201 | integration: str = Field( |
| 202 | ..., |
| 203 | description="The integration name.", |
| 204 | examples="mimecast", |
| 205 | ) |
| 206 | customer_code: str = Field( |
| 207 | ..., |
| 208 | description="The customer code.", |
| 209 | examples="socfortress", |
| 210 | ) |
| 211 | model_config = ConfigDict(extra="allow") |
| 212 | |
| 213 | def to_dict(self): |
| 214 | return self.model_dump(exclude_none=True) |
| 215 | |
| 216 | |
| 217 | class EventShipperPayloadResponse(BaseModel): |
| 218 | message: str |
| 219 | success: bool |
| 220 | data: Optional[dict] = Field( |
| 221 | None, |
| 222 | description="The Event Shipper response data.", |
| 223 | ) |
| 224 | |
| 225 | |
| 226 | ######### ! SEND TO ALERT CREATION ! ######### |
| 227 | class QueryString(BaseModel): |
| 228 | query: str |
| 229 | |
| 230 | |
| 231 | class Query(BaseModel): |
| 232 | query_string: QueryString |
| 233 | |
| 234 | |
| 235 | class Filter(BaseModel): |
| 236 | query: Query |
| 237 | |
| 238 | |
| 239 | class KibanaDiscoverTimeDelta(BaseModel): |
| 240 | minutes: int |
| 241 | |
| 242 | |
| 243 | class Realert(BaseModel): |
| 244 | minutes: int |
| 245 | |
| 246 | |
| 247 | class PraecoAlertConfig(BaseModel): |
| 248 | alert: List[str] |
| 249 | filter: List[Filter] |
| 250 | generate_kibana_discover_url: bool |
| 251 | http_post_ignore_ssl_errors: bool |
| 252 | http_post_timeout: int |
| 253 | http_post_url: List[str] |
| 254 | import_config: str = Field(..., alias="import") # Using alias |
| 255 | index: str |
| 256 | is_enabled: bool |
| 257 | kibana_discover_from_timedelta: KibanaDiscoverTimeDelta |
| 258 | kibana_discover_to_timedelta: KibanaDiscoverTimeDelta |
| 259 | match_enhancements: List[str] |
| 260 | name: str |
| 261 | realert: Realert |
| 262 | timestamp_field: str |
| 263 | timestamp_type: str |
| 264 | type: str |
| 265 | use_strftime_index: bool |
| 266 | model_config = ConfigDict(populate_by_name=True) |
| 267 | |
| 268 | |
| 269 | class PraecoProvisionAlertResponse(BaseModel): |
| 270 | success: bool |
| 271 | message: str |