diff --git a/public/services/AlertsService.ts b/public/services/AlertsService.ts index 6370630a7..79da15640 100644 --- a/public/services/AlertsService.ts +++ b/public/services/AlertsService.ts @@ -23,14 +23,19 @@ export default class AlertsService { detectorParams: GetAlertsParams ): Promise> => { const { detectorType, detector_id } = detectorParams; - let query: GetAlertsParams | {} = {}; + let query: GetAlertsParams | {} = { + sortOrder: 'desc', + size: 10000, + }; if (detector_id) { query = { + ...query, detector_id, }; } else if (detectorType) { query = { + ...query, detectorType, }; } diff --git a/public/services/FindingsService.ts b/public/services/FindingsService.ts index 3cd8a4b34..24d502b6d 100644 --- a/public/services/FindingsService.ts +++ b/public/services/FindingsService.ts @@ -19,14 +19,19 @@ export default class FindingsService { detectorParams: GetFindingsParams ): Promise> => { const { detectorType, detectorId } = detectorParams; - let query: GetFindingsParams | {} = {}; + let query: GetFindingsParams | {} = { + sortOrder: 'desc', + size: 10000, + }; if (detectorId) { query = { + ...query, detectorId, }; } else if (detectorType) { query = { + ...query, detectorType, }; } diff --git a/server/clusters/addAlertsMethods.ts b/server/clusters/addAlertsMethods.ts index 24c0245a9..eb02f3ade 100644 --- a/server/clusters/addAlertsMethods.ts +++ b/server/clusters/addAlertsMethods.ts @@ -8,12 +8,20 @@ import { METHOD_NAMES, API, BASE_API_PATH } from '../utils/constants'; export function addAlertsMethods(securityAnalytics: any, createAction: any): void { securityAnalytics[METHOD_NAMES.GET_ALERTS] = createAction({ url: { - fmt: `${API.GET_ALERTS}?detector_id=<%=detector_id%>`, + fmt: `${API.GET_ALERTS}?detector_id=<%=detector_id%>&sortOrder=<%=sortOrder%>&size=<%=size%>`, req: { detector_id: { type: 'string', required: false, }, + sortOrder: { + type: 'string', + required: false, + }, + size: { + type: 'number', + required: false, + }, }, }, needBody: false, diff --git a/server/clusters/addFindingsMethods.ts b/server/clusters/addFindingsMethods.ts index 94c88cc26..6b8f3b7a8 100644 --- a/server/clusters/addFindingsMethods.ts +++ b/server/clusters/addFindingsMethods.ts @@ -8,12 +8,20 @@ import { METHOD_NAMES, API } from '../utils/constants'; export function addFindingsMethods(securityAnalytics: any, createAction: any): void { securityAnalytics[METHOD_NAMES.GET_FINDINGS] = createAction({ url: { - fmt: `${API.GET_FINDINGS}?detector_id=<%=detectorId%>`, + fmt: `${API.GET_FINDINGS}?detector_id=<%=detectorId%>&sortOrder=<%=sortOrder%>&size=<%=size%>`, req: { detectorId: { type: 'string', required: false, }, + sortOrder: { + type: 'string', + required: false, + }, + size: { + type: 'number', + required: false, + }, }, }, needBody: false, diff --git a/server/models/interfaces/Alerts.ts b/server/models/interfaces/Alerts.ts index 85dfb3624..294cceb87 100644 --- a/server/models/interfaces/Alerts.ts +++ b/server/models/interfaces/Alerts.ts @@ -3,7 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -export type GetAlertsParams = +export type GetAlertsParams = { + sortOrder?: string; + size?: number; +} & ( | { detector_id: string; detectorType?: string; @@ -11,7 +14,8 @@ export type GetAlertsParams = | { detectorType: string; detector_id?: string; - }; + } +); export interface GetAlertsResponse { alerts: AlertResponse[]; diff --git a/server/models/interfaces/Findings.ts b/server/models/interfaces/Findings.ts index d77e642ad..1532c09dc 100644 --- a/server/models/interfaces/Findings.ts +++ b/server/models/interfaces/Findings.ts @@ -5,7 +5,10 @@ import { Finding } from '../../../public/pages/Findings/models/interfaces'; -export type GetFindingsParams = +export type GetFindingsParams = { + sortOrder?: string; + size?: number; +} & ( | { detectorId: string; detectorType?: string; @@ -13,7 +16,8 @@ export type GetFindingsParams = | { detectorType: string; detectorId?: string; - }; + } +); export interface GetFindingsResponse { total_findings: number; diff --git a/server/routes/AlertRoutes.ts b/server/routes/AlertRoutes.ts index 0cb302b0a..c8001f50d 100644 --- a/server/routes/AlertRoutes.ts +++ b/server/routes/AlertRoutes.ts @@ -18,6 +18,8 @@ export function setupAlertsRoutes(services: NodeServices, router: IRouter) { query: schema.object({ detectorType: schema.maybe(schema.string()), detector_id: schema.maybe(schema.string()), + sortOrder: schema.maybe(schema.string()), + size: schema.maybe(schema.number()), }), }, }, diff --git a/server/routes/FindingsRoutes.ts b/server/routes/FindingsRoutes.ts index 02e7c5aeb..442531d11 100644 --- a/server/routes/FindingsRoutes.ts +++ b/server/routes/FindingsRoutes.ts @@ -18,6 +18,8 @@ export function setupFindingsRoutes(services: NodeServices, router: IRouter) { query: schema.object({ detectorType: schema.maybe(schema.string()), detectorId: schema.maybe(schema.string()), + sortOrder: schema.maybe(schema.string()), + size: schema.maybe(schema.number()), }), }, }, diff --git a/server/services/AlertService.ts b/server/services/AlertService.ts index b0f52c965..4452238cc 100644 --- a/server/services/AlertService.ts +++ b/server/services/AlertService.ts @@ -36,15 +36,21 @@ export default class AlertService { response: OpenSearchDashboardsResponseFactory ): Promise | ResponseError>> => { try { - const { detectorType, detector_id } = request.query; + const { detectorType, detector_id, sortOrder, size } = request.query; + const defaultParams = { + sortOrder, + size, + }; let params: GetAlertsParams; if (detector_id) { params = { + ...defaultParams, detector_id, }; } else if (detectorType) { params = { + ...defaultParams, detectorType, }; } else { diff --git a/server/services/FindingsService.ts b/server/services/FindingsService.ts index 60735da85..85571e836 100644 --- a/server/services/FindingsService.ts +++ b/server/services/FindingsService.ts @@ -33,15 +33,21 @@ export default class FindingsService { IOpenSearchDashboardsResponse | ResponseError> > => { try { - const { detectorType, detectorId } = request.query; + const { detectorType, detectorId, sortOrder, size } = request.query; + const defaultParams = { + sortOrder, + size, + }; let params: GetFindingsParams; if (detectorId) { params = { + ...defaultParams, detectorId, }; } else if (detectorType) { params = { + ...defaultParams, detectorType, }; } else {