Skip to content

Commit

Permalink
Alarm Status
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Dec 19, 2024
1 parent 4d99ef0 commit 6ba345d
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 56 deletions.
59 changes: 46 additions & 13 deletions api/lib/aws/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,31 @@ export default class Alarm {

try {
const map: Map<number, string> = new Map();
const res = await cw.send(new CloudWatch.DescribeAlarmsCommand({
AlarmNamePrefix: `${this.stack}-layer-`
}));

for (const alarm of (res.MetricAlarms || [])) {
const MetricAlarms = [];

let res;
do {
const req: CloudWatch.DescribeAlarmsCommandInput = {
AlarmNamePrefix: `${this.stack}-layer-`
};

if (res && res.NextToken) req.NextToken = res.NextToken;
res = await cw.send(new CloudWatch.DescribeAlarmsCommand(req))

MetricAlarms.push(...(res.MetricAlarms || []));
} while (res.NextToken)

for (const alarm of (MetricAlarms || [])) {
let value = 'healthy';
if (alarm.StateValue === 'ALARM') value = 'alarm';
if (alarm.StateValue === 'INSUFFICIENT_DATA') value = 'unknown';

const layer = parseInt(String(alarm.AlarmName).replace(`${this.stack}-layer-`, ''));

map.set(layer, value);
if (!map.has(layer) || map.get(layer) === 'health' && value === 'alarm') {
map.set(layer, value);
}
}

return map;
Expand All @@ -41,16 +54,36 @@ export default class Alarm {
const cw = new CloudWatch.CloudWatchClient({ region: process.env.AWS_REGION });

try {
const res = await cw.send(new CloudWatch.DescribeAlarmsCommand({
AlarmNames: [`${this.stack}-layer-${layer}`]
}));
const MetricAlarms = [];

let res;
do {
const req: CloudWatch.DescribeAlarmsCommandInput = {
AlarmNames: [`${this.stack}-layer-${layer}`]
};

if (res && res.NextToken) req.NextToken = res.NextToken;
res = await cw.send(new CloudWatch.DescribeAlarmsCommand(req))

MetricAlarms.push(...(res.MetricAlarms || []));
} while (res.NextToken)

if (!res.MetricAlarms.length) return 'unknown';

if (!res.MetricAlarms || !res.MetricAlarms.length) return 'unknown';
let final;
for (const alarm of (MetricAlarms || [])) {
let value = 'healthy';
if (alarm.StateValue === 'ALARM') value = 'alarm';
if (alarm.StateValue === 'INSUFFICIENT_DATA') value = 'unknown';

const layer = parseInt(String(alarm.AlarmName).replace(`${this.stack}-layer-`, ''));

if (!final || final === 'health' && value === 'alarm') {
final = value
}
}

let value = 'healthy';
if (res.MetricAlarms[0].StateValue === 'ALARM') value = 'alarm';
if (res.MetricAlarms[0].StateValue === 'INSUFFICIENT_DATA') value = 'unknown';
return value;
return final;
} catch (err) {
throw new Err(500, new Error(err instanceof Error ? err.message : String(err)), 'Failed to describe alarm');
}
Expand Down
92 changes: 49 additions & 43 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/web/src/components/Connection/ConnectionLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default {
this.loading = true;
try {
const url = stdurl(`/api/connection/${this.$route.params.connectionid}/layer`);
url.searchParams.append('alarms', String(true));
url.searchParams.append('limit', this.paging.limit);
url.searchParams.append('page', this.paging.page);
url.searchParams.append('filter', this.paging.filter);
Expand Down

0 comments on commit 6ba345d

Please sign in to comment.