Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ import type {
CreateDashboardMigrationDashboardsRequestBodyInput,
GetDashboardMigrationRequestParamsInput,
GetDashboardMigrationResponse,
GetDashboardMigrationDashboardsRequestQueryInput,
GetDashboardMigrationDashboardsRequestParamsInput,
GetDashboardMigrationDashboardsResponse,
GetDashboardMigrationResourcesRequestQueryInput,
GetDashboardMigrationResourcesRequestParamsInput,
GetDashboardMigrationResourcesResponse,
Expand Down Expand Up @@ -1501,6 +1504,26 @@ finalize it.
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Retrieves the dashboards added to an existing dashboard migration
*/
async getDashboardMigrationDashboards(props: GetDashboardMigrationDashboardsProps) {
this.log.info(`${new Date().toISOString()} Calling API GetDashboardMigrationDashboards`);
return this.kbnClient
.request<GetDashboardMigrationDashboardsResponse>({
path: replaceParams(
'/internal/siem_migrations/dashboards/{migration_id}/dashboards',
props.params
),
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
},
method: 'GET',

query: props.query,
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Retrieves resources for an existing SIEM dashboards migration
*/
Expand Down Expand Up @@ -3112,6 +3135,10 @@ export interface GetAssetCriticalityRecordProps {
export interface GetDashboardMigrationProps {
params: GetDashboardMigrationRequestParamsInput;
}
export interface GetDashboardMigrationDashboardsProps {
query: GetDashboardMigrationDashboardsRequestQueryInput;
params: GetDashboardMigrationDashboardsRequestParamsInput;
}
export interface GetDashboardMigrationResourcesProps {
query: GetDashboardMigrationResourcesRequestQueryInput;
params: GetDashboardMigrationResourcesRequestParamsInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import type { SiemMigrationGetItemsOptions } from '../../../server/lib/siem_migrations/common/data/types';
import type { SiemMigrationFilters } from '../types';

export interface DashboardMigrationFilters extends SiemMigrationFilters {
searchTerm?: string;
installed?: boolean;
installable?: boolean;
}
export type DashboardMigrationFilters = SiemMigrationFilters;

export type DashboardMigrationGetDashboardOptions =
SiemMigrationGetItemsOptions<DashboardMigrationFilters>;
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/

import { z } from '@kbn/zod';
import { ArrayFromString } from '@kbn/zod-helpers';
import { ArrayFromString, BooleanFromString } from '@kbn/zod-helpers';

import { NonEmptyString } from '../../../../api/model/primitives.gen';
import {
DashboardMigration,
DashboardMigrationDashboard,
DashboardMigrationTaskExecutionSettings,
DashboardMigrationRetryFilter,
DashboardMigrationTaskStats,
Expand Down Expand Up @@ -82,6 +83,46 @@ export type GetDashboardMigrationRequestParamsInput = z.input<

export type GetDashboardMigrationResponse = z.infer<typeof GetDashboardMigrationResponse>;
export const GetDashboardMigrationResponse = DashboardMigration;
export type GetDashboardMigrationDashboardsRequestQuery = z.infer<
typeof GetDashboardMigrationDashboardsRequestQuery
>;
export const GetDashboardMigrationDashboardsRequestQuery = z.object({
page: z.coerce.number().optional(),
per_page: z.coerce.number().optional(),
sort_field: NonEmptyString.optional(),
sort_direction: z.enum(['asc', 'desc']).optional(),
search_term: z.string().optional(),
ids: ArrayFromString(NonEmptyString).optional(),
is_installed: BooleanFromString.optional(),
is_fully_translated: BooleanFromString.optional(),
is_partially_translated: BooleanFromString.optional(),
is_untranslatable: BooleanFromString.optional(),
is_failed: BooleanFromString.optional(),
});
export type GetDashboardMigrationDashboardsRequestQueryInput = z.input<
typeof GetDashboardMigrationDashboardsRequestQuery
>;

export type GetDashboardMigrationDashboardsRequestParams = z.infer<
typeof GetDashboardMigrationDashboardsRequestParams
>;
export const GetDashboardMigrationDashboardsRequestParams = z.object({
migration_id: NonEmptyString,
});
export type GetDashboardMigrationDashboardsRequestParamsInput = z.input<
typeof GetDashboardMigrationDashboardsRequestParams
>;

export type GetDashboardMigrationDashboardsResponse = z.infer<
typeof GetDashboardMigrationDashboardsResponse
>;
export const GetDashboardMigrationDashboardsResponse = z.object({
/**
* The total number of rules in migration.
*/
total: z.number(),
data: z.array(DashboardMigrationDashboard),
});
export type GetDashboardMigrationResourcesRequestQuery = z.infer<
typeof GetDashboardMigrationResourcesRequestQuery
>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,100 @@ paths:
responses:
200:
description: Indicates dashboards have been added to the migration successfully.
get:
summary: Retrieves dashboards for a migration
operationId: GetDashboardMigrationDashboards
x-codegen-enabled: true
x-internal: true
description: Retrieves the dashboards added to an existing dashboard migration
tags:
- SIEM Dashboard Migrations
parameters:
- name: migration_id
in: path
required: true
schema:
description: The migration id to start
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
- name: page
in: query
required: false
schema:
type: number
- name: per_page
in: query
required: false
schema:
type: number
- name: sort_field
in: query
required: false
schema:
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
- name: sort_direction
in: query
required: false
schema:
type: string
enum:
- asc
- desc
- name: search_term
in: query
required: false
schema:
type: string
- name: ids
in: query
required: false
schema:
type: array
items:
description: The rule migration id
$ref: '../../../../../common/api/model/primitives.schema.yaml#/components/schemas/NonEmptyString'
- name: is_installed
in: query
required: false
schema:
type: boolean
- name: is_fully_translated
in: query
required: false
schema:
type: boolean
- name: is_partially_translated
in: query
required: false
schema:
type: boolean
- name: is_untranslatable
in: query
required: false
schema:
type: boolean
- name: is_failed
in: query
required: false
schema:
type: boolean
responses:
200:
description: Indicates dashboards have been retrieved correctly.
content:
application/json:
schema:
type: object
required:
- total
- data
properties:
total:
type: number
description: The total number of rules in migration.
data:
type: array
items:
$ref: '../../dashboard_migration.schema.yaml#/components/schemas/DashboardMigrationDashboard'

/internal/siem_migrations/dashboards/{migration_id}/start:
post:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import type { SiemMigrationFilters } from '../types';

export interface RuleMigrationFilters extends SiemMigrationFilters {
searchTerm?: string;
installed?: boolean;
installable?: boolean;
prebuilt?: boolean;
missingIndex?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export interface SiemMigrationFilters {
fullyTranslated?: boolean;
partiallyTranslated?: boolean;
untranslatable?: boolean;
searchTerm?: string;
installed?: boolean;
installable?: boolean;
}

export type SiemMigrationVendor = OriginalRuleVendor | OriginalDashboardVendor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum SiemMigrationsAuditActions {
SIEM_MIGRATION_RETRIEVED = 'siem_migration_retrieved',
SIEM_MIGRATION_DELETED = 'siem_migration_deleted',
SIEM_MIGRATION_ADDED_RULES = 'siem_migration_added_rules',
SIEM_MIGRATION_RETRIEVED_RULES = 'siem_migration_retrieved_rules',
SIEM_MIGRATION_RETRIEVED_ITEMS = 'siem_migration_retrieved_items',
SIEM_MIGRATION_UPLOADED_RESOURCES = 'siem_migration_uploaded_resources',
SIEM_MIGRATION_RETRIEVED_RESOURCES = 'siem_migration_retrieved_resources',
SIEM_MIGRATION_STARTED = 'siem_migration_started',
Expand Down Expand Up @@ -62,7 +62,7 @@ export const siemMigrationAuditEventType: Record<
[SiemMigrationsAuditActions.SIEM_MIGRATION_UPDATED_RULE]: AUDIT_TYPE.CHANGE,
[SiemMigrationsAuditActions.SIEM_MIGRATION_INSTALLED_RULES]: AUDIT_TYPE.CREATION,
[SiemMigrationsAuditActions.SIEM_MIGRATION_ADDED_RULES]: AUDIT_TYPE.CREATION,
[SiemMigrationsAuditActions.SIEM_MIGRATION_RETRIEVED_RULES]: AUDIT_TYPE.ACCESS,
[SiemMigrationsAuditActions.SIEM_MIGRATION_RETRIEVED_ITEMS]: AUDIT_TYPE.ACCESS,
[SiemMigrationsAuditActions.SIEM_MIGRATION_DELETED]: AUDIT_TYPE.CHANGE,
[SiemMigrationsAuditActions.SIEM_MIGRATION_RETRIEVED_INTEGRATIONS_STATS]: AUDIT_TYPE.ACCESS,
[SiemMigrationsAuditActions.SIEM_MIGRATION_ADDED_DASHBOARDS]: AUDIT_TYPE.CREATION,
Expand Down Expand Up @@ -161,11 +161,11 @@ export class SiemMigrationAuditLogger {
});
}

public async logGetMigrationRules(params: { migrationId: string; error?: Error }): Promise<void> {
public async logGetMigrationItems(params: { migrationId: string; error?: Error }): Promise<void> {
const { migrationId, error } = params;
const message = `User retrieved rules for SIEM migration with [id=${migrationId}]`;
const message = `User retrieved items for SIEM migration with [id=${migrationId}]`;
return this.log({
action: SiemMigrationsAuditActions.SIEM_MIGRATION_RETRIEVED_RULES,
action: SiemMigrationsAuditActions.SIEM_MIGRATION_RETRIEVED_ITEMS,
Comment thread
semd marked this conversation as resolved.
message,
error,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import type {
SiemMigrationAllDataStats,
SiemMigrationDataStats,
SiemMigrationFilters,
SiemMigrationGetItemsOptions,
SiemMigrationSort,
} from './types';
import { dsl } from './dsl_queries';

Expand All @@ -35,18 +37,6 @@ export type CreateMigrationItemInput<I extends ItemDocument> = Omit<
'@timestamp' | 'id' | 'status' | 'created_by' | 'updated_by' | 'updated_at'
>;

export interface SiemMigrationItemSort {
sortField?: string;
sortDirection?: estypes.SortOrder;
}

export interface SiemMigrationGetItemsOptions<F extends object = object> {
filters?: F;
sort?: SiemMigrationItemSort;
from?: number;
size?: number;
}

/* BULK_MAX_SIZE defines the number to break down the bulk operations by.
* The 500 number was chosen as a reasonable number to avoid large payloads. It can be adjusted if needed. */
const BULK_MAX_SIZE = 500 as const;
Expand Down Expand Up @@ -373,5 +363,5 @@ export abstract class SiemMigrationsDataItemClient<
return { bool: { filter } };
}

protected abstract getSortOptions(sort?: SiemMigrationItemSort): estypes.Sort;
protected abstract getSortOptions(sort?: SiemMigrationSort): estypes.Sort;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { estypes } from '@elastic/elasticsearch';

export type SiemMigrationSortHandler = (
direction?: estypes.SortOrder
) => estypes.SortCombinations[];

export const commonSortingOptions = {
translationResult(direction: estypes.SortOrder = 'asc'): estypes.SortCombinations[] {
const field = 'translation_result';
return [
{
_script: {
order: direction,
type: 'number',
script: {
source: `
if (doc.containsKey('${field}') && !doc['${field}'].empty) {
def value = doc['${field}'].value.toLowerCase();
if (value == 'full') { return 2 }
if (value == 'partial') { return 1 }
if (value == 'untranslatable') { return 0 }
}
return -1;
`,
lang: 'painless',
},
},
},
];
},

updated(direction: estypes.SortOrder = 'asc'): estypes.SortCombinations[] {
return [{ updated_at: direction }];
},
};

/**
* Sort Direction `asc` - Missing values come last
* Sort Direction `desc` - Missing values come first
*
* values that exist can be distinct but are treated as same.
*
* */
export const getFieldExistenceSort = (field: string): SiemMigrationSortHandler => {
return (direction: estypes.SortOrder = 'asc') => [
{
_script: {
order: direction,
type: 'number',
script: {
source: `
if (doc.containsKey('${field}') && !doc['${field}'].empty) {
return 0;
}
return 1;
`,
lang: 'painless',
},
},
},
];
};
Comment thread
logeekal marked this conversation as resolved.
Loading