UNPKG

@khulnasoft/cdk

Version:

Define your observability as code using the AWS CDK

41 lines 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Alert = void 0; const aws_cdk_lib_1 = require("aws-cdk-lib"); const config_1 = require("../config"); const query_1 = require("./query"); class Alert extends aws_cdk_lib_1.CfnResource { constructor(id, props) { const defaultFrequency = "1h"; const defaultWindow = "1h"; let Parameters = undefined; if ("ref" in props.parameters.query) { Parameters = Object.assign(Object.assign({}, props.parameters), { threshold: props.parameters.threshold || { operation: "=", value: 0 }, query: props.parameters.query.ref, frequency: props.parameters.frequency || defaultFrequency, window: props.parameters.window || defaultWindow }); } if ("filters" in props.parameters.query) { const query = new query_1.Query(`${id}-query`, { parameters: Object.assign(Object.assign({}, props.parameters.query), { calculations: props.parameters.query.calculations || [ { operation: "COUNT" }, ] }), }); Parameters = Object.assign(Object.assign({}, props.parameters), { threshold: props.parameters.threshold || { operation: "=", value: 0 }, query: query.ref, frequency: props.parameters.frequency || defaultFrequency, window: props.parameters.window || defaultWindow }); } if (!Parameters) throw new Error("Invalid alert parameters. Declare at least one of filters or ref in the query."); super(config_1.Kengine.getConstruct(), id, { type: "Custom::KengineAlert", properties: { id, ServiceToken: config_1.Kengine.getServiceToken(), KengineApiKey: config_1.Kengine.getApiKey(), enabled: props.enabled, Description: props.description, Parameters, Channels: props.channels || config_1.Kengine.getDefaultChannel() && [config_1.Kengine.getDefaultChannel()], Origin: "cdk", }, }); } } exports.Alert = Alert; //# sourceMappingURL=alert.js.map