| 1 | from typing import Optional |
| 2 | |
| 3 | from fastapi import HTTPException |
| 4 | from pydantic import BaseModel |
| 5 | from pydantic import Field |
| 6 | from pydantic import field_validator |
| 7 | |
| 8 | |
| 9 | class InvokeCarbonBlackRequest(BaseModel): |
| 10 | customer_code: str = Field( |
| 11 | ..., |
| 12 | description="The customer code.", |
| 13 | examples=["00002"], |
| 14 | ) |
| 15 | integration_name: str = Field( |
| 16 | "CarbonBlack", |
| 17 | description="The integration name.", |
| 18 | examples=["CarbonBlack"], |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | class CarbonBlackAuthKeys(BaseModel): |
| 23 | carbonblack_api_url: str = Field(..., examples=["https://127.0.0.1"]) |
| 24 | carbonblack_api_key: str = Field(..., examples=["1234567890"]) |
| 25 | carbonblack_api_id: str = Field(..., examples=["1234567890"]) |
| 26 | carbonblack_org_key: str = Field(..., examples=["1234567890"]) |
| 27 | time_range: Optional[str] = Field( |
| 28 | "-15m", |
| 29 | examples=["-15m"], |
| 30 | description="The time range to collect events.", |
| 31 | ) |
| 32 | |
| 33 | |
| 34 | class InvokeCarbonBlackResponse(BaseModel): |
| 35 | success: bool = Field( |
| 36 | ..., |
| 37 | description="The success status.", |
| 38 | examples=[True], |
| 39 | ) |
| 40 | message: str = Field( |
| 41 | ..., |
| 42 | description="The message.", |
| 43 | examples=["CarbonBlack Events collected successfully."], |
| 44 | ) |
| 45 | |
| 46 | |
| 47 | class CollectCarbonBlack(BaseModel): |
| 48 | integration: str = Field(..., examples=["carbonblack"]) |
| 49 | customer_code: str = Field(..., examples=["socfortress"]) |
| 50 | graylog_host: str = Field(..., examples=["127.0.0.1"]) |
| 51 | graylog_port: str = Field(..., examples=[12201]) |
| 52 | carbonblack_api_url: str = Field(..., examples=["https://127.0.0.1"]) |
| 53 | carbonblack_api_key: str = Field(..., examples=["1234567890"]) |
| 54 | carbonblack_api_id: str = Field(..., examples=["1234567890"]) |
| 55 | carbonblack_org_key: str = Field(..., examples=["1234567890"]) |
| 56 | time_range: Optional[str] = Field( |
| 57 | "-15m", |
| 58 | examples=["-15m"], |
| 59 | ) |
| 60 | |
| 61 | @field_validator("integration") |
| 62 | @classmethod |
| 63 | def check_integration(cls, v): |
| 64 | if v != "carbonblack": |
| 65 | raise HTTPException( |
| 66 | status_code=400, |
| 67 | detail="Invalid integration. Only 'carbonblack' is supported.", |
| 68 | ) |
| 69 | return v |