Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
603 additions
and
10 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,119 @@ | ||
'use strict' | ||
|
||
/** | ||
* @param {object} eventsAlarmsConfig The fully resolved alarm configuration | ||
*/ | ||
module.exports = function eventsAlarms (eventsAlarmsConfig, context) { | ||
return { | ||
createRuleAlarms | ||
} | ||
|
||
/** | ||
* Add all required Events alarms to the provided CloudFormation template | ||
* based on the EventBridge Rule found within | ||
* | ||
* @param {CloudFormationTemplate} cfTemplate A CloudFormation template object | ||
*/ | ||
function createRuleAlarms (cfTemplate) { | ||
const ruleResources = cfTemplate.getResourcesByType( | ||
'AWS::Events::Rule' | ||
) | ||
|
||
for (const [ruleResourceName, ruleResource] of Object.entries(ruleResources)) { | ||
if (eventsAlarmsConfig.FailedInvocations.enabled) { | ||
const failedInvocations = createFailedInvocationsAlarm( | ||
ruleResourceName, | ||
ruleResource, | ||
eventsAlarmsConfig.FailedInvocations | ||
) | ||
cfTemplate.addResource(failedInvocations.resourceName, failedInvocations.resource) | ||
} | ||
|
||
if (eventsAlarmsConfig.ThrottledRules.enabled) { | ||
const throttledRules = createThrottledRulesAlarm( | ||
ruleResourceName, | ||
ruleResource, | ||
eventsAlarmsConfig.ThrottledRules | ||
) | ||
cfTemplate.addResource(throttledRules.resourceName, throttledRules.resource) | ||
} | ||
} | ||
} | ||
|
||
function createRuleAlarm ( | ||
alarmName, | ||
alarmDescription, | ||
ruleName, | ||
comparisonOperator, | ||
threshold, | ||
metricName, | ||
statistic, | ||
period, | ||
evaluationPeriods, | ||
treatMissingData | ||
) { | ||
const metricProperties = { | ||
Dimensions: [{ Name: 'RuleName', Value: ruleName }], | ||
MetricName: metricName, | ||
Namespace: 'AWS/Events', | ||
Period: period, | ||
Statistic: statistic | ||
} | ||
|
||
return { | ||
Type: 'AWS::CloudWatch::Alarm', | ||
Properties: { | ||
ActionsEnabled: true, | ||
AlarmActions: context.alarmActions, | ||
AlarmName: alarmName, | ||
AlarmDescription: alarmDescription, | ||
EvaluationPeriods: evaluationPeriods, | ||
ComparisonOperator: comparisonOperator, | ||
Threshold: threshold, | ||
TreatMissingData: treatMissingData, | ||
...metricProperties | ||
} | ||
} | ||
} | ||
|
||
function createFailedInvocationsAlarm (ruleResourceName, ruleResource, config) { | ||
const ruleName = ruleResource.Properties.Name | ||
const threshold = config.Threshold | ||
|
||
return { | ||
resourceName: `slicWatchEventsFailedInvocationsAlarm${ruleResourceName}`, | ||
resource: createRuleAlarm( | ||
`EventsFailedInvocationsAlarm_${ruleName}`, // alarmName | ||
`Failed Invocations for ${ruleName} breaches ${threshold}`, // alarmDescription | ||
ruleName, | ||
config.ComparisonOperator, | ||
threshold, | ||
'FailedInvocations', // metricName | ||
config.Statistic, | ||
config.Period, | ||
config.EvaluationPeriods, | ||
config.TreatMissingData | ||
) | ||
} | ||
} | ||
|
||
function createThrottledRulesAlarm (ruleResourceName, ruleResource, config) { | ||
const ruleName = ruleResource.Properties.Name | ||
const threshold = config.Threshold | ||
return { | ||
resourceName: `slicWatchEventsThrottledRulesAlarm${ruleResourceName}`, | ||
resource: createRuleAlarm( | ||
`EventsThrottledRulesAlarm_${ruleName}`, // alarmName | ||
`Throttled RulesAlarm for ${ruleName} breaches ${threshold}`, // alarmDescription | ||
ruleName, | ||
config.ComparisonOperator, | ||
threshold, | ||
'ThrottledRules', // metricName | ||
config.Statistic, | ||
config.Period, | ||
config.EvaluationPeriods, | ||
config.TreatMissingData | ||
) | ||
} | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.