UNPKG

cloud-report

Version:

Collects and analyzes cloud resources

40 lines (39 loc) 1.53 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../../../utils"); const aws_1 = require("../../../utils/aws"); const base_1 = require("../../base"); class AlarmsCollector extends base_1.BaseCollector { collect(callback) { return this.getAllAlarms(); } async getAllAlarms() { const self = this; const serviceName = "CloudWatch"; const CloudWatchRegions = self.getRegions(serviceName); const alarms = {}; for (const region of CloudWatchRegions) { try { const CloudWatchService = self.getClient(serviceName, region); alarms[region] = []; let fetchPending = true; let marker; while (fetchPending) { const alarmsResponse = await CloudWatchService.describeAlarms({ NextToken: marker }).promise(); if (alarmsResponse.MetricAlarms) { alarms[region] = alarms[region].concat(alarmsResponse.MetricAlarms); } marker = alarmsResponse.NextToken; fetchPending = marker !== undefined; await utils_1.CommonUtil.wait(200); } } catch (error) { aws_1.AWSErrorHandler.handle(error); continue; } } return { alarms }; } } exports.AlarmsCollector = AlarmsCollector;