import { Plugin , CoreSetup } from 'kibana/server' ; import { PluginSetupContract as AlertingSetup , RuleType , } from '../../../../../../plugins/alerting/server' ; import { PluginSetupContract as FeaturesPluginSetup } from '../../../../../../plugins/features/server' ; export interface AlertingExampleDeps { alerting : AlertingSetup ; features : FeaturesPluginSetup ; } export const noopAlertType = { id : 'test.noop' , name : 'Test: Noop' , actionGroups : [ { id : 'default' , name : 'Default' } ] , defaultActionGroupId : 'default' , minimumLicenseRequired : 'basic' , isExportable : true , async executor ( ) { } , producer : 'alerts' , } ; export const alwaysFiringAlertType = { id : 'test.always-firing' , name : 'Always Firing' , actionGroups : [ { id : 'default' , name : 'Default' } , { id : 'other' , name : 'Other' } , ] , defaultActionGroupId : 'default' , producer : 'alerts' , minimumLicenseRequired : 'basic' , isExportable : true , async executor ( alertExecutorOptions ) { const { services , state , params } = alertExecutorOptions ; ( params . instances || [ ] ) . forEach ( ( instance ) => { services . alertInstanceFactory ( instance . id ) . replaceState ( { instanceStateValue : true , ... ( instance . state || { } ) } ) . scheduleActions ( 'default' ) ; } ) ; return { globalStateValue : true , groupInSeriesIndex : ( state . groupInSeriesIndex || 0 ) + 1 , } ; } , } ; export const failingAlertType = { id : 'test.failing' , name : 'Test: Failing' , actionGroups : [ { id : 'default' , name : 'Default' , } , ] , producer : 'alerts' , defaultActionGroupId : 'default' , minimumLicenseRequired : 'basic' , isExportable : true , async executor ( ) { throw new Error ( 'Failed to execute alert type' ) ; } , } ; export class AlertingFixturePlugin implements Plugin < void , void , AlertingExampleDeps > { public setup ( core , { alerting , features } ) { alerting . registerType ( noopAlertType ) ; alerting . registerType ( alwaysFiringAlertType ) ; alerting . registerType ( failingAlertType ) ; features . registerKibanaFeature ( { id : 'alerting_fixture' , name : 'alerting_fixture' , app : [ ] , category : { id : 'foo' , label : 'foo' } , alerting : [ 'test.always-firing' , 'test.noop' , 'test.failing' ] , privileges : { all : { alerting : { rule : { all : [ 'test.always-firing' , 'test.noop' , 'test.failing' ] , } , } , savedObject : { all : [ ] , read : [ ] , } , ui : [ ] , } , read : { alerting : { rule : { all : [ 'test.always-firing' , 'test.noop' , 'test.failing' ] , } , } , savedObject : { all : [ ] , read : [ ] , } , ui : [ ] , } , } , } ) ; } public start ( ) { } public stop ( ) { } }