forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm-base.ts
96 lines (80 loc) · 2.31 KB
/
alarm-base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { IResource, Resource } from '@aws-cdk/core';
import { IAlarmAction } from './alarm-action';
/**
* Interface for Alarm Rule.
*/
export interface IAlarmRule {
/**
* serialized representation of Alarm Rule to be used when building the Composite Alarm resource.
*/
renderAlarmRule(): string;
}
/**
* Represents a CloudWatch Alarm
*/
export interface IAlarm extends IAlarmRule, IResource {
/**
* Alarm ARN (i.e. arn:aws:cloudwatch:<region>:<account-id>:alarm:Foo)
*
* @attribute
*/
readonly alarmArn: string;
/**
* Name of the alarm
*
* @attribute
*/
readonly alarmName: string;
}
/**
* The base class for Alarm and CompositeAlarm resources.
*/
export abstract class AlarmBase extends Resource implements IAlarm {
/**
* @attribute
*/
public abstract readonly alarmArn: string;
public abstract readonly alarmName: string;
protected alarmActionArns?: string[];
protected insufficientDataActionArns?: string[];
protected okActionArns?: string[];
/**
* AlarmRule indicating ALARM state for Alarm.
*/
public renderAlarmRule(): string {
return `ALARM(${this.alarmArn})`;
}
/**
* Trigger this action if the alarm fires
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public addAlarmAction(...actions: IAlarmAction[]) {
if (this.alarmActionArns === undefined) {
this.alarmActionArns = [];
}
this.alarmActionArns.push(...actions.map(a => a.bind(this, this).alarmActionArn));
}
/**
* Trigger this action if there is insufficient data to evaluate the alarm
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public addInsufficientDataAction(...actions: IAlarmAction[]) {
if (this.insufficientDataActionArns === undefined) {
this.insufficientDataActionArns = [];
}
this.insufficientDataActionArns.push(...actions.map(a => a.bind(this, this).alarmActionArn));
}
/**
* Trigger this action if the alarm returns from breaching state into ok state
*
* Typically the ARN of an SNS topic or ARN of an AutoScaling policy.
*/
public addOkAction(...actions: IAlarmAction[]) {
if (this.okActionArns === undefined) {
this.okActionArns = [];
}
this.okActionArns.push(...actions.map(a => a.bind(this, this).alarmActionArn));
}
}