-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cloudwatch): alarm status widget (#9456)
Add support for the alarm status widget. This widget allows you to see the status of multiple alarms in a grid view. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
CurtisEppel
authored
Aug 11, 2020
1 parent
ae9ed62
commit 41940d3
Showing
4 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/@aws-cdk/aws-cloudwatch/lib/alarm-status-widget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { IAlarm } from './alarm-base'; | ||
import { ConcreteWidget } from './widget'; | ||
|
||
/** | ||
* 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; | ||
} | ||
|
||
/** | ||
* 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), | ||
}, | ||
}, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/@aws-cdk/aws-cloudwatch/test/test.alarm-status-widget.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Stack } from '@aws-cdk/core'; | ||
import { Test } from 'nodeunit'; | ||
import { Metric, Alarm, AlarmStatusWidget } from '../lib'; | ||
export = { | ||
'alarm status widget'(test: Test) { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const metric = new Metric({ namespace: 'CDK', metricName: 'Test' }); | ||
const alarm = new Alarm(stack, 'Alarm', { | ||
metric, | ||
threshold: 1, | ||
evaluationPeriods: 1, | ||
}); | ||
|
||
// WHEN | ||
const widget = new AlarmStatusWidget({ | ||
alarms: [alarm], | ||
}); | ||
|
||
// THEN | ||
test.deepEqual(stack.resolve(widget.toJson()), [ | ||
{ | ||
type: 'alarm', | ||
width: 6, | ||
height: 3, | ||
properties: { | ||
title: 'Alarm Status', | ||
alarms: [{ 'Fn::GetAtt': ['Alarm7103F465', 'Arn'] }], | ||
}, | ||
}, | ||
]); | ||
|
||
test.done(); | ||
}, | ||
}; |