-
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 5 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,122 @@ | ||
resource "aws_cloudwatch_query_definition" "sms-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.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-carrier-dwell-times" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Carrier dwell times" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries.name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures.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-get-failures" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Get failures" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries_failures.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-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.name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures.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-interntional-sending-status" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / International sending status" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries.name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures.name | ||
] | ||
|
||
query_string = <<QUERY | ||
fields @timestamp, @message | ||
| parse @message /"isoCountryCode":"(?<Country>[^"]+)"/ | ||
| parse @message /"eventType":"(?<Event_Type>[^"]+)"/ | ||
| parse @message /"isFinal":(?<Is_Final>\w+)/ | ||
| filter Is_Final = "true" | ||
| stats count(*) as Event_Count by Country, Event_Type | ||
| display Country, Event_Type, Event_Count | ||
| sort Country asc | ||
| limit 200 | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "sms-success-vs-unreachable" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Success vs Unreachable" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries.name, | ||
aws_cloudwatch_log_group.sns_deliveries_failures.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-unreachable-phone-numbers" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (SNS) / Success vs Unreachable" | ||
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 name 'SMS (SNS) / Success vs Unreachable' is duplicated from the previous query definition. Consider renaming this to avoid confusion. |
||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.sns_deliveries_failures.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 |
---|---|---|
@@ -1,6 +1,41 @@ | ||
resource "aws_cloudwatch_query_definition" "pinpoint-carrier-dwell-times" { | ||
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. This is the equivalent of |
||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (Pinpoint) / Carrier dwell times" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.pinpoint_deliveries.name, | ||
aws_cloudwatch_log_group.pinpoint_deliveries_failures.name, | ||
] | ||
|
||
query_string = <<QUERY | ||
stats avg((eventTimestamp - messageRequestTimestamp) / 1000 / 60) as Avg_carrier_time_minutes, | ||
count(*) as Number by carrierName as Carrier | ||
| filter isFinal | ||
| sort by Avg_carrier_time_minutes desc | ||
| limit 100 | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "pinpoint-failures-by-carrier" { | ||
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. This is the new query over here for failures by carrier. |
||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS (Pinpoint) / Failures by carrier" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.pinpoint_deliveries.name, | ||
aws_cloudwatch_log_group.pinpoint_deliveries_failures.name, | ||
] | ||
|
||
query_string = <<QUERY | ||
filter isFinal | ||
| filter messageStatus not like /DELIVERED|SUCCESSFUL/ | ||
| stats count(*) as Total by coalesce(carrierName, 'Unknown/VOIP') as Carrier, messageStatus as MessageStatus | ||
| sort by Total desc | ||
QUERY | ||
} | ||
|
||
resource "aws_cloudwatch_query_definition" "pinpoint-logs" { | ||
count = var.cloudwatch_enabled ? 1 : 0 | ||
name = "SMS / Pinpoint logs" | ||
name = "SMS (Pinpoint) / Logs" | ||
|
||
log_group_names = [ | ||
aws_cloudwatch_log_group.pinpoint_deliveries.name | ||
|
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.