@@ -17,11 +17,62 @@ export interface AlertingExampleDeps {
1717 features : FeaturesPluginSetup ;
1818}
1919
20+ export const noopAlertType : AlertType = {
21+ id : 'test.noop' ,
22+ name : 'Test: Noop' ,
23+ actionGroups : [ { id : 'default' , name : 'Default' } ] ,
24+ defaultActionGroupId : 'default' ,
25+ async executor ( ) { } ,
26+ producer : 'alerts' ,
27+ } ;
28+
29+ export const alwaysFiringAlertType : any = {
30+ id : 'test.always-firing' ,
31+ name : 'Always Firing' ,
32+ actionGroups : [
33+ { id : 'default' , name : 'Default' } ,
34+ { id : 'other' , name : 'Other' } ,
35+ ] ,
36+ defaultActionGroupId : 'default' ,
37+ producer : 'alerts' ,
38+ async executor ( alertExecutorOptions : any ) {
39+ const { services, state, params } = alertExecutorOptions ;
40+
41+ ( params . instances || [ ] ) . forEach ( ( instance : { id : string ; state : any } ) => {
42+ services
43+ . alertInstanceFactory ( instance . id )
44+ . replaceState ( { instanceStateValue : true , ...( instance . state || { } ) } )
45+ . scheduleActions ( 'default' ) ;
46+ } ) ;
47+
48+ return {
49+ globalStateValue : true ,
50+ groupInSeriesIndex : ( state . groupInSeriesIndex || 0 ) + 1 ,
51+ } ;
52+ } ,
53+ } ;
54+
55+ export const failingAlertType : any = {
56+ id : 'test.failing' ,
57+ name : 'Test: Failing' ,
58+ actionGroups : [
59+ {
60+ id : 'default' ,
61+ name : 'Default' ,
62+ } ,
63+ ] ,
64+ producer : 'alerts' ,
65+ defaultActionGroupId : 'default' ,
66+ async executor ( ) {
67+ throw new Error ( 'Failed to execute alert type' ) ;
68+ } ,
69+ } ;
70+
2071export class AlertingFixturePlugin implements Plugin < void , void , AlertingExampleDeps > {
2172 public setup ( core : CoreSetup , { alerts, features } : AlertingExampleDeps ) {
22- createNoopAlertType ( alerts ) ;
23- createAlwaysFiringAlertType ( alerts ) ;
24- createFailingAlertType ( alerts ) ;
73+ alerts . registerType ( noopAlertType ) ;
74+ alerts . registerType ( alwaysFiringAlertType ) ;
75+ alerts . registerType ( failingAlertType ) ;
2576 features . registerKibanaFeature ( {
2677 id : 'alerting_fixture' ,
2778 name : 'alerting_fixture' ,
@@ -56,64 +107,3 @@ export class AlertingFixturePlugin implements Plugin<void, void, AlertingExample
56107 public start ( ) { }
57108 public stop ( ) { }
58109}
59-
60- function createNoopAlertType ( alerts : AlertingSetup ) {
61- const noopAlertType : AlertType = {
62- id : 'test.noop' ,
63- name : 'Test: Noop' ,
64- actionGroups : [ { id : 'default' , name : 'Default' } ] ,
65- defaultActionGroupId : 'default' ,
66- async executor ( ) { } ,
67- producer : 'alerts' ,
68- } ;
69- alerts . registerType ( noopAlertType ) ;
70- }
71-
72- function createAlwaysFiringAlertType ( alerts : AlertingSetup ) {
73- // Alert types
74- const alwaysFiringAlertType : any = {
75- id : 'test.always-firing' ,
76- name : 'Always Firing' ,
77- actionGroups : [
78- { id : 'default' , name : 'Default' } ,
79- { id : 'other' , name : 'Other' } ,
80- ] ,
81- defaultActionGroupId : 'default' ,
82- producer : 'alerts' ,
83- async executor ( alertExecutorOptions : any ) {
84- const { services, state, params } = alertExecutorOptions ;
85-
86- ( params . instances || [ ] ) . forEach ( ( instance : { id : string ; state : any } ) => {
87- services
88- . alertInstanceFactory ( instance . id )
89- . replaceState ( { instanceStateValue : true , ...( instance . state || { } ) } )
90- . scheduleActions ( 'default' ) ;
91- } ) ;
92-
93- return {
94- globalStateValue : true ,
95- groupInSeriesIndex : ( state . groupInSeriesIndex || 0 ) + 1 ,
96- } ;
97- } ,
98- } ;
99- alerts . registerType ( alwaysFiringAlertType ) ;
100- }
101-
102- function createFailingAlertType ( alerts : AlertingSetup ) {
103- const failingAlertType : any = {
104- id : 'test.failing' ,
105- name : 'Test: Failing' ,
106- actionGroups : [
107- {
108- id : 'default' ,
109- name : 'Default' ,
110- } ,
111- ] ,
112- producer : 'alerts' ,
113- defaultActionGroupId : 'default' ,
114- async executor ( ) {
115- throw new Error ( 'Failed to execute alert type' ) ;
116- } ,
117- } ;
118- alerts . registerType ( failingAlertType ) ;
119- }
0 commit comments