Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [SecuritySolution][SIEM migrations] Implement background task API (#197997) #199209

Merged
merged 1 commit into from
Nov 7, 2024
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 @@ -364,7 +364,16 @@ import type {
import type {
CreateRuleMigrationRequestBodyInput,
CreateRuleMigrationResponse,
GetAllStatsRuleMigrationResponse,
GetRuleMigrationRequestParamsInput,
GetRuleMigrationResponse,
GetRuleMigrationStatsRequestParamsInput,
GetRuleMigrationStatsResponse,
StartRuleMigrationRequestParamsInput,
StartRuleMigrationRequestBodyInput,
StartRuleMigrationResponse,
StopRuleMigrationRequestParamsInput,
StopRuleMigrationResponse,
} from '../siem_migrations/model/api/rules/rules_migration.gen';

export interface ClientOptions {
Expand Down Expand Up @@ -1205,6 +1214,21 @@ finalize it.
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Retrieves the rule migrations stats for all migrations stored in the system
*/
async getAllStatsRuleMigration() {
this.log.info(`${new Date().toISOString()} Calling API GetAllStatsRuleMigration`);
return this.kbnClient
.request<GetAllStatsRuleMigrationResponse>({
path: '/internal/siem_migrations/rules/stats',
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
},
method: 'GET',
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Get the criticality record for a specific asset.
*/
Expand Down Expand Up @@ -1395,13 +1419,28 @@ finalize it.
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Retrieves the rule migrations stored in the system
* Retrieves the rule documents stored in the system given the rule migration id
*/
async getRuleMigration() {
async getRuleMigration(props: GetRuleMigrationProps) {
this.log.info(`${new Date().toISOString()} Calling API GetRuleMigration`);
return this.kbnClient
.request<GetRuleMigrationResponse>({
path: '/internal/siem_migrations/rules',
path: replaceParams('/internal/siem_migrations/rules/{migration_id}', props.params),
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
},
method: 'GET',
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Retrieves the stats of a SIEM rules migration using the migration id provided
*/
async getRuleMigrationStats(props: GetRuleMigrationStatsProps) {
this.log.info(`${new Date().toISOString()} Calling API GetRuleMigrationStats`);
return this.kbnClient
.request<GetRuleMigrationStatsResponse>({
path: replaceParams('/internal/siem_migrations/rules/{migration_id}/stats', props.params),
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
},
Expand Down Expand Up @@ -1913,6 +1952,22 @@ detection engine rules.
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Starts a SIEM rules migration using the migration id provided
*/
async startRuleMigration(props: StartRuleMigrationProps) {
this.log.info(`${new Date().toISOString()} Calling API StartRuleMigration`);
return this.kbnClient
.request<StartRuleMigrationResponse>({
path: replaceParams('/internal/siem_migrations/rules/{migration_id}/start', props.params),
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
},
method: 'PUT',
body: props.body,
})
.catch(catchAxiosErrorFormatAndThrow);
}
async stopEntityEngine(props: StopEntityEngineProps) {
this.log.info(`${new Date().toISOString()} Calling API StopEntityEngine`);
return this.kbnClient
Expand All @@ -1925,6 +1980,21 @@ detection engine rules.
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Stops a running SIEM rules migration using the migration id provided
*/
async stopRuleMigration(props: StopRuleMigrationProps) {
this.log.info(`${new Date().toISOString()} Calling API StopRuleMigration`);
return this.kbnClient
.request<StopRuleMigrationResponse>({
path: replaceParams('/internal/siem_migrations/rules/{migration_id}/stop', props.params),
headers: {
[ELASTIC_HTTP_VERSION_HEADER]: '1',
},
method: 'PUT',
})
.catch(catchAxiosErrorFormatAndThrow);
}
/**
* Suggests user profiles.
*/
Expand Down Expand Up @@ -2161,6 +2231,12 @@ export interface GetRuleExecutionResultsProps {
query: GetRuleExecutionResultsRequestQueryInput;
params: GetRuleExecutionResultsRequestParamsInput;
}
export interface GetRuleMigrationProps {
params: GetRuleMigrationRequestParamsInput;
}
export interface GetRuleMigrationStatsProps {
params: GetRuleMigrationStatsRequestParamsInput;
}
export interface GetTimelineProps {
query: GetTimelineRequestQueryInput;
}
Expand Down Expand Up @@ -2237,9 +2313,16 @@ export interface SetAlertTagsProps {
export interface StartEntityEngineProps {
params: StartEntityEngineRequestParamsInput;
}
export interface StartRuleMigrationProps {
params: StartRuleMigrationRequestParamsInput;
body: StartRuleMigrationRequestBodyInput;
}
export interface StopEntityEngineProps {
params: StopEntityEngineRequestParamsInput;
}
export interface StopRuleMigrationProps {
params: StopRuleMigrationRequestParamsInput;
}
export interface SuggestUserProfilesProps {
query: SuggestUserProfilesRequestQueryInput;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@
export const SIEM_MIGRATIONS_PATH = '/internal/siem_migrations' as const;
export const SIEM_RULE_MIGRATIONS_PATH = `${SIEM_MIGRATIONS_PATH}/rules` as const;

export enum SiemMigrationsStatus {
export const SIEM_RULE_MIGRATIONS_ALL_STATS_PATH = `${SIEM_RULE_MIGRATIONS_PATH}/stats` as const;
export const SIEM_RULE_MIGRATIONS_GET_PATH = `${SIEM_RULE_MIGRATIONS_PATH}/{migration_id}` as const;
export const SIEM_RULE_MIGRATIONS_START_PATH =
`${SIEM_RULE_MIGRATIONS_PATH}/{migration_id}/start` as const;
export const SIEM_RULE_MIGRATIONS_STATS_PATH =
`${SIEM_RULE_MIGRATIONS_PATH}/{migration_id}/stats` as const;
export const SIEM_RULE_MIGRATIONS_STOP_PATH =
`${SIEM_RULE_MIGRATIONS_PATH}/{migration_id}/stop` as const;

export enum SiemMigrationStatus {
PENDING = 'pending',
PROCESSING = 'processing',
FINISHED = 'finished',
ERROR = 'error',
COMPLETED = 'completed',
FAILED = 'failed',
}

export enum SiemMigrationRuleTranslationResult {
FULL = 'full',
PARTIAL = 'partial',
UNTRANSLATABLE = 'untranslatable',
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

import { z } from '@kbn/zod';

import { OriginalRule, RuleMigration } from '../../rule_migration.gen';
import {
OriginalRule,
RuleMigrationAllTaskStats,
RuleMigration,
RuleMigrationTaskStats,
} from '../../rule_migration.gen';
import { ConnectorId, LangSmithOptions } from '../common.gen';

export type CreateRuleMigrationRequestBody = z.infer<typeof CreateRuleMigrationRequestBody>;
export const CreateRuleMigrationRequestBody = z.array(OriginalRule);
Expand All @@ -30,5 +36,60 @@ export const CreateRuleMigrationResponse = z.object({
migration_id: z.string(),
});

export type GetAllStatsRuleMigrationResponse = z.infer<typeof GetAllStatsRuleMigrationResponse>;
export const GetAllStatsRuleMigrationResponse = RuleMigrationAllTaskStats;

export type GetRuleMigrationRequestParams = z.infer<typeof GetRuleMigrationRequestParams>;
export const GetRuleMigrationRequestParams = z.object({
migration_id: z.string(),
});
export type GetRuleMigrationRequestParamsInput = z.input<typeof GetRuleMigrationRequestParams>;

export type GetRuleMigrationResponse = z.infer<typeof GetRuleMigrationResponse>;
export const GetRuleMigrationResponse = z.array(RuleMigration);

export type GetRuleMigrationStatsRequestParams = z.infer<typeof GetRuleMigrationStatsRequestParams>;
export const GetRuleMigrationStatsRequestParams = z.object({
migration_id: z.string(),
});
export type GetRuleMigrationStatsRequestParamsInput = z.input<
typeof GetRuleMigrationStatsRequestParams
>;

export type GetRuleMigrationStatsResponse = z.infer<typeof GetRuleMigrationStatsResponse>;
export const GetRuleMigrationStatsResponse = RuleMigrationTaskStats;

export type StartRuleMigrationRequestParams = z.infer<typeof StartRuleMigrationRequestParams>;
export const StartRuleMigrationRequestParams = z.object({
migration_id: z.string(),
});
export type StartRuleMigrationRequestParamsInput = z.input<typeof StartRuleMigrationRequestParams>;

export type StartRuleMigrationRequestBody = z.infer<typeof StartRuleMigrationRequestBody>;
export const StartRuleMigrationRequestBody = z.object({
connector_id: ConnectorId,
langsmith_options: LangSmithOptions.optional(),
});
export type StartRuleMigrationRequestBodyInput = z.input<typeof StartRuleMigrationRequestBody>;

export type StartRuleMigrationResponse = z.infer<typeof StartRuleMigrationResponse>;
export const StartRuleMigrationResponse = z.object({
/**
* Indicates the migration has been started. `false` means the migration does not need to be started.
*/
started: z.boolean(),
});

export type StopRuleMigrationRequestParams = z.infer<typeof StopRuleMigrationRequestParams>;
export const StopRuleMigrationRequestParams = z.object({
migration_id: z.string(),
});
export type StopRuleMigrationRequestParamsInput = z.input<typeof StopRuleMigrationRequestParams>;

export type StopRuleMigrationResponse = z.infer<typeof StopRuleMigrationResponse>;
export const StopRuleMigrationResponse = z.object({
/**
* Indicates the migration has been stopped.
*/
stopped: z.boolean(),
});
Loading