Fix error handling
This commit is contained in:
parent
98962ae5f5
commit
233f9768e8
|
@ -111,7 +111,7 @@ def send_plugin_notification(event_type, data, recipients, notification):
|
||||||
notification.plugin.send(event_type, data, recipients, notification.options)
|
notification.plugin.send(event_type, data, recipients, notification.options)
|
||||||
status = SUCCESS_METRIC_STATUS
|
status = SUCCESS_METRIC_STATUS
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log_data["message"] = f"Unable to send expiration notification to recipients {recipients}"
|
log_data["message"] = f"Unable to send {event_type} notification to recipients {recipients}"
|
||||||
current_app.logger.error(log_data, exc_info=True)
|
current_app.logger.error(log_data, exc_info=True)
|
||||||
sentry.captureException()
|
sentry.captureException()
|
||||||
|
|
||||||
|
|
|
@ -454,7 +454,4 @@ class SNSNotificationPlugin(ExpirationNotificationPlugin):
|
||||||
f"{self.get_option('topicName', options)}"
|
f"{self.get_option('topicName', options)}"
|
||||||
|
|
||||||
current_app.logger.debug(f"Publishing {notification_type} notification to topic {topic_arn}")
|
current_app.logger.debug(f"Publishing {notification_type} notification to topic {topic_arn}")
|
||||||
try:
|
|
||||||
sns.publish(topic_arn, message, notification_type, region_name=self.get_option("region", options))
|
sns.publish(topic_arn, message, notification_type, region_name=self.get_option("region", options))
|
||||||
except Exception:
|
|
||||||
current_app.logger.exception(f"Error publishing {notification_type} notification to topic {topic_arn}")
|
|
||||||
|
|
|
@ -29,7 +29,8 @@ def publish_single(sns_client, topic_arn, certificate, notification_type):
|
||||||
|
|
||||||
response_code = response["ResponseMetadata"]["HTTPStatusCode"]
|
response_code = response["ResponseMetadata"]["HTTPStatusCode"]
|
||||||
if response_code != 200:
|
if response_code != 200:
|
||||||
raise Exception(f"Failed to publish notification to SNS, response code was {response_code}")
|
raise Exception(f"Failed to publish {notification_type} notification to SNS topic {topic_arn}. "
|
||||||
|
f"SNS response: {response_code} {response}")
|
||||||
|
|
||||||
current_app.logger.debug(f"AWS SNS message published to topic [{topic_arn}]: [{response}]")
|
current_app.logger.debug(f"AWS SNS message published to topic [{topic_arn}]: [{response}]")
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ class SlackNotificationPlugin(ExpirationNotificationPlugin):
|
||||||
raise Exception("Unable to create message attachments")
|
raise Exception("Unable to create message attachments")
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"text": "Lemur {0} Notification".format(notification_type.capitalize()),
|
"text": f"Lemur {notification_type.capitalize()} Notification",
|
||||||
"attachments": attachments,
|
"attachments": attachments,
|
||||||
"channel": self.get_option("recipients", options),
|
"channel": self.get_option("recipients", options),
|
||||||
"username": self.get_option("username", options),
|
"username": self.get_option("username", options),
|
||||||
|
@ -136,8 +136,8 @@ class SlackNotificationPlugin(ExpirationNotificationPlugin):
|
||||||
r = requests.post(self.get_option("webhook", options), json.dumps(body))
|
r = requests.post(self.get_option("webhook", options), json.dumps(body))
|
||||||
|
|
||||||
if r.status_code not in [200]:
|
if r.status_code not in [200]:
|
||||||
raise Exception("Failed to send message")
|
raise Exception(f"Failed to send message. Slack response: {r.status_code} {body}")
|
||||||
|
|
||||||
current_app.logger.info(
|
current_app.logger.info(
|
||||||
"Slack response: {0} Message Body: {1}".format(r.status_code, body)
|
f"Slack response: {r.status_code} Message Body: {body}"
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue