1
- import { Construct , IResource , Lazy , Resource , Stack , Token } from '@aws-cdk/core' ;
2
- import { IAlarmAction } from './alarm-action ' ;
1
+ import { Construct , Lazy , Stack , Token } from '@aws-cdk/core' ;
2
+ import { AlarmBase , IAlarm } from './alarm-base ' ;
3
3
import { CfnAlarm , CfnAlarmProps } from './cloudwatch.generated' ;
4
4
import { HorizontalAnnotation } from './graph' ;
5
5
import { CreateAlarmOptions } from './metric' ;
@@ -9,37 +9,6 @@ import { dropUndefined } from './private/object';
9
9
import { MetricSet } from './private/rendering' ;
10
10
import { parseStatistic } from './private/statistic' ;
11
11
12
- /**
13
- * Interface for Alarm Rule.
14
- */
15
- export interface IAlarmRule {
16
-
17
- /**
18
- * serialized representation of Alarm Rule to be used when building the Composite Alarm resource.
19
- */
20
- toAlarmRule ( ) : string ;
21
-
22
- }
23
-
24
- /**
25
- * Represents a CloudWatch Alarm
26
- */
27
- export interface IAlarm extends IAlarmRule , IResource {
28
- /**
29
- * Alarm ARN (i.e. arn:aws:cloudwatch:<region>:<account-id>:alarm:Foo)
30
- *
31
- * @attribute
32
- */
33
- readonly alarmArn : string ;
34
-
35
- /**
36
- * Name of the alarm
37
- *
38
- * @attribute
39
- */
40
- readonly alarmName : string ;
41
- }
42
-
43
12
/**
44
13
* Properties for Alarms
45
14
*/
@@ -51,14 +20,6 @@ export interface AlarmProps extends CreateAlarmOptions {
51
20
* custom Metric objects by instantiating one.
52
21
*/
53
22
readonly metric : IMetric ;
54
-
55
- /**
56
- * AlarmState to build composite alarm expressions.
57
- *
58
- * @default - ALARM
59
- */
60
- readonly alarmState ?: AlarmState ;
61
-
62
23
}
63
24
64
25
/**
@@ -124,86 +85,6 @@ export enum TreatMissingData {
124
85
MISSING = 'missing'
125
86
}
126
87
127
- /**
128
- * Enumeration indicates state of Alarm used in building Alarm Rule.
129
- */
130
- export enum AlarmState {
131
-
132
- /**
133
- * State indicates resource is in ALARM
134
- */
135
- ALARM = 'ALARM' ,
136
-
137
- /**
138
- * State indicates resource is not in ALARM
139
- */
140
- OK = 'OK' ,
141
-
142
- /**
143
- * State indicates there is not enough data to determine is resource is in ALARM
144
- */
145
- INSUFFICIENT_DATA = 'INSUFFICIENT_DATA' ,
146
-
147
- }
148
-
149
- /**
150
- * The base class for Alarm and CompositeAlarm resources.
151
- */
152
- export abstract class AlarmBase extends Resource implements IAlarm {
153
-
154
- /**
155
- * @attribute
156
- */
157
- public abstract readonly alarmArn : string ;
158
- public abstract readonly alarmName : string ;
159
-
160
- protected alarmActionArns ?: string [ ] ;
161
- protected insufficientDataActionArns ?: string [ ] ;
162
- protected okActionArns ?: string [ ] ;
163
-
164
- public abstract toAlarmRule ( ) : string ;
165
-
166
- /**
167
- * Trigger this action if the alarm fires
168
- *
169
- * Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
170
- */
171
- public addAlarmAction ( ...actions : IAlarmAction [ ] ) {
172
- if ( this . alarmActionArns === undefined ) {
173
- this . alarmActionArns = [ ] ;
174
- }
175
-
176
- this . alarmActionArns . push ( ...actions . map ( a => a . bind ( this , this ) . alarmActionArn ) ) ;
177
- }
178
-
179
- /**
180
- * Trigger this action if there is insufficient data to evaluate the alarm
181
- *
182
- * Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
183
- */
184
- public addInsufficientDataAction ( ...actions : IAlarmAction [ ] ) {
185
- if ( this . insufficientDataActionArns === undefined ) {
186
- this . insufficientDataActionArns = [ ] ;
187
- }
188
-
189
- this . insufficientDataActionArns . push ( ...actions . map ( a => a . bind ( this , this ) . alarmActionArn ) ) ;
190
- }
191
-
192
- /**
193
- * Trigger this action if the alarm returns from breaching state into ok state
194
- *
195
- * Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
196
- */
197
- public addOkAction ( ...actions : IAlarmAction [ ] ) {
198
- if ( this . okActionArns === undefined ) {
199
- this . okActionArns = [ ] ;
200
- }
201
-
202
- this . okActionArns . push ( ...actions . map ( a => a . bind ( this , this ) . alarmActionArn ) ) ;
203
- }
204
-
205
- }
206
-
207
88
/**
208
89
* An alarm on a CloudWatch metric
209
90
*/
@@ -217,13 +98,9 @@ export class Alarm extends AlarmBase {
217
98
* @param alarmArn Alarm ARN (i.e. arn:aws:cloudwatch:<region>:<account-id>:alarm:Foo)
218
99
*/
219
100
public static fromAlarmArn ( scope : Construct , id : string , alarmArn : string ) : IAlarm {
220
- class Import extends Resource implements IAlarm {
101
+ class Import extends AlarmBase implements IAlarm {
221
102
public readonly alarmArn = alarmArn ;
222
103
public readonly alarmName = Stack . of ( scope ) . parseArn ( alarmArn , ':' ) . resourceName ! ;
223
-
224
- public toAlarmRule ( ) : string {
225
- throw new Error ( 'Method not implemented.' ) ;
226
- }
227
104
}
228
105
return new Import ( scope , id ) ;
229
106
}
@@ -252,8 +129,6 @@ export class Alarm extends AlarmBase {
252
129
*/
253
130
private readonly annotation : HorizontalAnnotation ;
254
131
255
- private readonly alarmState : AlarmState ;
256
-
257
132
constructor ( scope : Construct , id : string , props : AlarmProps ) {
258
133
super ( scope , id , {
259
134
physicalName : props . alarmName ,
@@ -314,7 +189,6 @@ export class Alarm extends AlarmBase {
314
189
label : `${ this . metric } ${ OPERATOR_SYMBOLS [ comparisonOperator ] } ${ props . threshold } for ${ datapoints } datapoints within ${ describePeriod ( props . evaluationPeriods * metricPeriod ( props . metric ) . toSeconds ( ) ) } ` ,
315
190
value : props . threshold ,
316
191
} ;
317
- this . alarmState = props . alarmState || AlarmState . ALARM ;
318
192
}
319
193
320
194
/**
@@ -337,10 +211,6 @@ export class Alarm extends AlarmBase {
337
211
return this . annotation ;
338
212
}
339
213
340
- public toAlarmRule ( ) : string {
341
- return `${ this . alarmState } (${ this . alarmArn } )` ;
342
- }
343
-
344
214
private renderMetric ( metric : IMetric ) {
345
215
const self = this ;
346
216
return dispatchMetric ( metric , {
0 commit comments