-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SMS (SNS) stored queries from CWI into Terraform / SMS (pinpoint) new queries #1574
Changes from 15 commits
3b3a53e
c7f5644
2c81d0b
a84776c
7b8e94a
1aed8de
8997ad6
239c76d
a33a84c
d21165c
ef024bd
0da9bb6
dcd1985
e51161d
912a4e7
bcfdc1d
d0ac9b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
resource "aws_cloudwatch_query_definition" "sms-sns-blocked-as-spam" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Block as spam" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp as Timestamp, delivery.phoneCarrier as Carrier, delivery.providerResponse as `Provider response`, delivery.destination as `Destination phone number` | ||
| filter delivery.providerResponse like 'spam' | ||
| sort Timestamp desc | ||
| limit 100 | ||
} | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-sns-carrier-dwell-times" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Carrier dwell times" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries[0].name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
stats avg(delivery.dwellTimeMsUntilDeviceAck / 1000 / 60) as Avg_carrier_time_minutes, | ||
| count(*) as Number by delivery.phoneCarrier as Carrier | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-sns-get-failures" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Get failures" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp as Timestamp, status, delivery.phoneCarrier as Carrier, delivery.providerResponse as `Provider response`, delivery.destination as `Destination phone number`, notification.messageId as messageId, @message | ||
| filter status = 'FAILURE' | ||
| sort Timestamp desc | ||
| limit 200 | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-sns-get-sms-logs-by-phone-number" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Get SMS logs by phone number" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries[0].name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp as Timestamp, status as Status, notification.messageId as `Message ID`, | ||
delivery.destination as `Destination phone number`, delivery.providerResponse as `Provider response`, | ||
delivery.smsType as `Message type` | ||
| filter delivery.destination like '1416xxxxxxx' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider parameterizing the phone number filter to avoid hardcoding '1416xxxxxxx'. This will make the query more flexible and reusable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can use parameters in these unfortunately. If that was a query in a dashboard, yeah but that is not the case. |
||
| sort Timestamp desc | ||
| limit 100 | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-sns-international-sending-status" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / International sending status" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries[0].name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp, @message, delivery.mcc as CountryCode, status | ||
| stats count(*) as Event_Count by CountryCode, status | ||
| display CountryCode, status, Event_Count | ||
| sort CountryCode asc | ||
| limit 200 | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-sns-success-vs-unreachable" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Success vs Unreachable" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries[0].name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp, delivery.providerResponse | ||
| parse delivery.providerResponse "Phone is currently unreachable/*" as @unavailable | ||
| parse delivery.providerResponse "Message has been * by phone" as @available | ||
| sort @timestamp desc | ||
| stats count(@unavailable), count(@available), count(*) by bin(1h) | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-sns-unreachable-phone-numbers" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Unreachable phone numbers" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries_failures[0].name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp, delivery.providerResponse | ||
| filter delivery.providerResponse like "Phone is currently unreachable/unavailable" | ||
| sort @timestamp desc | ||
| limit 20 | ||
QUERY | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# | ||
|
||
resource "aws_cloudwatch_log_group" "pinpoint_deliveries" { | ||
# REVIEW: We might want the count attribute present to disable this resource | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment suggests adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah probably a good idea to have it enabled/disabled based on cloudwatch enabled. |
||
name = "sns/${var.region}/${var.account_id}/PinpointDirectPublishToPhoneNumber" | ||
retention_in_days = var.sensitive_log_retention_period_days | ||
tags = { | ||
|
@@ -11,6 +12,7 @@ resource "aws_cloudwatch_log_group" "pinpoint_deliveries" { | |
} | ||
|
||
resource "aws_cloudwatch_log_group" "pinpoint_deliveries_failures" { | ||
# REVIEW: We might want the count attribute present to disable this resource | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment suggests adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
name = "sns/${var.region}/${var.account_id}/PinpointDirectPublishToPhoneNumber/Failure" | ||
retention_in_days = var.sensitive_log_retention_period_days | ||
tags = { | ||
|
@@ -122,3 +124,20 @@ resource "aws_cloudwatch_log_metric_filter" "pinpoint-sms-failures" { | |
default_value = "0" | ||
} | ||
} | ||
|
||
resource "aws_cloudwatch_log_metric_filter" "pinpoint-sms-failures-carriers" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
log_group_name = aws_cloudwatch_log_group.pinpoint_deliveries_failures.name | ||
|
||
name = "pinpoint-sms-failures-carriers" | ||
pattern = "{ ($.isFinal IS TRUE) && ($.carrierName != \"\" && ( ($.messageStatus != \"SUCCESSFUL\") && ($.messageStatus != \"DELIVERED\") )) }" | ||
jimleroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
metric_transformation { | ||
name = "pinpoint-sms-failures-carriers" | ||
namespace = "LogMetrics" | ||
value = "1" | ||
dimensions = { | ||
jimleroyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Carrier = "$.carrierName" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
count(*) as Number
should be on a new line for better readability and consistency with other queries.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is on a new line.