mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
Merge pull request #502 from GSA/debug
add debug for check sms deliver receipt bug
This commit is contained in:
@@ -4,6 +4,7 @@ import re
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from boto3 import client
|
from boto3 import client
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
from app.clients import AWS_CLIENT_CONFIG, Client
|
from app.clients import AWS_CLIENT_CONFIG, Client
|
||||||
from app.cloudfoundry_config import cloud_config
|
from app.cloudfoundry_config import cloud_config
|
||||||
@@ -50,6 +51,7 @@ class AwsCloudwatchClient(Client):
|
|||||||
# Check all cloudwatch logs from the time the notification was sent (currently 5 minutes previously) until now
|
# Check all cloudwatch logs from the time the notification was sent (currently 5 minutes previously) until now
|
||||||
now = round(time.time() * 1000)
|
now = round(time.time() * 1000)
|
||||||
beginning = sent_at
|
beginning = sent_at
|
||||||
|
current_app.logger.info(f"TIME RANGE TO CHECK {beginning} to {now}")
|
||||||
next_token = None
|
next_token = None
|
||||||
all_log_events = []
|
all_log_events = []
|
||||||
while True:
|
while True:
|
||||||
@@ -72,13 +74,20 @@ class AwsCloudwatchClient(Client):
|
|||||||
all_log_events.extend(log_events)
|
all_log_events.extend(log_events)
|
||||||
if len(log_events) > 0:
|
if len(log_events) > 0:
|
||||||
# We found it
|
# We found it
|
||||||
|
current_app.logger.info(
|
||||||
|
f"WE FOUND THE EVENT WE WERE LOOKING FOR? {log_events}"
|
||||||
|
)
|
||||||
break
|
break
|
||||||
next_token = response.get("nextToken")
|
next_token = response.get("nextToken")
|
||||||
if not next_token:
|
if not next_token:
|
||||||
break
|
break
|
||||||
|
if len(all_log_events) == 0:
|
||||||
|
print(f"WE FOUND NO LOG EVENTS OVER TIME RANGE {beginning} to {now}")
|
||||||
return all_log_events
|
return all_log_events
|
||||||
|
|
||||||
def check_sms(self, message_id, notification_id, created_at):
|
def check_sms(self, message_id, notification_id, created_at):
|
||||||
|
if os.getenv("LOCALSTACK_ENDPOINT_URL"):
|
||||||
|
current_app.logger.info("GADZOOKS WE ARE RUNNING WITH LOCALSTACK")
|
||||||
region = cloud_config.sns_region
|
region = cloud_config.sns_region
|
||||||
# TODO this clumsy approach to getting the account number will be fixed as part of notify-api #258
|
# TODO this clumsy approach to getting the account number will be fixed as part of notify-api #258
|
||||||
account_number = cloud_config.ses_domain_arn
|
account_number = cloud_config.ses_domain_arn
|
||||||
@@ -87,24 +96,39 @@ class AwsCloudwatchClient(Client):
|
|||||||
account_number = account_number[0]
|
account_number = account_number[0]
|
||||||
|
|
||||||
log_group_name = f"sns/{region}/{account_number}/DirectPublishToPhoneNumber"
|
log_group_name = f"sns/{region}/{account_number}/DirectPublishToPhoneNumber"
|
||||||
|
current_app.logger.info(
|
||||||
|
f"LOG GROUP NAME: {log_group_name} MESSAGE ID: {message_id}"
|
||||||
|
)
|
||||||
filter_pattern = '{$.notification.messageId="XXXXX"}'
|
filter_pattern = '{$.notification.messageId="XXXXX"}'
|
||||||
filter_pattern = filter_pattern.replace("XXXXX", message_id)
|
filter_pattern = filter_pattern.replace("XXXXX", message_id)
|
||||||
all_log_events = self._get_log(filter_pattern, log_group_name, created_at)
|
all_log_events = self._get_log(filter_pattern, log_group_name, created_at)
|
||||||
|
current_app.logger.info(f"NUMBER OF ALL LOG EVENTS {len(all_log_events)}")
|
||||||
|
|
||||||
if all_log_events and len(all_log_events) > 0:
|
if all_log_events and len(all_log_events) > 0:
|
||||||
|
current_app.logger.info(
|
||||||
|
"SHOULD RETURN SUCCESS BECAUSE WE FOUND A SUCCESS MESSAGE FOR MESSAGE ID"
|
||||||
|
)
|
||||||
event = all_log_events[0]
|
event = all_log_events[0]
|
||||||
message = json.loads(event["message"])
|
message = json.loads(event["message"])
|
||||||
|
current_app.logger.info(f"MESSAGE {message}")
|
||||||
return "success", message["delivery"]["providerResponse"]
|
return "success", message["delivery"]["providerResponse"]
|
||||||
|
|
||||||
log_group_name = (
|
log_group_name = (
|
||||||
f"sns/{region}/{account_number}/DirectPublishToPhoneNumber/Failure"
|
f"sns/{region}/{account_number}/DirectPublishToPhoneNumber/Failure"
|
||||||
)
|
)
|
||||||
|
current_app.logger.info(f"FAILURE LOG GROUP NAME {log_group_name}")
|
||||||
all_failed_events = self._get_log(filter_pattern, log_group_name, created_at)
|
all_failed_events = self._get_log(filter_pattern, log_group_name, created_at)
|
||||||
|
current_app.logger.info(
|
||||||
|
f"NUMBER OF ALL FAILED LOG EVENTS {len(all_failed_events)}"
|
||||||
|
)
|
||||||
if all_failed_events and len(all_failed_events) > 0:
|
if all_failed_events and len(all_failed_events) > 0:
|
||||||
|
current_app.logger.info("SHOULD RETURN FAILED BECAUSE WE FOUND A FAILURE")
|
||||||
event = all_failed_events[0]
|
event = all_failed_events[0]
|
||||||
message = json.loads(event["message"])
|
message = json.loads(event["message"])
|
||||||
|
current_app.logger.info(f"MESSAGE {message}")
|
||||||
return "failure", message["delivery"]["providerResponse"]
|
return "failure", message["delivery"]["providerResponse"]
|
||||||
|
|
||||||
|
print(f"RAISING EXCEPTION FOR MESSAGE_ID {message_id}")
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"No event found for message_id {message_id} notification_id {notification_id}"
|
f"No event found for message_id {message_id} notification_id {notification_id}"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user