| 1 | import type { |
| 2 | DashboardCategory, |
| 3 | DashboardCategoryWithTemplates, |
| 4 | EnableDashboardPayload, |
| 5 | EnabledDashboard, |
| 6 | PanelDataResponse |
| 7 | } from "@/types/dashboards.d" |
| 8 | import type { EventSearchResult, FieldMapping } from "@/types/events.d" |
| 9 | import type { DisplayColumn, EventSource } from "@/types/eventSources.d" |
| 10 | import type { FlaskBaseResponse } from "@/types/flask.d" |
| 11 | import { HttpClient } from "../httpClient" |
| 12 | |
| 13 | export interface EventSourceCreatePayload { |
| 14 | customer_code: string |
| 15 | name: string |
| 16 | index_pattern: string |
| 17 | event_type: string |
| 18 | time_field: string |
| 19 | enabled: boolean |
| 20 | displayed_columns?: DisplayColumn[] | null |
| 21 | } |
| 22 | |
| 23 | export interface EventSourceUpdatePayload { |
| 24 | name?: string |
| 25 | index_pattern?: string |
| 26 | event_type?: string |
| 27 | time_field?: string |
| 28 | enabled?: boolean |
| 29 | displayed_columns?: DisplayColumn[] | null |
| 30 | } |
| 31 | |
| 32 | export default { |
| 33 | getEventSources(customerCode: string) { |
| 34 | return HttpClient.get<FlaskBaseResponse & { event_sources: EventSource[] }>( |
| 35 | `/siem/event_sources/${customerCode}` |
| 36 | ) |
| 37 | }, |
| 38 | createEventSource(payload: EventSourceCreatePayload) { |
| 39 | return HttpClient.post<FlaskBaseResponse & { event_source: EventSource }>(`/siem/event_sources`, payload) |
| 40 | }, |
| 41 | updateEventSource(eventSourceId: number, payload: EventSourceUpdatePayload) { |
| 42 | return HttpClient.put<FlaskBaseResponse & { event_source: EventSource }>( |
| 43 | `/siem/event_sources/${eventSourceId}`, |
| 44 | payload |
| 45 | ) |
| 46 | }, |
| 47 | deleteEventSource(eventSourceId: number) { |
| 48 | return HttpClient.delete<FlaskBaseResponse>(`/siem/event_sources/${eventSourceId}`) |
| 49 | }, |
| 50 | queryEvents( |
| 51 | customerCode: string, |
| 52 | sourceName: string, |
| 53 | params: { |
| 54 | timerange?: string |
| 55 | page_size?: number |
| 56 | scroll_id?: string |
| 57 | query?: string |
| 58 | time_from?: string |
| 59 | time_to?: string |
| 60 | } |
| 61 | ) { |
| 62 | return HttpClient.get< |
| 63 | FlaskBaseResponse & { |
| 64 | events: EventSearchResult[] |
| 65 | total: number |
| 66 | scroll_id: string | null |
| 67 | page_size: number |
| 68 | } |
| 69 | >(`/siem/events/${customerCode}/${sourceName}`, { params }) |
| 70 | }, |
| 71 | getFieldMappings(customerCode: string, sourceName: string) { |
| 72 | return HttpClient.get<FlaskBaseResponse & { fields: FieldMapping[]; total: number; index_pattern: string }>( |
| 73 | `/siem/events/${customerCode}/${sourceName}/fields` |
| 74 | ) |
| 75 | }, |
| 76 | |
| 77 | // ── Dashboards ────────────────────────────────────────────── |
| 78 | getDashboardCategories() { |
| 79 | return HttpClient.get<FlaskBaseResponse & { categories: DashboardCategory[] }>(`/siem/dashboards/templates`) |
| 80 | }, |
| 81 | getDashboardCategory(categoryId: string) { |
| 82 | return HttpClient.get<FlaskBaseResponse & { category: DashboardCategoryWithTemplates }>( |
| 83 | `/siem/dashboards/templates/${categoryId}` |
| 84 | ) |
| 85 | }, |
| 86 | getEnabledDashboards(customerCode: string) { |
| 87 | return HttpClient.get<FlaskBaseResponse & { enabled_dashboards: EnabledDashboard[] }>( |
| 88 | `/siem/dashboards/enabled/${customerCode}` |
| 89 | ) |
| 90 | }, |
| 91 | enableDashboard(payload: EnableDashboardPayload) { |
| 92 | return HttpClient.post<FlaskBaseResponse & { enabled_dashboard: EnabledDashboard }>( |
| 93 | `/siem/dashboards/enable`, |
| 94 | payload |
| 95 | ) |
| 96 | }, |
| 97 | disableDashboard(dashboardId: number) { |
| 98 | return HttpClient.delete<FlaskBaseResponse>(`/siem/dashboards/disable/${dashboardId}`) |
| 99 | }, |
| 100 | getPanelData(dashboardId: number, timerange: string, signal?: AbortSignal) { |
| 101 | return HttpClient.post<PanelDataResponse>( |
| 102 | `/siem/dashboards/panel-data`, |
| 103 | { |
| 104 | dashboard_id: dashboardId, |
| 105 | timerange |
| 106 | }, |
| 107 | signal ? { signal } : {} |
| 108 | ) |
| 109 | } |
| 110 | } |