UNPKG

cloud-report

Version:

Collects and analyzes cloud resources

56 lines (55 loc) 2.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const types_1 = require("../../../types"); const base_1 = require("../../base"); class ApiLogsAnalyzer extends base_1.BaseAnalyzer { analyze(params, fullReport) { const allApis = params.apis; const allApiStages = params.api_stages; if (!allApis || !allApiStages) { return undefined; } const api_logs_enabled = { type: types_1.CheckAnalysisType.OperationalExcellence }; api_logs_enabled.what = "Are CloudWatch logs enabled for Apis?"; api_logs_enabled.why = "It is important to set logs for Apis for debugging API issues"; api_logs_enabled.recommendation = "Recommended to set logs for all Apis"; api_logs_enabled.benchmark = ['all']; const allRegionsAnalysis = {}; for (const region in allApis) { const regionApis = allApis[region]; allRegionsAnalysis[region] = []; for (const api of regionApis) { if (!allApiStages[region][api.id] || !allApiStages[region][api.id].length) { continue; } for (const apiStage of allApiStages[region][api.id]) { const apiStageAnalysis = {}; apiStageAnalysis.resource = { apiName: api.name, stage: apiStage }; apiStageAnalysis.resourceSummary = { name: "ApiState", value: `${api.name} | ${apiStage.stageName}`, }; const stageLogLevel = this.getLogLevel(apiStage); if (stageLogLevel && stageLogLevel !== "OFF") { apiStageAnalysis.severity = types_1.SeverityStatus.Good; apiStageAnalysis.message = `Logs are enabled with logLevel: ${stageLogLevel}`; } else { apiStageAnalysis.severity = types_1.SeverityStatus.Warning; apiStageAnalysis.message = "Logs are not enabled"; apiStageAnalysis.action = "Set logs for API Stage"; } allRegionsAnalysis[region].push(apiStageAnalysis); } } } api_logs_enabled.regions = allRegionsAnalysis; return { api_logs_enabled }; } getLogLevel(stage) { if (stage.methodSettings["*/*"]) { return stage.methodSettings["*/*"].loggingLevel; } } } exports.ApiLogsAnalyzer = ApiLogsAnalyzer;