diff --git a/x-pack/examples/alerting_example/server/alert_types/always_firing.ts b/x-pack/examples/alerting_example/server/alert_types/always_firing.ts index 1900f55a51a55..a0abf01e53937 100644 --- a/x-pack/examples/alerting_example/server/alert_types/always_firing.ts +++ b/x-pack/examples/alerting_example/server/alert_types/always_firing.ts @@ -41,6 +41,7 @@ export const alertType: AlertType = { name: 'Always firing', actionGroups: ACTION_GROUPS, defaultActionGroupId: DEFAULT_ACTION_GROUP, + minimumLicenseRequired: 'basic', async executor({ services, params: { instances = DEFAULT_INSTANCES_TO_GENERATE, thresholds }, diff --git a/x-pack/examples/alerting_example/server/alert_types/astros.ts b/x-pack/examples/alerting_example/server/alert_types/astros.ts index 852e6f57d1106..0a2c3f26fe47a 100644 --- a/x-pack/examples/alerting_example/server/alert_types/astros.ts +++ b/x-pack/examples/alerting_example/server/alert_types/astros.ts @@ -42,6 +42,7 @@ export const alertType: AlertType = { id: 'example.people-in-space', name: 'People In Space Right Now', actionGroups: [{ id: 'default', name: 'default' }], + minimumLicenseRequired: 'basic', defaultActionGroupId: 'default', async executor({ services, params }) { const { outerSpaceCapacity, craft: craftToTriggerBy, op } = params; diff --git a/x-pack/plugins/alerts/README.md b/x-pack/plugins/alerts/README.md index 62058d47cbd44..5b0c39985652f 100644 --- a/x-pack/plugins/alerts/README.md +++ b/x-pack/plugins/alerts/README.md @@ -171,6 +171,7 @@ server.newPlatform.setup.plugins.alerts.registerType({ { name: 'cpuUsage', description: 'CPU usage' }, ], }, + minimumLicenseRequired: 'basic', async executor({ alertId, startedAt, @@ -238,6 +239,7 @@ server.newPlatform.setup.plugins.alerts.registerType({ }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', actionVariables: { context: [ { name: 'server', description: 'the server' }, diff --git a/x-pack/plugins/alerts/common/alert_type.ts b/x-pack/plugins/alerts/common/alert_type.ts index f07555c334074..364c07edfa408 100644 --- a/x-pack/plugins/alerts/common/alert_type.ts +++ b/x-pack/plugins/alerts/common/alert_type.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import { LicenseType } from '../../licensing/common/types'; + export interface AlertType { id: string; name: string; @@ -11,6 +13,7 @@ export interface AlertType { actionVariables: string[]; defaultActionGroupId: ActionGroup['id']; producer: string; + minimumLicenseRequired: LicenseType; } export interface ActionGroup { diff --git a/x-pack/plugins/alerts/public/alert_api.test.ts b/x-pack/plugins/alerts/public/alert_api.test.ts index 0fa2e7f25323b..cd3280aa8f76b 100644 --- a/x-pack/plugins/alerts/public/alert_api.test.ts +++ b/x-pack/plugins/alerts/public/alert_api.test.ts @@ -22,6 +22,7 @@ describe('loadAlertTypes', () => { actionVariables: ['var1'], actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', }, ]; @@ -45,6 +46,7 @@ describe('loadAlertType', () => { actionVariables: ['var1'], actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', }; http.get.mockResolvedValueOnce([alertType]); @@ -65,6 +67,7 @@ describe('loadAlertType', () => { actionVariables: [], actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', }; http.get.mockResolvedValueOnce([alertType]); @@ -80,6 +83,7 @@ describe('loadAlertType', () => { actionVariables: [], actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', }, ]); diff --git a/x-pack/plugins/alerts/public/alert_navigation_registry/alert_navigation_registry.test.ts b/x-pack/plugins/alerts/public/alert_navigation_registry/alert_navigation_registry.test.ts index 72c955923a0cc..3ba2063f66460 100644 --- a/x-pack/plugins/alerts/public/alert_navigation_registry/alert_navigation_registry.test.ts +++ b/x-pack/plugins/alerts/public/alert_navigation_registry/alert_navigation_registry.test.ts @@ -17,6 +17,7 @@ const mockAlertType = (id: string): AlertType => ({ actionVariables: [], defaultActionGroupId: 'default', producer: 'alerts', + minimumLicenseRequired: 'basic', }); describe('AlertNavigationRegistry', () => { diff --git a/x-pack/plugins/alerts/server/alert_type_registry.test.ts b/x-pack/plugins/alerts/server/alert_type_registry.test.ts index b04871a047e4b..a12aea53e0cf9 100644 --- a/x-pack/plugins/alerts/server/alert_type_registry.test.ts +++ b/x-pack/plugins/alerts/server/alert_type_registry.test.ts @@ -8,6 +8,7 @@ import { TaskRunnerFactory } from './task_runner'; import { AlertTypeRegistry } from './alert_type_registry'; import { AlertType } from './types'; import { taskManagerMock } from '../../task_manager/server/mocks'; +import { LicenseType } from '../../licensing/server'; const taskManager = taskManagerMock.createSetup(); const alertTypeRegistryParams = { @@ -35,6 +36,7 @@ describe('has()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }); @@ -54,6 +56,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, executor: jest.fn(), producer: 'alerts', }; @@ -85,6 +88,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, executor: jest.fn(), producer: 'alerts', }; @@ -110,6 +114,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, executor: jest.fn(), producer: 'alerts', }; @@ -133,6 +138,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, executor: jest.fn(), producer: 'alerts', }; @@ -162,6 +168,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, executor: jest.fn(), producer: 'alerts', }; @@ -183,6 +190,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }); @@ -197,6 +205,7 @@ describe('register()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }) @@ -217,6 +226,7 @@ describe('get()', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }); @@ -274,6 +284,7 @@ describe('list()', () => { }, ], defaultActionGroupId: 'testActionGroup', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }); @@ -346,6 +357,7 @@ function alertTypeWithVariables(id: string, context: string, state: string): Ale name: `${id}-name`, actionGroups: [], defaultActionGroupId: id, + minimumLicenseRequired: 'basic' as LicenseType, async executor() {}, producer: 'alerts', }; diff --git a/x-pack/plugins/alerts/server/alerts_client/tests/aggregate.test.ts b/x-pack/plugins/alerts/server/alerts_client/tests/aggregate.test.ts index cc5d10c3346e8..f666c890f12d5 100644 --- a/x-pack/plugins/alerts/server/alerts_client/tests/aggregate.test.ts +++ b/x-pack/plugins/alerts/server/alerts_client/tests/aggregate.test.ts @@ -53,6 +53,7 @@ describe('aggregate()', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myType', name: 'myType', producer: 'myApp', @@ -102,6 +103,7 @@ describe('aggregate()', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', authorizedConsumers: { myApp: { read: true, all: true }, diff --git a/x-pack/plugins/alerts/server/alerts_client/tests/create.test.ts b/x-pack/plugins/alerts/server/alerts_client/tests/create.test.ts index 171ed13763c46..061c20e809fea 100644 --- a/x-pack/plugins/alerts/server/alerts_client/tests/create.test.ts +++ b/x-pack/plugins/alerts/server/alerts_client/tests/create.test.ts @@ -689,6 +689,7 @@ describe('create()', () => { threshold: schema.number({ min: 0, max: 1 }), }), }, + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', }); diff --git a/x-pack/plugins/alerts/server/alerts_client/tests/find.test.ts b/x-pack/plugins/alerts/server/alerts_client/tests/find.test.ts index 3d7473a746986..f3bf1588f9038 100644 --- a/x-pack/plugins/alerts/server/alerts_client/tests/find.test.ts +++ b/x-pack/plugins/alerts/server/alerts_client/tests/find.test.ts @@ -54,6 +54,7 @@ describe('find()', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myType', name: 'myType', producer: 'myApp', @@ -109,6 +110,7 @@ describe('find()', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', authorizedConsumers: { myApp: { read: true, all: true }, diff --git a/x-pack/plugins/alerts/server/alerts_client/tests/lib.ts b/x-pack/plugins/alerts/server/alerts_client/tests/lib.ts index 028a7c6737474..b7b77fb6512d4 100644 --- a/x-pack/plugins/alerts/server/alerts_client/tests/lib.ts +++ b/x-pack/plugins/alerts/server/alerts_client/tests/lib.ts @@ -83,6 +83,7 @@ export function getBeforeSetup( name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', })); diff --git a/x-pack/plugins/alerts/server/alerts_client/tests/list_alert_types.test.ts b/x-pack/plugins/alerts/server/alerts_client/tests/list_alert_types.test.ts index 8cbe47655ef68..ec1f620102b37 100644 --- a/x-pack/plugins/alerts/server/alerts_client/tests/list_alert_types.test.ts +++ b/x-pack/plugins/alerts/server/alerts_client/tests/list_alert_types.test.ts @@ -50,6 +50,7 @@ describe('listAlertTypes', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'alertingAlertType', name: 'alertingAlertType', producer: 'alerts', @@ -58,6 +59,7 @@ describe('listAlertTypes', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myAppAlertType', name: 'myAppAlertType', producer: 'myApp', @@ -96,6 +98,7 @@ describe('listAlertTypes', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myType', name: 'myType', producer: 'myApp', @@ -105,6 +108,7 @@ describe('listAlertTypes', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', }, ]); @@ -119,6 +123,7 @@ describe('listAlertTypes', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', producer: 'alerts', authorizedConsumers: { myApp: { read: true, all: true }, diff --git a/x-pack/plugins/alerts/server/alerts_client/tests/update.test.ts b/x-pack/plugins/alerts/server/alerts_client/tests/update.test.ts index 046d7ec63c048..73ed3a879ec36 100644 --- a/x-pack/plugins/alerts/server/alerts_client/tests/update.test.ts +++ b/x-pack/plugins/alerts/server/alerts_client/tests/update.test.ts @@ -97,6 +97,7 @@ describe('update()', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', }); @@ -676,6 +677,7 @@ describe('update()', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', validate: { params: schema.object({ param1: schema.string(), @@ -1021,6 +1023,7 @@ describe('update()', () => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', }); diff --git a/x-pack/plugins/alerts/server/alerts_client_conflict_retries.test.ts b/x-pack/plugins/alerts/server/alerts_client_conflict_retries.test.ts index ca9389ece310c..0fa2e6e08ed2a 100644 --- a/x-pack/plugins/alerts/server/alerts_client_conflict_retries.test.ts +++ b/x-pack/plugins/alerts/server/alerts_client_conflict_retries.test.ts @@ -331,6 +331,7 @@ beforeEach(() => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', })); @@ -340,6 +341,7 @@ beforeEach(() => { name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', }); diff --git a/x-pack/plugins/alerts/server/authorization/alerts_authorization.test.ts b/x-pack/plugins/alerts/server/authorization/alerts_authorization.test.ts index eb116b9e208dc..68ae7bc8d5f88 100644 --- a/x-pack/plugins/alerts/server/authorization/alerts_authorization.test.ts +++ b/x-pack/plugins/alerts/server/authorization/alerts_authorization.test.ts @@ -172,6 +172,7 @@ beforeEach(() => { name: 'My Alert Type', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'myApp', })); @@ -534,6 +535,7 @@ describe('AlertsAuthorization', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myOtherAppAlertType', name: 'myOtherAppAlertType', producer: 'alerts', @@ -542,6 +544,7 @@ describe('AlertsAuthorization', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myAppAlertType', name: 'myAppAlertType', producer: 'myApp', @@ -550,6 +553,7 @@ describe('AlertsAuthorization', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'mySecondAppAlertType', name: 'mySecondAppAlertType', producer: 'myApp', @@ -824,6 +828,7 @@ describe('AlertsAuthorization', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myOtherAppAlertType', name: 'myOtherAppAlertType', producer: 'myOtherApp', @@ -832,6 +837,7 @@ describe('AlertsAuthorization', () => { actionGroups: [], actionVariables: undefined, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myAppAlertType', name: 'myAppAlertType', producer: 'myApp', diff --git a/x-pack/plugins/alerts/server/authorization/alerts_authorization_kuery.test.ts b/x-pack/plugins/alerts/server/authorization/alerts_authorization_kuery.test.ts index e4b9f8c54c38d..5113f0dd11d6a 100644 --- a/x-pack/plugins/alerts/server/authorization/alerts_authorization_kuery.test.ts +++ b/x-pack/plugins/alerts/server/authorization/alerts_authorization_kuery.test.ts @@ -20,6 +20,7 @@ describe('asFiltersByAlertTypeAndConsumer', () => { id: 'myAppAlertType', name: 'myAppAlertType', producer: 'myApp', + minimumLicenseRequired: 'basic', authorizedConsumers: { myApp: { read: true, all: true }, }, @@ -40,6 +41,7 @@ describe('asFiltersByAlertTypeAndConsumer', () => { { actionGroups: [], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myAppAlertType', name: 'myAppAlertType', producer: 'myApp', @@ -65,6 +67,7 @@ describe('asFiltersByAlertTypeAndConsumer', () => { { actionGroups: [], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myAppAlertType', name: 'myAppAlertType', producer: 'myApp', @@ -78,6 +81,7 @@ describe('asFiltersByAlertTypeAndConsumer', () => { { actionGroups: [], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'myOtherAppAlertType', name: 'myOtherAppAlertType', producer: 'alerts', @@ -91,6 +95,7 @@ describe('asFiltersByAlertTypeAndConsumer', () => { { actionGroups: [], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', id: 'mySecondAppAlertType', name: 'mySecondAppAlertType', producer: 'myApp', diff --git a/x-pack/plugins/alerts/server/lib/validate_alert_type_params.test.ts b/x-pack/plugins/alerts/server/lib/validate_alert_type_params.test.ts index 1e6c26c02e65b..2814eaef3e02a 100644 --- a/x-pack/plugins/alerts/server/lib/validate_alert_type_params.test.ts +++ b/x-pack/plugins/alerts/server/lib/validate_alert_type_params.test.ts @@ -19,6 +19,7 @@ test('should return passed in params when validation not defined', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', }, @@ -41,6 +42,7 @@ test('should validate and apply defaults when params is valid', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', validate: { params: schema.object({ param1: schema.string(), @@ -71,6 +73,7 @@ test('should validate and throw error when params is invalid', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', validate: { params: schema.object({ param1: schema.string(), diff --git a/x-pack/plugins/alerts/server/plugin.test.ts b/x-pack/plugins/alerts/server/plugin.test.ts index fee7901c4ea55..6706be75e92bf 100644 --- a/x-pack/plugins/alerts/server/plugin.test.ts +++ b/x-pack/plugins/alerts/server/plugin.test.ts @@ -4,7 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { AlertingPlugin, AlertingPluginsSetup, AlertingPluginsStart } from './plugin'; +import { + AlertingPlugin, + AlertingPluginsSetup, + AlertingPluginsStart, + PluginSetupContract, +} from './plugin'; import { coreMock, statusServiceMock } from '../../../../src/core/server/mocks'; import { licensingMock } from '../../licensing/server/mocks'; import { encryptedSavedObjectsMock } from '../../encrypted_saved_objects/server/mocks'; @@ -14,9 +19,16 @@ import { KibanaRequest, CoreSetup } from 'kibana/server'; import { featuresPluginMock } from '../../features/server/mocks'; import { KibanaFeature } from '../../features/server'; import { AlertsConfig } from './config'; +import { AlertType } from './types'; +import { eventLogMock } from '../../event_log/server/mocks'; +import { actionsMock } from '../../actions/server/mocks'; describe('Alerting Plugin', () => { describe('setup()', () => { + let plugin: AlertingPlugin; + let coreSetup: ReturnType; + let pluginsSetup: jest.Mocked; + it('should log warning when Encrypted Saved Objects plugin is using an ephemeral encryption key', async () => { const context = coreMock.createPluginInitializerContext({ healthCheck: { @@ -27,9 +39,9 @@ describe('Alerting Plugin', () => { removalDelay: '5m', }, }); - const plugin = new AlertingPlugin(context); + plugin = new AlertingPlugin(context); - const coreSetup = coreMock.createSetup(); + coreSetup = coreMock.createSetup(); const encryptedSavedObjectsSetup = encryptedSavedObjectsMock.createSetup(); const statusMock = statusServiceMock.createSetupContract(); await plugin.setup( @@ -55,6 +67,56 @@ describe('Alerting Plugin', () => { 'APIs are disabled because the Encrypted Saved Objects plugin uses an ephemeral encryption key. Please set xpack.encryptedSavedObjects.encryptionKey in the kibana.yml or use the bin/kibana-encryption-keys command.' ); }); + + describe('registerType()', () => { + let setup: PluginSetupContract; + const sampleAlertType: AlertType = { + id: 'test', + name: 'test', + minimumLicenseRequired: 'basic', + actionGroups: [], + defaultActionGroupId: 'default', + producer: 'test', + async executor() {}, + }; + + beforeEach(async () => { + setup = await plugin.setup(coreSetup, pluginsSetup); + coreSetup = coreMock.createSetup(); + pluginsSetup = { + taskManager: taskManagerMock.createSetup(), + encryptedSavedObjects: encryptedSavedObjectsMock.createSetup(), + licensing: licensingMock.createSetup(), + eventLog: eventLogMock.createSetup(), + actions: actionsMock.createSetup(), + statusService: statusServiceMock.createSetupContract(), + }; + }); + + it('should throw error when license type is invalid', async () => { + expect(() => + setup.registerType({ + ...sampleAlertType, + // eslint-disable-next-line @typescript-eslint/no-explicit-any + minimumLicenseRequired: 'foo' as any, + }) + ).toThrowErrorMatchingInlineSnapshot(`"\\"foo\\" is not a valid license type"`); + }); + + it('should not throw when license type is gold', async () => { + setup.registerType({ + ...sampleAlertType, + minimumLicenseRequired: 'gold', + }); + }); + + it('should not throw when license type is basic', async () => { + setup.registerType({ + ...sampleAlertType, + minimumLicenseRequired: 'basic', + }); + }); + }); }); describe('start()', () => { diff --git a/x-pack/plugins/alerts/server/plugin.ts b/x-pack/plugins/alerts/server/plugin.ts index bafb89c64076b..e4ddf44b8808c 100644 --- a/x-pack/plugins/alerts/server/plugin.ts +++ b/x-pack/plugins/alerts/server/plugin.ts @@ -54,12 +54,12 @@ import { unmuteAlertInstanceRoute, healthRoute, } from './routes'; -import { LicensingPluginSetup } from '../../licensing/server'; +import { LICENSE_TYPE, LicensingPluginSetup } from '../../licensing/server'; import { PluginSetupContract as ActionsPluginSetupContract, PluginStartContract as ActionsPluginStartContract, } from '../../actions/server'; -import { AlertsHealth, Services } from './types'; +import { AlertsHealth, AlertType, Services } from './types'; import { registerAlertsUsageCollector } from './usage'; import { initializeAlertingTelemetry, scheduleAlertingTelemetry } from './usage/task'; import { IEventLogger, IEventLogService, IEventLogClientService } from '../../event_log/server'; @@ -90,7 +90,7 @@ export const LEGACY_EVENT_LOG_ACTIONS = { }; export interface PluginSetupContract { - registerType: AlertTypeRegistry['register']; + registerType: (alertType: AlertType) => void; } export interface PluginStartContract { listTypes: AlertTypeRegistry['list']; @@ -250,7 +250,12 @@ export class AlertingPlugin { healthRoute(router, this.licenseState, plugins.encryptedSavedObjects); return { - registerType: alertTypeRegistry.register.bind(alertTypeRegistry), + registerType: (alertType: AlertType) => { + if (!(alertType.minimumLicenseRequired in LICENSE_TYPE)) { + throw new Error(`"${alertType.minimumLicenseRequired}" is not a valid license type`); + } + alertTypeRegistry.register(alertType); + }, }; } diff --git a/x-pack/plugins/alerts/server/routes/list_alert_types.test.ts b/x-pack/plugins/alerts/server/routes/list_alert_types.test.ts index af20dd6e202ba..be1fad5403556 100644 --- a/x-pack/plugins/alerts/server/routes/list_alert_types.test.ts +++ b/x-pack/plugins/alerts/server/routes/list_alert_types.test.ts @@ -43,6 +43,7 @@ describe('listAlertTypesRoute', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', authorizedConsumers: {}, actionVariables: { context: [], @@ -107,6 +108,7 @@ describe('listAlertTypesRoute', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', authorizedConsumers: {}, actionVariables: { context: [], @@ -156,6 +158,7 @@ describe('listAlertTypesRoute', () => { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', authorizedConsumers: {}, actionVariables: { context: [], diff --git a/x-pack/plugins/alerts/server/task_runner/create_execution_handler.test.ts b/x-pack/plugins/alerts/server/task_runner/create_execution_handler.test.ts index ed73fec24db26..f97c71750047c 100644 --- a/x-pack/plugins/alerts/server/task_runner/create_execution_handler.test.ts +++ b/x-pack/plugins/alerts/server/task_runner/create_execution_handler.test.ts @@ -20,6 +20,7 @@ const alertType: AlertType = { { id: 'other-group', name: 'Other Group' }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }; diff --git a/x-pack/plugins/alerts/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerts/server/task_runner/task_runner.test.ts index d4c4f746392c3..2e286a7dfa529 100644 --- a/x-pack/plugins/alerts/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerts/server/task_runner/task_runner.test.ts @@ -33,6 +33,7 @@ const alertType = { name: 'My test alert', actionGroups: [{ id: 'default', name: 'Default' }, RecoveredActionGroup], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }; diff --git a/x-pack/plugins/alerts/server/task_runner/task_runner_factory.test.ts b/x-pack/plugins/alerts/server/task_runner/task_runner_factory.test.ts index 1c10a997d8cdd..e622f1d5d2cbc 100644 --- a/x-pack/plugins/alerts/server/task_runner/task_runner_factory.test.ts +++ b/x-pack/plugins/alerts/server/task_runner/task_runner_factory.test.ts @@ -22,6 +22,7 @@ const alertType = { name: 'My test alert', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: jest.fn(), producer: 'alerts', }; diff --git a/x-pack/plugins/alerts/server/types.ts b/x-pack/plugins/alerts/server/types.ts index 500c681a1d2b9..57498be36f7f1 100644 --- a/x-pack/plugins/alerts/server/types.ts +++ b/x-pack/plugins/alerts/server/types.ts @@ -29,6 +29,7 @@ import { AlertExecutionStatusErrorReasons, AlertsHealth, } from '../common'; +import { LicenseType } from '../../licensing/server'; export type WithoutQueryAndParams = Pick>; export type GetServicesFunction = (request: KibanaRequest) => Services; @@ -107,6 +108,7 @@ export interface AlertType< state?: ActionVariable[]; params?: ActionVariable[]; }; + minimumLicenseRequired: LicenseType; } export interface RawAlertAction extends SavedObjectAttributes { diff --git a/x-pack/plugins/apm/common/alert_types.ts b/x-pack/plugins/apm/common/alert_types.ts index a234226d18034..7cc36253ef581 100644 --- a/x-pack/plugins/apm/common/alert_types.ts +++ b/x-pack/plugins/apm/common/alert_types.ts @@ -29,6 +29,7 @@ export const ALERT_TYPES_CONFIG = { }), actionGroups: [THRESHOLD_MET_GROUP], defaultActionGroupId: 'threshold_met', + minimumLicenseRequired: 'basic', producer: 'apm', }, [AlertType.TransactionDuration]: { @@ -37,6 +38,7 @@ export const ALERT_TYPES_CONFIG = { }), actionGroups: [THRESHOLD_MET_GROUP], defaultActionGroupId: 'threshold_met', + minimumLicenseRequired: 'basic', producer: 'apm', }, [AlertType.TransactionDurationAnomaly]: { @@ -45,6 +47,7 @@ export const ALERT_TYPES_CONFIG = { }), actionGroups: [THRESHOLD_MET_GROUP], defaultActionGroupId: 'threshold_met', + minimumLicenseRequired: 'basic', producer: 'apm', }, [AlertType.TransactionErrorRate]: { @@ -53,6 +56,7 @@ export const ALERT_TYPES_CONFIG = { }), actionGroups: [THRESHOLD_MET_GROUP], defaultActionGroupId: 'threshold_met', + minimumLicenseRequired: 'basic', producer: 'apm', }, }; diff --git a/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts index 464a737c50ea2..2b33f8a35d50e 100644 --- a/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts +++ b/x-pack/plugins/apm/server/lib/alerts/register_error_count_alert_type.ts @@ -59,6 +59,7 @@ export function registerErrorCountAlertType({ ], }, producer: 'apm', + minimumLicenseRequired: 'basic', executor: async ({ services, params }) => { const config = await config$.pipe(take(1)).toPromise(); const alertParams = params; diff --git a/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts index 602ee99970f8a..ac51a151bb207 100644 --- a/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts +++ b/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_alert_type.ts @@ -68,6 +68,7 @@ export function registerTransactionDurationAlertType({ ], }, producer: 'apm', + minimumLicenseRequired: 'basic', executor: async ({ services, params }) => { const config = await config$.pipe(take(1)).toPromise(); const alertParams = params; diff --git a/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_anomaly_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_anomaly_alert_type.ts index b9e970ace869d..f3df0092dbbbd 100644 --- a/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_anomaly_alert_type.ts +++ b/x-pack/plugins/apm/server/lib/alerts/register_transaction_duration_anomaly_alert_type.ts @@ -67,6 +67,7 @@ export function registerTransactionDurationAnomalyAlertType({ ], }, producer: 'apm', + minimumLicenseRequired: 'basic', executor: async ({ services, params, state }) => { if (!ml) { return; diff --git a/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts b/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts index 0506e1b4c3aed..96ab854e5ea39 100644 --- a/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts +++ b/x-pack/plugins/apm/server/lib/alerts/register_transaction_error_rate_alert_type.ts @@ -65,6 +65,7 @@ export function registerTransactionErrorRateAlertType({ ], }, producer: 'apm', + minimumLicenseRequired: 'basic', executor: async ({ services, params: alertParams }) => { const config = await config$.pipe(take(1)).toPromise(); const indices = await getApmIndices({ diff --git a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_alert_type.ts b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_alert_type.ts index 14d1acf0e4a9f..6ec6210ecb344 100644 --- a/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_alert_type.ts +++ b/x-pack/plugins/infra/server/lib/alerting/inventory_metric_threshold/register_inventory_metric_threshold_alert_type.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { schema } from '@kbn/config-schema'; +import { AlertType } from '../../../../../alerts/server'; import { createInventoryMetricThresholdExecutor, FIRED_ACTIONS, @@ -38,7 +39,7 @@ const condition = schema.object({ ), }); -export const registerMetricInventoryThresholdAlertType = (libs: InfraBackendLibs) => ({ +export const registerMetricInventoryThresholdAlertType = (libs: InfraBackendLibs): AlertType => ({ id: METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, name: 'Inventory', validate: { @@ -58,6 +59,7 @@ export const registerMetricInventoryThresholdAlertType = (libs: InfraBackendLibs defaultActionGroupId: FIRED_ACTIONS.id, actionGroups: [FIRED_ACTIONS], producer: 'infrastructure', + minimumLicenseRequired: 'basic', executor: createInventoryMetricThresholdExecutor(libs), actionVariables: { context: [ diff --git a/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts b/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts index 34afddc2a4d48..64bfad92a8458 100644 --- a/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts +++ b/x-pack/plugins/infra/server/lib/alerting/log_threshold/register_log_threshold_alert_type.ts @@ -89,6 +89,7 @@ export async function registerLogThresholdAlertType( }, defaultActionGroupId: FIRED_ACTIONS.id, actionGroups: [FIRED_ACTIONS], + minimumLicenseRequired: 'basic', executor: createLogThresholdExecutor(libs), actionVariables: { context: [ diff --git a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts index 45b1df2f03ea1..1a10765eaf734 100644 --- a/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts +++ b/x-pack/plugins/infra/server/lib/alerting/metric_threshold/register_metric_threshold_alert_type.ts @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { schema } from '@kbn/config-schema'; +import { AlertType } from '../../../../../alerts/server'; import { METRIC_EXPLORER_AGGREGATIONS } from '../../../../common/http_api/metrics_explorer'; import { createMetricThresholdExecutor, FIRED_ACTIONS } from './metric_threshold_executor'; import { METRIC_THRESHOLD_ALERT_TYPE_ID, Comparator } from './types'; @@ -19,7 +20,7 @@ import { thresholdActionVariableDescription, } from '../common/messages'; -export function registerMetricThresholdAlertType(libs: InfraBackendLibs) { +export function registerMetricThresholdAlertType(libs: InfraBackendLibs): AlertType { const baseCriterion = { threshold: schema.arrayOf(schema.number()), comparator: oneOfLiterals(Object.values(Comparator)), @@ -60,6 +61,7 @@ export function registerMetricThresholdAlertType(libs: InfraBackendLibs) { }, defaultActionGroupId: FIRED_ACTIONS.id, actionGroups: [FIRED_ACTIONS], + minimumLicenseRequired: 'basic', executor: createMetricThresholdExecutor(libs), actionVariables: { context: [ diff --git a/x-pack/plugins/monitoring/server/alerts/base_alert.ts b/x-pack/plugins/monitoring/server/alerts/base_alert.ts index 4c1a4d8df2ab5..255a3a19d38a8 100644 --- a/x-pack/plugins/monitoring/server/alerts/base_alert.ts +++ b/x-pack/plugins/monitoring/server/alerts/base_alert.ts @@ -113,6 +113,7 @@ export class BaseAlert { }, ], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', executor: (options: AlertExecutorOptions): Promise => this.execute(options), producer: 'monitoring', actionVariables: { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts index 802b9472a4487..088cc417cf28e 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/notifications/rules_notification_alert_type.ts @@ -31,6 +31,7 @@ export const rulesNotificationAlertType = ({ ruleAlertId: schema.string(), }), }, + minimumLicenseRequired: 'basic', async executor({ startedAt, previousStartedAt, alertId, services, params }) { const ruleAlertSavedObject = await services.savedObjectsClient.get( 'alert', diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts index d6bdc14a92b40..91c5a8c3ecf6c 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts @@ -90,6 +90,7 @@ export const signalRulesAlertType = ({ params: signalParamsSchema(), }, producer: SERVER_APP_ID, + minimumLicenseRequired: 'basic', async executor({ previousStartedAt, startedAt, diff --git a/x-pack/plugins/stack_alerts/server/alert_types/geo_threshold/alert_type.ts b/x-pack/plugins/stack_alerts/server/alert_types/geo_threshold/alert_type.ts index 0c40f5b5f3866..f485f53e2be62 100644 --- a/x-pack/plugins/stack_alerts/server/alert_types/geo_threshold/alert_type.ts +++ b/x-pack/plugins/stack_alerts/server/alert_types/geo_threshold/alert_type.ts @@ -7,6 +7,7 @@ import { i18n } from '@kbn/i18n'; import { schema } from '@kbn/config-schema'; import { Logger } from 'src/core/server'; +import { LicenseType } from '../../../../licensing/server'; import { STACK_ALERTS_FEATURE_ID } from '../../../common'; import { getGeoThresholdExecutor } from './geo_threshold'; import { @@ -182,6 +183,7 @@ export function getAlertType( ): { defaultActionGroupId: string; actionGroups: ActionGroup[]; + minimumLicenseRequired: LicenseType; executor: ({ previousStartedAt: currIntervalStartTime, startedAt: currIntervalEndTime, @@ -233,5 +235,6 @@ export function getAlertType( params: ParamsSchema, }, actionVariables, + minimumLicenseRequired: 'gold', }; } diff --git a/x-pack/plugins/stack_alerts/server/alert_types/index_threshold/alert_type.ts b/x-pack/plugins/stack_alerts/server/alert_types/index_threshold/alert_type.ts index 9de0940771525..9600395c78218 100644 --- a/x-pack/plugins/stack_alerts/server/alert_types/index_threshold/alert_type.ts +++ b/x-pack/plugins/stack_alerts/server/alert_types/index_threshold/alert_type.ts @@ -143,6 +143,7 @@ export function getAlertType( ...alertParamsVariables, ], }, + minimumLicenseRequired: 'basic', executor, producer: STACK_ALERTS_FEATURE_ID, }; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx index 2f7a31721fa07..040c1e0cc85d6 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx @@ -16,6 +16,7 @@ import { } from '../../../../../../alerts/common'; import { useKibana } from '../../../../common/lib/kibana'; import { alertTypeRegistryMock } from '../../../alert_type_registry.mock'; +import { LicenseType } from '../../../../../../licensing/public'; jest.mock('../../../../common/lib/kibana'); @@ -60,6 +61,7 @@ describe('alert_details', () => { actionGroups: [{ id: 'default', name: 'Default' }], actionVariables: { context: [], state: [], params: [] }, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, producer: ALERTS_FEATURE_ID, authorizedConsumers, }; @@ -85,6 +87,7 @@ describe('alert_details', () => { actionGroups: [{ id: 'default', name: 'Default' }], actionVariables: { context: [], state: [], params: [] }, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, producer: ALERTS_FEATURE_ID, authorizedConsumers, }; @@ -113,6 +116,7 @@ describe('alert_details', () => { actionGroups: [{ id: 'default', name: 'Default' }], actionVariables: { context: [], state: [], params: [] }, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, producer: ALERTS_FEATURE_ID, authorizedConsumers, }; @@ -147,6 +151,7 @@ describe('alert_details', () => { actionGroups: [{ id: 'default', name: 'Default' }], actionVariables: { context: [], state: [], params: [] }, defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, producer: ALERTS_FEATURE_ID, authorizedConsumers, }; @@ -202,6 +207,7 @@ describe('alert_details', () => { actionVariables: { context: [], state: [], params: [] }, defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, + minimumLicenseRequired: 'basic' as LicenseType, authorizedConsumers, }; const actionTypes: ActionType[] = [ @@ -262,6 +268,7 @@ describe('alert_details', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; expect( @@ -282,6 +289,7 @@ describe('alert_details', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; expect( @@ -311,6 +319,7 @@ describe('disable button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const enableButton = shallow( @@ -339,6 +348,7 @@ describe('disable button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const enableButton = shallow( @@ -367,6 +377,7 @@ describe('disable button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const disableAlert = jest.fn(); @@ -404,6 +415,7 @@ describe('disable button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const enableAlert = jest.fn(); @@ -444,6 +456,7 @@ describe('mute button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const enableButton = shallow( @@ -473,6 +486,7 @@ describe('mute button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const enableButton = shallow( @@ -502,6 +516,7 @@ describe('mute button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const muteAlert = jest.fn(); @@ -540,6 +555,7 @@ describe('mute button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const unmuteAlert = jest.fn(); @@ -578,6 +594,7 @@ describe('mute button', () => { defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; const enableButton = shallow( @@ -643,6 +660,7 @@ describe('edit button', () => { defaultActionGroupId: 'default', producer: 'alerting', authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; expect( @@ -685,6 +703,7 @@ describe('edit button', () => { defaultActionGroupId: 'default', producer: 'alerting', authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; expect( @@ -720,6 +739,7 @@ describe('edit button', () => { defaultActionGroupId: 'default', producer: 'alerting', authorizedConsumers, + minimumLicenseRequired: 'basic' as LicenseType, }; expect( diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.test.tsx index 52a85e8bc57bd..18858f12483db 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.test.tsx @@ -309,6 +309,7 @@ function mockAlertType(overloads: Partial = {}): AlertType { defaultActionGroupId: 'default', authorizedConsumers: {}, producer: 'alerts', + minimumLicenseRequired: 'basic', ...overloads, }; } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.test.tsx index 2256efe30831b..14ad638546f3e 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.test.tsx @@ -149,6 +149,7 @@ function mockAlertType(overloads: Partial = {}): AlertType { defaultActionGroupId: 'default', authorizedConsumers: {}, producer: 'alerts', + minimumLicenseRequired: 'basic', ...overloads, }; } diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx index 084da8905663e..9980f0256d7be 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_add.test.tsx @@ -61,6 +61,7 @@ describe('alert_add', () => { }, ], defaultActionGroupId: 'testActionGroup', + minimumLicenseRequired: 'basic', producer: ALERTS_FEATURE_ID, authorizedConsumers: { [ALERTS_FEATURE_ID]: { read: true, all: true }, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx index 6b5f0a31d345c..a0625f0cbcf47 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_form/alert_form.test.tsx @@ -85,6 +85,7 @@ describe('alert_form', () => { }, ], defaultActionGroupId: 'testActionGroup', + minimumLicenseRequired: 'basic', producer: ALERTS_FEATURE_ID, authorizedConsumers: { [ALERTS_FEATURE_ID]: { read: true, all: true }, @@ -218,6 +219,7 @@ describe('alert_form', () => { }, ], defaultActionGroupId: 'testActionGroup', + minimumLicenseRequired: 'basic', producer: ALERTS_FEATURE_ID, authorizedConsumers: { [ALERTS_FEATURE_ID]: { read: true, all: true }, @@ -234,6 +236,7 @@ describe('alert_form', () => { }, ], defaultActionGroupId: 'testActionGroup', + minimumLicenseRequired: 'basic', producer: 'test', authorizedConsumers: { [ALERTS_FEATURE_ID]: { read: true, all: true }, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx index 351eccf2934be..cb187655c77a2 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alerts_list/components/alerts_list.test.tsx @@ -59,6 +59,7 @@ const alertTypeFromApi = { actionVariables: { context: [], state: [] }, defaultActionGroupId: 'default', producer: ALERTS_FEATURE_ID, + minimumLicenseRequired: 'basic', authorizedConsumers: { [ALERTS_FEATURE_ID]: { read: true, all: true }, }, diff --git a/x-pack/plugins/triggers_actions_ui/public/types.ts b/x-pack/plugins/triggers_actions_ui/public/types.ts index a4eac1ab1da21..f488f2eb6ed59 100644 --- a/x-pack/plugins/triggers_actions_ui/public/types.ts +++ b/x-pack/plugins/triggers_actions_ui/public/types.ts @@ -9,6 +9,7 @@ import { ComponentType } from 'react'; import { ActionGroup, AlertActionParam } from '../../alerts/common'; import { ActionType } from '../../actions/common'; import { TypeRegistry } from './application/type_registry'; +import { AlertType as AlertTypeApi } from '../../alerts/common'; import { SanitizedAlert as Alert, AlertAction, @@ -133,14 +134,9 @@ export interface ActionVariables { params: ActionVariable[]; } -export interface AlertType { - id: string; - name: string; - actionGroups: ActionGroup[]; +export interface AlertType extends Omit { actionVariables: ActionVariables; - defaultActionGroupId: ActionGroup['id']; authorizedConsumers: Record; - producer: string; } export type SanitizedAlertType = Omit; diff --git a/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts b/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts index 022ec48bad1d9..f5e79ad43336b 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/duration_anomaly.ts @@ -82,6 +82,7 @@ export const durationAnomalyAlertFactory: UptimeAlertTypeFactory = (_server, _li context: [], state: [...durationAnomalyTranslations.actionVariables, ...commonStateTranslations], }, + minimumLicenseRequired: 'basic', async executor({ options, uptimeEsClient, savedObjectsClient, dynamicSettings }) { const { services: { alertInstanceFactory }, diff --git a/x-pack/plugins/uptime/server/lib/alerts/status_check.ts b/x-pack/plugins/uptime/server/lib/alerts/status_check.ts index 3e45ce302bf87..56ca7a85784c5 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/status_check.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/status_check.ts @@ -255,6 +255,7 @@ export const statusCheckAlertFactory: UptimeAlertTypeFactory = (_server, libs) = ], state: [...commonMonitorStateI18, ...commonStateTranslations], }, + minimumLicenseRequired: 'basic', async executor({ options: { params: rawParams, diff --git a/x-pack/plugins/uptime/server/lib/alerts/tls.ts b/x-pack/plugins/uptime/server/lib/alerts/tls.ts index 41a5101716122..b6501f7d92059 100644 --- a/x-pack/plugins/uptime/server/lib/alerts/tls.ts +++ b/x-pack/plugins/uptime/server/lib/alerts/tls.ts @@ -100,6 +100,7 @@ export const tlsAlertFactory: UptimeAlertTypeFactory = (_server, libs) => context: [], state: [...tlsTranslations.actionVariables, ...commonStateTranslations], }, + minimumLicenseRequired: 'basic', async executor({ options, dynamicSettings, uptimeEsClient }) { const { services: { alertInstanceFactory }, diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts index 998ec6ab2ed0e..ff28aea660036 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts @@ -7,6 +7,7 @@ import { CoreSetup } from 'src/core/server'; import { schema, TypeOf } from '@kbn/config-schema'; import { times } from 'lodash'; +import { LicenseType } from '../../../../../../../plugins/licensing/public'; import { ES_TEST_INDEX_NAME } from '../../../../lib'; import { FixtureStartDeps, FixtureSetupDeps } from './plugin'; import { @@ -43,6 +44,7 @@ function getAlwaysFiringAlertType() { }, producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic' as LicenseType, actionVariables: { state: [{ name: 'instanceStateValue', description: 'the instance state value' }], params: [{ name: 'instanceParamsValue', description: 'the instance params value' }], @@ -113,6 +115,7 @@ function getCumulativeFiringAlertType() { ], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor(alertExecutorOptions) { const { services, state } = alertExecutorOptions; const group = 'default'; @@ -157,6 +160,7 @@ function getNeverFiringAlertType() { }, producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor({ services, params, state }) { await services.callCluster('index', { index: params.index, @@ -196,6 +200,7 @@ function getFailingAlertType() { ], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor({ services, params, state }) { await services.callCluster('index', { index: params.index, @@ -234,6 +239,7 @@ function getAuthorizationAlertType(core: CoreSetup) { ], defaultActionGroupId: 'default', producer: 'alertsFixture', + minimumLicenseRequired: 'basic', validate: { params: paramsSchema, }, @@ -319,6 +325,7 @@ function getValidationAlertType() { }, ], producer: 'alertsFixture', + minimumLicenseRequired: 'basic', defaultActionGroupId: 'default', validate: { params: paramsSchema, @@ -343,6 +350,7 @@ function getPatternFiringAlertType() { actionGroups: [{ id: 'default', name: 'Default' }], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor(alertExecutorOptions) { const { services, state, params } = alertExecutorOptions; const pattern = params.pattern; @@ -398,6 +406,7 @@ export function defineAlertTypes( actionGroups: [{ id: 'default', name: 'Default' }], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, }; const onlyContextVariablesAlertType: AlertType = { @@ -406,6 +415,7 @@ export function defineAlertTypes( actionGroups: [{ id: 'default', name: 'Default' }], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', actionVariables: { context: [{ name: 'aContextVariable', description: 'this is a context variable' }], }, @@ -420,6 +430,7 @@ export function defineAlertTypes( actionVariables: { state: [{ name: 'aStateVariable', description: 'this is a state variable' }], }, + minimumLicenseRequired: 'basic', async executor() {}, }; const throwAlertType: AlertType = { @@ -433,6 +444,7 @@ export function defineAlertTypes( ], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() { throw new Error('this alert is intended to fail'); }, @@ -448,6 +460,7 @@ export function defineAlertTypes( ], producer: 'alertsFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() { await new Promise((resolve) => setTimeout(resolve, 5000)); }, diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts_restricted/server/alert_types.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts_restricted/server/alert_types.ts index 00d06c30aa910..976efa9c62102 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts_restricted/server/alert_types.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts_restricted/server/alert_types.ts @@ -18,6 +18,7 @@ export function defineAlertTypes( actionGroups: [{ id: 'default', name: 'Default' }], producer: 'alertsRestrictedFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor({ services, params, state }: AlertExecutorOptions) {}, }; const noopUnrestrictedAlertType: AlertType = { @@ -26,6 +27,7 @@ export function defineAlertTypes( actionGroups: [{ id: 'default', name: 'Default' }], producer: 'alertsRestrictedFixture', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor({ services, params, state }: AlertExecutorOptions) {}, }; alerts.registerType(noopRestrictedAlertType); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts index bfaf8a2a4788e..2a1d1baaf230c 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts @@ -28,6 +28,7 @@ export default function listAlertTypes({ getService }: FtrProviderContext) { params: [], }, producer: 'alertsFixture', + minimumLicenseRequired: 'basic', }; const expectedRestrictedNoOpType = { @@ -44,6 +45,7 @@ export default function listAlertTypes({ getService }: FtrProviderContext) { params: [], }, producer: 'alertsRestrictedFixture', + minimumLicenseRequired: 'basic', }; describe('list_alert_types', () => { diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts index 9d38f4abb7f3f..a9ea8a82c6493 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts @@ -36,6 +36,7 @@ export default function listAlertTypes({ getService }: FtrProviderContext) { context: [], }, producer: 'alertsFixture', + minimumLicenseRequired: 'basic', }); expect(Object.keys(authorizedConsumers)).to.contain('alertsFixture'); }); diff --git a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts index 6584c5891a8b9..f6cbc52e7a421 100644 --- a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts +++ b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/server/plugin.ts @@ -22,11 +22,12 @@ export const noopAlertType: AlertType = { name: 'Test: Noop', actionGroups: [{ id: 'default', name: 'Default' }], defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() {}, producer: 'alerts', }; -export const alwaysFiringAlertType: any = { +export const alwaysFiringAlertType: AlertType = { id: 'test.always-firing', name: 'Always Firing', actionGroups: [ @@ -35,6 +36,7 @@ export const alwaysFiringAlertType: any = { ], defaultActionGroupId: 'default', producer: 'alerts', + minimumLicenseRequired: 'basic', async executor(alertExecutorOptions: any) { const { services, state, params } = alertExecutorOptions; @@ -52,7 +54,7 @@ export const alwaysFiringAlertType: any = { }, }; -export const failingAlertType: any = { +export const failingAlertType: AlertType = { id: 'test.failing', name: 'Test: Failing', actionGroups: [ @@ -63,6 +65,7 @@ export const failingAlertType: any = { ], producer: 'alerts', defaultActionGroupId: 'default', + minimumLicenseRequired: 'basic', async executor() { throw new Error('Failed to execute alert type'); },