| 1 | import type { |
| 2 | Agent, |
| 3 | AgentArtifactData, |
| 4 | AgentSca, |
| 5 | AgentVulnerabilities, |
| 6 | BulkDeleteAgentRequest, |
| 7 | BulkDeleteAgentsResponse, |
| 8 | BulkDeleteFilterRequest, |
| 9 | OutdatedVelociraptorAgents, |
| 10 | OutdatedWazuhAgents, |
| 11 | ScaPolicyResult |
| 12 | } from "@/types/agents.d" |
| 13 | import type { FlaskBaseResponse } from "@/types/flask.d" |
| 14 | import { HttpClient } from "../httpClient" |
| 15 | |
| 16 | export interface AgentPayload { |
| 17 | velociraptor_id: string |
| 18 | } |
| 19 | |
| 20 | export type VulnerabilitySeverityType = "Low" | "Medium" | "High" | "Critical" | "All" |
| 21 | |
| 22 | // TODO-FE: refactor |
| 23 | export default { |
| 24 | getAgents(agentId?: string) { |
| 25 | return HttpClient.get<FlaskBaseResponse & { agents: Agent[] }>(`/agents${agentId ? `/${agentId}` : ""}`) |
| 26 | }, |
| 27 | markCritical(agentId: string) { |
| 28 | return HttpClient.post<FlaskBaseResponse>(`/agents/${agentId}/critical`) |
| 29 | }, |
| 30 | markNonCritical(agentId: string) { |
| 31 | return HttpClient.post<FlaskBaseResponse>(`/agents/${agentId}/noncritical`) |
| 32 | }, |
| 33 | deleteAgent(agentId: string) { |
| 34 | return HttpClient.delete<FlaskBaseResponse>(`/agents/${agentId}/delete`) |
| 35 | }, |
| 36 | /** |
| 37 | * Bulk delete agents by their IDs |
| 38 | * @param agentIds - Array of agent IDs to delete |
| 39 | */ |
| 40 | bulkDeleteAgents(agentIds: string[]) { |
| 41 | const payload: BulkDeleteAgentRequest = { agent_ids: agentIds } |
| 42 | return HttpClient.post<BulkDeleteAgentsResponse>(`/agents/bulk/delete`, payload) |
| 43 | }, |
| 44 | /** |
| 45 | * Bulk delete agents based on filter conditions |
| 46 | * At least one filter must be specified |
| 47 | * @param filters - Filter conditions (customer_code, status, disconnected_days) |
| 48 | */ |
| 49 | bulkDeleteAgentsByFilter(filters: BulkDeleteFilterRequest) { |
| 50 | return HttpClient.post<BulkDeleteAgentsResponse>(`/agents/bulk/delete/filter`, filters) |
| 51 | }, |
| 52 | syncAgents() { |
| 53 | return HttpClient.post<FlaskBaseResponse>(`/agents/sync`) |
| 54 | }, |
| 55 | syncVulnerabilities(customerCode: string) { |
| 56 | return HttpClient.post<FlaskBaseResponse>(`/agents/sync/vulnerabilities/${customerCode}`) |
| 57 | }, |
| 58 | agentVulnerabilities(agentId: string, severity: VulnerabilitySeverityType, signal?: AbortSignal) { |
| 59 | return HttpClient.get<FlaskBaseResponse & { vulnerabilities: AgentVulnerabilities[] }>( |
| 60 | `/agents/${agentId}/vulnerabilities/${severity}`, |
| 61 | signal ? { signal } : {} |
| 62 | ) |
| 63 | }, |
| 64 | agentVulnerabilitiesDownload(agentId: string, severity: VulnerabilitySeverityType) { |
| 65 | return HttpClient.get<string>(`/agents/${agentId}/csv/vulnerabilities/${severity}`) |
| 66 | }, |
| 67 | getSocCases(agentId: string | number, signal?: AbortSignal) { |
| 68 | return HttpClient.get<FlaskBaseResponse & { case_ids: number[] }>( |
| 69 | `/agents/${agentId}/soc_cases`, |
| 70 | signal ? { signal } : {} |
| 71 | ) |
| 72 | }, |
| 73 | getSCA(agentId: string | number, signal?: AbortSignal) { |
| 74 | return HttpClient.get<FlaskBaseResponse & { sca: AgentSca[] }>( |
| 75 | `/agents/${agentId}/sca`, |
| 76 | signal ? { signal } : {} |
| 77 | ) |
| 78 | }, |
| 79 | getSCAResults(agentId: string | number, policyId: string, signal?: AbortSignal) { |
| 80 | return HttpClient.get<FlaskBaseResponse & { sca_policy_results: ScaPolicyResult[] }>( |
| 81 | `/agents/${agentId}/sca/${policyId}`, |
| 82 | signal ? { signal } : {} |
| 83 | ) |
| 84 | }, |
| 85 | scaResultsDownload(agentId: string | number, policyId: string) { |
| 86 | return HttpClient.get<Blob>(`/agents/${agentId}/csv/sca/${policyId}`, { |
| 87 | responseType: "blob" |
| 88 | }) |
| 89 | }, |
| 90 | updateAgent(agentId: string, payload: AgentPayload) { |
| 91 | return HttpClient.put<FlaskBaseResponse>( |
| 92 | `/agents/${agentId}/update`, |
| 93 | {}, |
| 94 | { |
| 95 | params: { |
| 96 | velociraptor_id: payload.velociraptor_id |
| 97 | } |
| 98 | } |
| 99 | ) |
| 100 | }, |
| 101 | upgradeWazuhAgent(agentId: string) { |
| 102 | return HttpClient.post<FlaskBaseResponse>(`/agents/${agentId}/wazuh/upgrade`) |
| 103 | }, |
| 104 | // Agent Data Store / Artifact Collection Methods |
| 105 | /** |
| 106 | * List all artifact files for a specific agent |
| 107 | * @param agentId - The agent ID |
| 108 | * @param flowId - Optional flow ID to filter artifacts |
| 109 | * @param signal - Optional AbortSignal for request cancellation |
| 110 | */ |
| 111 | listAgentArtifacts(agentId: string, flowId?: string, signal?: AbortSignal) { |
| 112 | const params = flowId ? { flow_id: flowId } : {} |
| 113 | return HttpClient.get< |
| 114 | FlaskBaseResponse & { |
| 115 | data: AgentArtifactData[] |
| 116 | total: number |
| 117 | } |
| 118 | >(`/agent_data_store/agent/${agentId}/artifacts`, signal ? { signal, params } : { params }) |
| 119 | }, |
| 120 | |
| 121 | /** |
| 122 | * Get details of a specific artifact file |
| 123 | * @param agentId - The agent ID |
| 124 | * @param artifactId - The artifact ID |
| 125 | * @param signal - Optional AbortSignal for request cancellation |
| 126 | */ |
| 127 | getAgentArtifactDetails(agentId: string, artifactId: number, signal?: AbortSignal) { |
| 128 | return HttpClient.get<FlaskBaseResponse & { data: AgentArtifactData | null }>( |
| 129 | `/agent_data_store/agent/${agentId}/artifacts/${artifactId}`, |
| 130 | signal ? { signal } : {} |
| 131 | ) |
| 132 | }, |
| 133 | |
| 134 | /** |
| 135 | * Download a specific artifact file |
| 136 | * @param agentId - The agent ID |
| 137 | * @param artifactId - The artifact ID |
| 138 | * @returns Promise with Blob response |
| 139 | */ |
| 140 | downloadAgentArtifact(agentId: string, artifactId: number) { |
| 141 | return HttpClient.get<Blob>(`/agent_data_store/agent/${agentId}/artifacts/${artifactId}/download`, { |
| 142 | responseType: "blob" |
| 143 | }) |
| 144 | }, |
| 145 | |
| 146 | /** |
| 147 | * Delete a specific artifact file |
| 148 | * @param agentId - The agent ID |
| 149 | * @param artifactId - The artifact ID |
| 150 | */ |
| 151 | deleteAgentArtifact(agentId: string, artifactId: number) { |
| 152 | return HttpClient.delete<FlaskBaseResponse>(`/agent_data_store/agent/${agentId}/artifacts/${artifactId}`) |
| 153 | }, |
| 154 | |
| 155 | // IGNORE AT THE MOMENT ! |
| 156 | /** @deprecated */ |
| 157 | agentsWazuhOutdated() { |
| 158 | return HttpClient.get<FlaskBaseResponse & { outdated_wazuh_agents: OutdatedWazuhAgents }>( |
| 159 | `/agents/wazuh/outdated` |
| 160 | ) // Include the outdated Wazuh agents |
| 161 | }, |
| 162 | // IGNORE AT THE MOMENT ! |
| 163 | /** @deprecated */ |
| 164 | agentsVelociraptorOutdated() { |
| 165 | return HttpClient.get<FlaskBaseResponse & { outdated_velociraptor_agents: OutdatedVelociraptorAgents }>( |
| 166 | `/agents/velociraptor/outdated` |
| 167 | ) // Include the outdated Velociraptor agents |
| 168 | } |
| 169 | } |