From 4b1b78761ea6d26bede52d0785419cfc0ae3d5a0 Mon Sep 17 00:00:00 2001 From: Ying Mao Date: Mon, 22 Mar 2021 14:20:44 -0400 Subject: [PATCH] Simplifying --- .../actions/server/actions_client.test.ts | 1 - .../actions/server/actions_config.test.ts | 1 - .../alert_history_es_index.ts | 27 ------- .../alert_history_es_index/types.ts | 37 --------- .../server/builtin_action_types/es_index.ts | 19 +++-- x-pack/plugins/actions/server/config.test.ts | 2 - x-pack/plugins/actions/server/config.ts | 1 - x-pack/plugins/actions/server/mocks.ts | 3 +- x-pack/plugins/actions/server/plugin.test.ts | 11 --- x-pack/plugins/actions/server/plugin.ts | 20 +---- x-pack/plugins/actions/server/types.ts | 6 +- ...reate_alert_history_index_template.test.ts | 65 +++++++++++++++ .../create_alert_history_index_template.ts} | 80 ++----------------- .../server/alert_history}/mappings.json | 4 - .../alerting/server/alert_history/types.ts | 10 +++ x-pack/plugins/alerting/server/plugin.ts | 6 ++ .../task_runner/create_execution_handler.ts | 1 - .../transform_action_params.test.ts | 18 ----- .../task_runner/transform_action_params.ts | 9 +-- .../es_index/es_index.tsx | 25 +++--- .../components/builtin_action_types/types.ts | 1 + 21 files changed, 121 insertions(+), 226 deletions(-) delete mode 100644 x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/alert_history_es_index.ts delete mode 100644 x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/types.ts create mode 100644 x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.test.ts rename x-pack/plugins/{actions/server/builtin_action_types/alert_history_es_index/create_alert_history_es_index.ts => alerting/server/alert_history/create_alert_history_index_template.ts} (53%) rename x-pack/plugins/{actions/server/builtin_action_types/alert_history_es_index => alerting/server/alert_history}/mappings.json (94%) create mode 100644 x-pack/plugins/alerting/server/alert_history/types.ts diff --git a/x-pack/plugins/actions/server/actions_client.test.ts b/x-pack/plugins/actions/server/actions_client.test.ts index 88eb956e5fc4a..98b9b46fac48d 100644 --- a/x-pack/plugins/actions/server/actions_client.test.ts +++ b/x-pack/plugins/actions/server/actions_client.test.ts @@ -403,7 +403,6 @@ describe('create()', () => { enabled: true, enabledActionTypes: ['some-not-ignored-action-type'], allowedHosts: ['*'], - preconfiguredAlertHistoryEsIndex: true, preconfigured: {}, proxyRejectUnauthorizedCertificates: true, rejectUnauthorized: true, diff --git a/x-pack/plugins/actions/server/actions_config.test.ts b/x-pack/plugins/actions/server/actions_config.test.ts index 356fa3a3c9b77..cae6777a82441 100644 --- a/x-pack/plugins/actions/server/actions_config.test.ts +++ b/x-pack/plugins/actions/server/actions_config.test.ts @@ -16,7 +16,6 @@ const defaultActionsConfig: ActionsConfig = { enabled: false, allowedHosts: [], enabledActionTypes: [], - preconfiguredAlertHistoryEsIndex: true, preconfigured: {}, proxyRejectUnauthorizedCertificates: true, rejectUnauthorized: true, diff --git a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/alert_history_es_index.ts b/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/alert_history_es_index.ts deleted file mode 100644 index 01d7c5eaa37c8..0000000000000 --- a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/alert_history_es_index.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { i18n } from '@kbn/i18n'; -import { PreConfiguredAction } from '../../types'; -import { ActionTypeId as EsIndexActionTypeId } from '../es_index'; -import { AlertHistoryEsIndexConnectorId } from '../../../common'; -import { getInitialIndexName } from './types'; - -export function getAlertHistoryEsIndex(kibanaVersion: string): Readonly { - return Object.freeze({ - name: i18n.translate('xpack.actions.alertHistoryEsIndexConnector.name', { - defaultMessage: 'Alert History ES Index', - }), - actionTypeId: EsIndexActionTypeId, - id: AlertHistoryEsIndexConnectorId, - isPreconfigured: true, - config: { - index: getInitialIndexName(kibanaVersion), - }, - secrets: {}, - }); -} diff --git a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/types.ts b/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/types.ts deleted file mode 100644 index 6a31b9582a7f9..0000000000000 --- a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/types.ts +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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. - */ - -export const ALERT_HISTORY = 'alert-history'; - -export const AlertHistoryEsIndexConnectorIndexName = `${ALERT_HISTORY}-index`; -export const AlertHistoryIlmPolicyName = `${ALERT_HISTORY}-policy`; - -export const AlertHistoryIlmPolicy = { - policy: { - phases: { - hot: { - actions: { - rollover: { - max_size: '50GB', - max_age: '30d', - }, - }, - }, - delete: { - min_age: '90d', - actions: { - delete: {}, - }, - }, - }, - }, -}; - -export const getIndexName = (kibanaVersion: string) => `${ALERT_HISTORY}-${kibanaVersion}`; - -export const getInitialIndexName = (kibanaVersion: string) => - `${getIndexName(kibanaVersion)}-000001`; diff --git a/x-pack/plugins/actions/server/builtin_action_types/es_index.ts b/x-pack/plugins/actions/server/builtin_action_types/es_index.ts index 9d065164d30d6..d6222f4640c6c 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/es_index.ts +++ b/x-pack/plugins/actions/server/builtin_action_types/es_index.ts @@ -11,7 +11,7 @@ import { schema, TypeOf } from '@kbn/config-schema'; import { Logger } from '../../../../../src/core/server'; import { ActionType, ActionTypeExecutorOptions, ActionTypeExecutorResult } from '../types'; import { renderMustacheObject } from '../lib/mustache_renderer'; -import { buildAlertHistoryDocument, AlertHistoryEsIndexConnectorId } from '../../common'; +import { buildAlertHistoryDocument } from '../../common'; export type ESIndexActionType = ActionType; export type ESIndexActionTypeExecutorOptions = ActionTypeExecutorOptions< @@ -39,6 +39,7 @@ export type ActionParamsType = TypeOf; // eventually: https://github.com/elastic/kibana/projects/26#card-24087404 const ParamsSchema = schema.object({ documents: schema.arrayOf(schema.recordOf(schema.string(), schema.any())), + usePreconfiguredSchema: schema.boolean({ defaultValue: false }), }); export const ActionTypeId = '.index'; @@ -111,20 +112,22 @@ async function executor( function renderParameterTemplates( params: ActionParamsType, - variables: Record, - actionId: string + variables: Record ): ActionParamsType { - const { documents } = renderMustacheObject(params, variables); + const { documents, usePreconfiguredSchema } = renderMustacheObject( + params, + variables + ); - if (actionId === AlertHistoryEsIndexConnectorId) { + if (usePreconfiguredSchema) { const alertHistoryDoc = buildAlertHistoryDocument(variables); if (!alertHistoryDoc) { - throw new Error(`error creating alert history document for ${actionId} connector`); + throw new Error(`error creating alert history document`); } - return { documents: [alertHistoryDoc] }; + return { documents: [alertHistoryDoc], usePreconfiguredSchema }; } - return { documents }; + return { documents, usePreconfiguredSchema }; } function wrapErr( diff --git a/x-pack/plugins/actions/server/config.test.ts b/x-pack/plugins/actions/server/config.test.ts index 00433a371edef..c90a5b2fb9768 100644 --- a/x-pack/plugins/actions/server/config.test.ts +++ b/x-pack/plugins/actions/server/config.test.ts @@ -20,7 +20,6 @@ describe('config validation', () => { "*", ], "preconfigured": Object {}, - "preconfiguredAlertHistoryEsIndex": true, "proxyRejectUnauthorizedCertificates": true, "rejectUnauthorized": true, } @@ -60,7 +59,6 @@ describe('config validation', () => { "secrets": Object {}, }, }, - "preconfiguredAlertHistoryEsIndex": true, "proxyRejectUnauthorizedCertificates": false, "rejectUnauthorized": false, } diff --git a/x-pack/plugins/actions/server/config.ts b/x-pack/plugins/actions/server/config.ts index 8aef8a72f2518..b4f29b752957f 100644 --- a/x-pack/plugins/actions/server/config.ts +++ b/x-pack/plugins/actions/server/config.ts @@ -29,7 +29,6 @@ export const configSchema = schema.object({ defaultValue: [AllowedHosts.Any], } ), - preconfiguredAlertHistoryEsIndex: schema.boolean({ defaultValue: true }), preconfigured: schema.recordOf(schema.string(), preconfiguredActionSchema, { defaultValue: {}, validate: validatePreconfigured, diff --git a/x-pack/plugins/actions/server/mocks.ts b/x-pack/plugins/actions/server/mocks.ts index 4d32c2e2bf16d..ab29f524c202d 100644 --- a/x-pack/plugins/actions/server/mocks.ts +++ b/x-pack/plugins/actions/server/mocks.ts @@ -40,11 +40,10 @@ const createStartMock = () => { // this is a default renderer that escapes nothing export function renderActionParameterTemplatesDefault( actionTypeId: string, - actionId: string, params: Record, variables: Record ) { - return renderActionParameterTemplates(undefined, actionTypeId, actionId, params, variables); + return renderActionParameterTemplates(undefined, actionTypeId, params, variables); } const createServicesMock = () => { diff --git a/x-pack/plugins/actions/server/plugin.test.ts b/x-pack/plugins/actions/server/plugin.test.ts index 89f4634faa90e..b8f83e91239e2 100644 --- a/x-pack/plugins/actions/server/plugin.test.ts +++ b/x-pack/plugins/actions/server/plugin.test.ts @@ -34,7 +34,6 @@ describe('Actions Plugin', () => { enabled: true, enabledActionTypes: ['*'], allowedHosts: ['*'], - preconfiguredAlertHistoryEsIndex: true, preconfigured: {}, proxyRejectUnauthorizedCertificates: true, rejectUnauthorized: true, @@ -188,7 +187,6 @@ describe('Actions Plugin', () => { enabled: true, enabledActionTypes: ['*'], allowedHosts: ['*'], - preconfiguredAlertHistoryEsIndex: true, preconfigured: { preconfiguredServerLog: { actionTypeId: '.server-log', @@ -228,15 +226,6 @@ describe('Actions Plugin', () => { expect(pluginStart.isActionExecutable('preconfiguredServerLog', '.server-log')).toBe(true); }); - it('should handle preconfiguredAlertHistoryEsIndex = true', async () => { - await plugin.setup(coreSetup, pluginsSetup); - const pluginStart = await plugin.start(coreStart, pluginsStart); - - expect( - pluginStart.isActionExecutable('preconfigured-alert-history-es-index', '.index') - ).toBe(true); - }); - it('should not throw error when ESO plugin has encryption key', async () => { await plugin.setup(coreSetup, { ...pluginsSetup, diff --git a/x-pack/plugins/actions/server/plugin.ts b/x-pack/plugins/actions/server/plugin.ts index 735c1e7279b0b..5ec9241533b3c 100644 --- a/x-pack/plugins/actions/server/plugin.ts +++ b/x-pack/plugins/actions/server/plugin.ts @@ -68,8 +68,6 @@ import { } from './authorization/get_authorization_mode_by_source'; import { ensureSufficientLicense } from './lib/ensure_sufficient_license'; import { renderMustacheObject } from './lib/mustache_renderer'; -import { getAlertHistoryEsIndex } from './builtin_action_types/alert_history_es_index/alert_history_es_index'; -import { createAlertHistoryEsIndex } from './builtin_action_types/alert_history_es_index/create_alert_history_es_index'; const EVENT_LOG_PROVIDER = 'actions'; export const EVENT_LOG_ACTIONS = { @@ -100,7 +98,6 @@ export interface PluginStartContract { preconfiguredActions: PreConfiguredAction[]; renderActionParameterTemplates( actionTypeId: string, - actionId: string, params: Params, variables: Record ): Params; @@ -142,7 +139,6 @@ export class ActionsPlugin implements Plugin(); @@ -150,7 +146,6 @@ export class ActionsPlugin implements Plugin { return this.actionTypeRegistry!.isActionTypeEnabled(id, options); @@ -485,13 +468,12 @@ export class ActionsPlugin implements Plugin( actionTypeRegistry: ActionTypeRegistry | undefined, actionTypeId: string, - actionId: string, params: Params, variables: Record ): Params { const actionType = actionTypeRegistry?.get(actionTypeId); if (actionType?.renderParameterTemplates) { - return actionType.renderParameterTemplates(params, variables, actionId) as Params; + return actionType.renderParameterTemplates(params, variables) as Params; } else { return renderMustacheObject(params, variables); } diff --git a/x-pack/plugins/actions/server/types.ts b/x-pack/plugins/actions/server/types.ts index 7bab71c2a7d9c..4e3916f5d6e23 100644 --- a/x-pack/plugins/actions/server/types.ts +++ b/x-pack/plugins/actions/server/types.ts @@ -107,11 +107,7 @@ export interface ActionType< config?: ValidatorType; secrets?: ValidatorType; }; - renderParameterTemplates?( - params: Params, - variables: Record, - actionId?: string - ): Params; + renderParameterTemplates?(params: Params, variables: Record): Params; executor: ExecutorType; } diff --git a/x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.test.ts b/x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.test.ts new file mode 100644 index 0000000000000..074ceea1f4a24 --- /dev/null +++ b/x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.test.ts @@ -0,0 +1,65 @@ +/* + * 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 { contextMock } from './context.mock'; +import { initializeEs } from './init'; + +describe('initializeEs', () => { + let esContext = contextMock.create(); + + beforeEach(() => { + esContext = contextMock.create(); + }); + + test(`should create ILM policy if it doesn't exist`, async () => { + esContext.esAdapter.doesIlmPolicyExist.mockResolvedValue(false); + + await initializeEs(esContext); + expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled(); + expect(esContext.esAdapter.createIlmPolicy).toHaveBeenCalled(); + }); + + test(`shouldn't create ILM policy if it exists`, async () => { + esContext.esAdapter.doesIlmPolicyExist.mockResolvedValue(true); + + await initializeEs(esContext); + expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled(); + expect(esContext.esAdapter.createIlmPolicy).not.toHaveBeenCalled(); + }); + + test(`should create index template if it doesn't exist`, async () => { + esContext.esAdapter.doesIndexTemplateExist.mockResolvedValue(false); + + await initializeEs(esContext); + expect(esContext.esAdapter.doesIndexTemplateExist).toHaveBeenCalled(); + expect(esContext.esAdapter.createIndexTemplate).toHaveBeenCalled(); + }); + + test(`shouldn't create index template if it already exists`, async () => { + esContext.esAdapter.doesIndexTemplateExist.mockResolvedValue(true); + + await initializeEs(esContext); + expect(esContext.esAdapter.doesIndexTemplateExist).toHaveBeenCalled(); + expect(esContext.esAdapter.createIndexTemplate).not.toHaveBeenCalled(); + }); + + test(`should create initial index if it doesn't exist`, async () => { + esContext.esAdapter.doesAliasExist.mockResolvedValue(false); + + await initializeEs(esContext); + expect(esContext.esAdapter.doesAliasExist).toHaveBeenCalled(); + expect(esContext.esAdapter.createIndex).toHaveBeenCalled(); + }); + + test(`shouldn't create initial index if it already exists`, async () => { + esContext.esAdapter.doesAliasExist.mockResolvedValue(true); + + await initializeEs(esContext); + expect(esContext.esAdapter.doesAliasExist).toHaveBeenCalled(); + expect(esContext.esAdapter.createIndex).not.toHaveBeenCalled(); + }); +}); diff --git a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/create_alert_history_es_index.ts b/x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.ts similarity index 53% rename from x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/create_alert_history_es_index.ts rename to x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.ts index d84479eb8d807..a2d9b10bfb472 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/create_alert_history_es_index.ts +++ b/x-pack/plugins/alerting/server/alert_history/create_alert_history_index_template.ts @@ -8,76 +8,17 @@ import { ElasticsearchClient, Logger } from 'src/core/server'; import mappings from './mappings.json'; -import { getIndexName, AlertHistoryIlmPolicyName, AlertHistoryIlmPolicy } from './types'; - -function getAlertHistoryIndexTemplate(indexName: string, ilmPolicyName: string) { +function getAlertHistoryIndexTemplate() { return { - index_patterns: [`${indexName}-*`], + index_patterns: [`alert-history-*`], settings: { number_of_shards: 1, auto_expand_replicas: '0-1', - 'index.lifecycle.name': ilmPolicyName, - 'index.lifecycle.rollover_alias': indexName, }, mappings, }; } -async function doesIlmPolicyExist({ - client, - policyName, -}: { - client: ElasticsearchClient; - policyName: string; -}) { - try { - await client.transport.request({ - method: 'GET', - path: `/_ilm/policy/${policyName}`, - }); - } catch (err) { - if (err.statusCode === 404) { - return false; - } else { - throw new Error(`error checking existence of ilm policy: ${err.message}`); - } - } - - return true; -} - -async function createIlmPolicy({ - client, - policyName, -}: { - client: ElasticsearchClient; - policyName: string; -}) { - try { - await client.transport.request({ - method: 'PUT', - path: `/_ilm/policy/${policyName}`, - body: AlertHistoryIlmPolicy, - }); - } catch (err) { - throw new Error(`error creating ilm policy: ${err.message}`); - } -} - -async function createIlmPolicyIfNotExists({ - client, - policyName, -}: { - client: ElasticsearchClient; - policyName: string; -}) { - const ilmPolicyExists = await doesIlmPolicyExist({ client, policyName }); - - if (!ilmPolicyExists) { - await createIlmPolicy({ client, policyName }); - } -} - async function doesIndexTemplateExist({ client, templateName, @@ -138,27 +79,22 @@ async function createIndexTemplateIfNotExists({ } } -export async function createAlertHistoryEsIndex({ +export async function createAlertHistoryIndexTemplate({ client, - kibanaVersion, logger, }: { client: ElasticsearchClient; - kibanaVersion: string; logger: Logger; }) { try { - const indexName = getIndexName(kibanaVersion); - const ilmPolicyName = AlertHistoryIlmPolicyName; - const indexTemplate = getAlertHistoryIndexTemplate(indexName, ilmPolicyName); - - await createIlmPolicyIfNotExists({ client, policyName: ilmPolicyName }); await createIndexTemplateIfNotExists({ client, - templateName: `${indexName}-template`, - template: indexTemplate, + templateName: `alert-history-template`, + template: getAlertHistoryIndexTemplate(), }); } catch (err) { - logger.error(`Could not initialize alert history index with mappings: ${err.message}.`); + logger.error( + `Could not initialize alert history index template with mappings: ${err.message}.` + ); } } diff --git a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/mappings.json b/x-pack/plugins/alerting/server/alert_history/mappings.json similarity index 94% rename from x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/mappings.json rename to x-pack/plugins/alerting/server/alert_history/mappings.json index ef3e0ad233cca..f53e6dd307ec1 100644 --- a/x-pack/plugins/actions/server/builtin_action_types/alert_history_es_index/mappings.json +++ b/x-pack/plugins/alerting/server/alert_history/mappings.json @@ -21,10 +21,6 @@ }, "id": { "type": "keyword" - }, - "state": { - "type": "object", - "enabled": false } } }, diff --git a/x-pack/plugins/alerting/server/alert_history/types.ts b/x-pack/plugins/alerting/server/alert_history/types.ts new file mode 100644 index 0000000000000..3c6de33077613 --- /dev/null +++ b/x-pack/plugins/alerting/server/alert_history/types.ts @@ -0,0 +1,10 @@ +/* + * 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. + */ + +export const ALERT_HISTORY = 'alert-history'; + +export const AlertHistoryEsIndexConnectorIndexName = `${ALERT_HISTORY}-index`; diff --git a/x-pack/plugins/alerting/server/plugin.ts b/x-pack/plugins/alerting/server/plugin.ts index ff36ebcd84ba5..811d14163cb8b 100644 --- a/x-pack/plugins/alerting/server/plugin.ts +++ b/x-pack/plugins/alerting/server/plugin.ts @@ -86,6 +86,7 @@ import { } from './health'; import { AlertsConfig } from './config'; import { getHealth } from './health/get_health'; +import { createAlertHistoryIndexTemplate } from './alert_history/create_alert_history_index_template'; export const EVENT_LOG_PROVIDER = 'alerting'; export const EVENT_LOG_ACTIONS = { @@ -384,6 +385,11 @@ export class AlertingPlugin { : Promise.resolve([]); }); + createAlertHistoryIndexTemplate({ + client: core.elasticsearch.client.asInternalUser, + logger: this.logger, + }); + scheduleAlertingTelemetry(this.telemetryLogger, plugins.taskManager); scheduleAlertingHealthCheck(this.logger, this.config, plugins.taskManager); diff --git a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts index 2ecf540485695..bf6b372d7bd80 100644 --- a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts +++ b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.ts @@ -128,7 +128,6 @@ export function createExecutionHandler< alertActionSubgroup: actionSubgroup, context, actionParams: action.params, - actionId: action.id, state, kibanaBaseUrl, alertParams, diff --git a/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts b/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts index e325d597da145..56e6b5965c7cb 100644 --- a/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/transform_action_params.test.ts @@ -35,7 +35,6 @@ test('skips non string parameters', () => { state: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -71,7 +70,6 @@ test('missing parameters get emptied out', () => { state: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -100,7 +98,6 @@ test('context parameters are passed to templates', () => { context: { foo: 'fooVal' }, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -128,7 +125,6 @@ test('state parameters are passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -156,7 +152,6 @@ test('alertId is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -184,7 +179,6 @@ test('alertName is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -212,7 +206,6 @@ test('tags is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -240,7 +233,6 @@ test('undefined tags is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', spaceId: 'spaceId-A', alertInstanceId: '2', @@ -267,7 +259,6 @@ test('empty tags is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: [], spaceId: 'spaceId-A', @@ -295,7 +286,6 @@ test('spaceId is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -323,7 +313,6 @@ test('alertInstanceId is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -351,7 +340,6 @@ test('alertActionGroup is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -379,7 +367,6 @@ test('alertActionGroupName is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -407,7 +394,6 @@ test('rule variables are passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -437,7 +423,6 @@ test('rule alert variables are passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -467,7 +452,6 @@ test('date is passed to templates', () => { context: {}, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -497,7 +481,6 @@ test('works recursively', () => { context: { value: 'context' }, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', @@ -529,7 +512,6 @@ test('works recursively with arrays', () => { context: { value: 'context' }, alertId: '1', alertType: 'rule-type-id', - actionId: 'action-id', alertName: 'alert-name', tags: ['tag-A', 'tag-B'], spaceId: 'spaceId-A', diff --git a/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts b/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts index 3f9fe9e9c59e0..b0c7bcb25e2d2 100644 --- a/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts +++ b/x-pack/plugins/alerting/server/task_runner/transform_action_params.ts @@ -17,7 +17,6 @@ interface TransformActionParamsOptions { actionsPlugin: ActionsPluginStartContract; alertId: string; alertType: string; - actionId: string; actionTypeId: string; alertName: string; spaceId: string; @@ -37,7 +36,6 @@ export function transformActionParams({ actionsPlugin, alertId, alertType, - actionId, actionTypeId, alertName, spaceId, @@ -83,10 +81,5 @@ export function transformActionParams({ actionSubgroup: alertActionSubgroup, }, }; - return actionsPlugin.renderActionParameterTemplates( - actionTypeId, - actionId, - actionParams, - variables - ); + return actionsPlugin.renderActionParameterTemplates(actionTypeId, actionParams, variables); } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index/es_index.tsx b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index/es_index.tsx index bc09e5abe1120..cf0a3e5a50cc9 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index/es_index.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index/es_index.tsx @@ -56,18 +56,25 @@ export function getActionType(): ActionTypeModel => { const errors = { documents: new Array(), + usePreconfiguredSchema: new Array(), }; const validationResult = { errors }; - if (!actionParams.documents?.length || Object.keys(actionParams.documents[0]).length === 0) { - errors.documents.push( - i18n.translate( - 'xpack.triggersActionsUI.components.builtinActionTypes.error.requiredDocumentJson', - { - defaultMessage: 'Document is required and should be a valid JSON object.', - } - ) - ); + if (!actionParams.usePreconfiguredSchema) { + if ( + !actionParams.documents?.length || + Object.keys(actionParams.documents[0]).length === 0 + ) { + errors.documents.push( + i18n.translate( + 'xpack.triggersActionsUI.components.builtinActionTypes.error.requiredDocumentJson', + { + defaultMessage: 'Document is required and should be a valid JSON object.', + } + ) + ); + } } + return validationResult; }, }; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/types.ts b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/types.ts index 8a1b2bfb4ac22..e57bec1b6947a 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/types.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/types.ts @@ -42,6 +42,7 @@ export interface PagerDutyActionParams { export interface IndexActionParams { documents: Array>; + usePreconfiguredSchema: boolean; } export enum ServerLogLevelOptions {