@@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n';
99import { schema } from '@kbn/config-schema' ;
1010import typeDetect from 'type-detect' ;
1111import { intersection } from 'lodash' ;
12+ import { LicensingPluginSetup } from '../../licensing/server' ;
1213import { RunContext , TaskManagerSetupContract } from '../../task_manager/server' ;
1314import { TaskRunnerFactory } from './task_runner' ;
1415import {
@@ -19,10 +20,14 @@ import {
1920 AlertInstanceContext ,
2021} from './types' ;
2122import { RecoveredActionGroup , getBuiltinActionGroups } from '../common' ;
23+ import { ILicenseState } from './lib/license_state' ;
24+ import { getAlertTypeFeatureUsageName } from './lib/get_alert_type_feature_usage_name' ;
2225
23- interface ConstructorOptions {
26+ export interface ConstructorOptions {
2427 taskManager : TaskManagerSetupContract ;
2528 taskRunnerFactory : TaskRunnerFactory ;
29+ licenseState : ILicenseState ;
30+ licensing : LicensingPluginSetup ;
2631}
2732
2833export interface RegistryAlertType
@@ -34,8 +39,10 @@ export interface RegistryAlertType
3439 | 'defaultActionGroupId'
3540 | 'actionVariables'
3641 | 'producer'
42+ | 'minimumLicenseRequired'
3743 > {
3844 id : string ;
45+ enabledInLicense : boolean ;
3946}
4047
4148/**
@@ -70,16 +77,24 @@ export class AlertTypeRegistry {
7077 private readonly taskManager : TaskManagerSetupContract ;
7178 private readonly alertTypes : Map < string , NormalizedAlertType > = new Map ( ) ;
7279 private readonly taskRunnerFactory : TaskRunnerFactory ;
80+ private readonly licenseState : ILicenseState ;
81+ private readonly licensing : LicensingPluginSetup ;
7382
74- constructor ( { taskManager, taskRunnerFactory } : ConstructorOptions ) {
83+ constructor ( { taskManager, taskRunnerFactory, licenseState , licensing } : ConstructorOptions ) {
7584 this . taskManager = taskManager ;
7685 this . taskRunnerFactory = taskRunnerFactory ;
86+ this . licenseState = licenseState ;
87+ this . licensing = licensing ;
7788 }
7889
7990 public has ( id : string ) {
8091 return this . alertTypes . has ( id ) ;
8192 }
8293
94+ public ensureAlertTypeEnabled ( id : string ) {
95+ this . licenseState . ensureLicenseForAlertType ( this . get ( id ) ) ;
96+ }
97+
8398 public register <
8499 Params extends AlertTypeParams = AlertTypeParams ,
85100 State extends AlertTypeState = AlertTypeState ,
@@ -108,6 +123,13 @@ export class AlertTypeRegistry {
108123 this . taskRunnerFactory . create ( normalizedAlertType , context ) ,
109124 } ,
110125 } ) ;
126+ // No need to notify usage on basic alert types
127+ if ( alertType . minimumLicenseRequired !== 'basic' ) {
128+ this . licensing . featureUsage . register (
129+ getAlertTypeFeatureUsageName ( alertType . name ) ,
130+ alertType . minimumLicenseRequired
131+ ) ;
132+ }
111133 }
112134
113135 public get <
@@ -157,6 +179,11 @@ export class AlertTypeRegistry {
157179 actionVariables,
158180 producer,
159181 minimumLicenseRequired,
182+ enabledInLicense : ! ! this . licenseState . getLicenseCheckForAlertType (
183+ id ,
184+ name ,
185+ minimumLicenseRequired
186+ ) . isValid ,
160187 } )
161188 )
162189 ) ;
0 commit comments