/
alarm-status-widget.ts
109 lines (98 loc) · 2.81 KB
/
alarm-status-widget.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
97
98
99
100
101
102
103
104
105
106
107
108
109
import { IAlarm } from './alarm-base';
import { AlarmState } from './alarm-rule';
import { ConcreteWidget } from './widget';
/**
* The sort possibilities for AlarmStatusWidgets
*/
export enum AlarmStatusWidgetSortBy {
/**
* Choose DEFAULT to sort them in alphabetical order by alarm name.
*/
DEFAULT = 'default',
/**
* Choose STATE_UPDATED_TIMESTAMP to sort them first by alarm state, with alarms in ALARM state first,
* INSUFFICIENT_DATA alarms next, and OK alarms last.
* Within each group, the alarms are sorted by when they last changed state, with more recent state changes listed first.
*/
STATE_UPDATED_TIMESTAMP = 'stateUpdatedTimestamp',
/**
* Choose TIMESTAMP to sort them by the time when the alarms most recently changed state,
* no matter the current alarm state.
* The alarm that changed state most recently is listed first.
*/
TIMESTAMP = 'timestamp',
}
/**
* Properties for an Alarm Status Widget
*/
export interface AlarmStatusWidgetProps {
/**
* CloudWatch Alarms to show in widget
*/
readonly alarms: IAlarm[];
/**
* The title of the widget
*
* @default 'Alarm Status'
*/
readonly title?: string;
/**
* Width of the widget, in a grid of 24 units wide
*
* @default 6
*/
readonly width?: number;
/**
* Height of the widget
*
* @default 3
*/
readonly height?: number;
/**
* Specifies how to sort the alarms in the widget.
*
* @default - alphabetical order
*/
readonly sortBy?: AlarmStatusWidgetSortBy;
/**
* Use this field to filter the list of alarms displayed in the widget to only those alarms currently in the specified states.
* You can specify one or more alarm states in the value for this field.
* The alarm states that you can specify are ALARM, INSUFFICIENT_DATA, and OK.
*
* If you omit this field or specify an empty array, all the alarms specifed in alarms are displayed.
*
* @default - all the alarms specified in alarms are displayed.
*/
readonly states?: AlarmState[];
}
/**
* A dashboard widget that displays alarms in a grid view
*/
export class AlarmStatusWidget extends ConcreteWidget {
private readonly props: AlarmStatusWidgetProps;
constructor(props: AlarmStatusWidgetProps) {
super(props.width || 6, props.height || 3);
this.props = props;
}
public position(x: number, y: number): void {
this.x = x;
this.y = y;
}
public toJson(): any[] {
return [
{
type: 'alarm',
width: this.width,
height: this.height,
x: this.x,
y: this.y,
properties: {
title: this.props.title ? this.props.title : 'Alarm Status',
alarms: this.props.alarms.map((alarm) => alarm.alarmArn),
states: this.props.states,
sortBy: this.props.sortBy,
},
},
];
}
}