Skip to content
Open
51 changes: 41 additions & 10 deletions aws/common/cloudwatch_alarms_sms.tf
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ resource "aws_cloudwatch_metric_alarm" "sns-sms-success-rate-canadian-numbers-us
id = "alarmCondition"
label = "Guarded Alarm Condition"
return_data = true
expression = "IF(successRate < 0.85 AND messagesPublished > 75, 0, 1)"
expression = "IF(successRate < 0.85 AND messagesPublished > 85, 0, 1)"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a typo on my part

}
}

Expand All @@ -167,24 +167,55 @@ resource "aws_cloudwatch_metric_alarm" "sns-sms-success-rate-canadian-numbers-cr

resource "aws_cloudwatch_metric_alarm" "sns-sms-success-rate-canadian-numbers-us-west-2-critical" {
provider = aws.us-west-2
count = var.cloudwatch_enabled ? 1 : 0

count = var.cloudwatch_enabled ? 1 : 0
alarm_name = "sns-sms-success-rate-canadian-numbers-us-west-2-critical"
alarm_description = "SMS success rate to Canadian numbers is below 75% over 2 consecutive periods of 12 hours"
comparison_operator = "LessThanThreshold"
evaluation_periods = "2"
datapoints_to_alarm = "2"
metric_name = "SMSSuccessRate"
namespace = "AWS/SNS"
period = 60 * 60 * 12
statistic = "Average"
threshold = 75 / 100
threshold = 1
alarm_actions = [aws_sns_topic.notification-canada-ca-alert-critical-us-west-2.arn]
ok_actions = [aws_sns_topic.notification-canada-ca-alert-ok-us-west-2.arn]
treat_missing_data = "notBreaching"
dimensions = {
SMSType = "Transactional"
Country = "CA"

metric_query {
id = "successRate"
label = "Success Rate"
return_data = false
metric {
namespace = "AWS/SNS"
metric_name = "SMSSuccessRate"
period = 60 * 60 * 12
stat = "Average"
dimensions = {
SMSType = "Transactional"
Country = "CA"
}
}
}

metric_query {
id = "messagesPublished"
label = "Messages Published"
return_data = false
metric {
namespace = "AWS/SNS"
metric_name = "NumberOfMessagesPublished"
period = 60 * 60 * 12
stat = "Sum"
dimensions = {
SMSType = "Transactional"
Country = "CA"
}
}
}

metric_query {
id = "alarmCondition"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it not matter that there are two metric_query's with the same id?

Copy link
Contributor Author

@whabanks whabanks Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the metric_query's are scoped to the metric alarms themselves and shouldn't collide. @P0NDER0SA is that correct?

label = "Guarded Alarm Condition"
return_data = true
expression = "IF(successRate < 0.75 AND messagesPublished > 75, 0, 1)"
}
}

Expand Down
Loading