Restructure log messages
This commit is contained in:
parent
60bb0037f0
commit
072b337f37
|
@ -8,6 +8,7 @@
|
||||||
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
|
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
@ -96,14 +97,20 @@ def send_notification(event_type, data, targets, notification):
|
||||||
:param notification:
|
:param notification:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
function = f"{__name__}.{sys._getframe().f_code.co_name}"
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"message": "Sending expiration notification for to targets {}".format(targets),
|
||||||
|
"notification_type": "rotation",
|
||||||
|
"targets": targets,
|
||||||
|
}
|
||||||
status = FAILURE_METRIC_STATUS
|
status = FAILURE_METRIC_STATUS
|
||||||
try:
|
try:
|
||||||
notification.plugin.send(event_type, data, targets, notification.options)
|
notification.plugin.send(event_type, data, targets, notification.options)
|
||||||
status = SUCCESS_METRIC_STATUS
|
status = SUCCESS_METRIC_STATUS
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(
|
log_data["message"] = "Unable to send expiration notification to targets {}".format(targets)
|
||||||
"Unable to send notification to {}.".format(targets), exc_info=True
|
current_app.logger.error(log_data, exc_info=True)
|
||||||
)
|
|
||||||
sentry.captureException()
|
sentry.captureException()
|
||||||
|
|
||||||
metrics.send(
|
metrics.send(
|
||||||
|
@ -190,6 +197,14 @@ def send_rotation_notification(certificate, notification_plugin=None):
|
||||||
:param notification_plugin:
|
:param notification_plugin:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
function = f"{__name__}.{sys._getframe().f_code.co_name}"
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"message": "Sending rotation notification for certificate {}".format(certificate.name),
|
||||||
|
"notification_type": "rotation",
|
||||||
|
"name": certificate.name,
|
||||||
|
"owner": certificate.owner,
|
||||||
|
}
|
||||||
status = FAILURE_METRIC_STATUS
|
status = FAILURE_METRIC_STATUS
|
||||||
if not notification_plugin:
|
if not notification_plugin:
|
||||||
notification_plugin = plugins.get(
|
notification_plugin = plugins.get(
|
||||||
|
@ -202,9 +217,9 @@ def send_rotation_notification(certificate, notification_plugin=None):
|
||||||
notification_plugin.send("rotation", data, [data["owner"]], [])
|
notification_plugin.send("rotation", data, [data["owner"]], [])
|
||||||
status = SUCCESS_METRIC_STATUS
|
status = SUCCESS_METRIC_STATUS
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(
|
log_data["message"] = "Unable to send rotation notification for certificate {0} to ownner {1}" \
|
||||||
"Unable to send notification to {}.".format(data["owner"]), exc_info=True
|
.format(certificate.name, data["owner"])
|
||||||
)
|
current_app.logger.error(log_data)
|
||||||
sentry.captureException()
|
sentry.captureException()
|
||||||
|
|
||||||
metrics.send(
|
metrics.send(
|
||||||
|
@ -228,6 +243,14 @@ def send_pending_failure_notification(
|
||||||
:param notification_plugin:
|
:param notification_plugin:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
function = f"{__name__}.{sys._getframe().f_code.co_name}"
|
||||||
|
log_data = {
|
||||||
|
"function": function,
|
||||||
|
"message": "Sending pending failure notification for pending certificate {}".format(pending_cert.name),
|
||||||
|
"notification_type": "rotation",
|
||||||
|
"name": pending_cert.name,
|
||||||
|
"owner": pending_cert.owner,
|
||||||
|
}
|
||||||
status = FAILURE_METRIC_STATUS
|
status = FAILURE_METRIC_STATUS
|
||||||
|
|
||||||
if not notification_plugin:
|
if not notification_plugin:
|
||||||
|
@ -245,12 +268,10 @@ def send_pending_failure_notification(
|
||||||
notification_plugin.send("failed", data, [data["owner"]], pending_cert)
|
notification_plugin.send("failed", data, [data["owner"]], pending_cert)
|
||||||
status = SUCCESS_METRIC_STATUS
|
status = SUCCESS_METRIC_STATUS
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(
|
log_data["recipient"] = data["owner"]
|
||||||
"Unable to send pending failure notification to {}.".format(
|
log_data["message"] = "Unable to send pending failure notification for certificate {0} to owner {1}" \
|
||||||
data["owner"]
|
.format(pending_cert.name, pending_cert.owner)
|
||||||
),
|
current_app.logger.error(log_data, exc_info=True)
|
||||||
exc_info=True,
|
|
||||||
)
|
|
||||||
sentry.captureException()
|
sentry.captureException()
|
||||||
|
|
||||||
if notify_security:
|
if notify_security:
|
||||||
|
@ -260,11 +281,10 @@ def send_pending_failure_notification(
|
||||||
)
|
)
|
||||||
status = SUCCESS_METRIC_STATUS
|
status = SUCCESS_METRIC_STATUS
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.error(
|
log_data["recipient"] = data["security_email"]
|
||||||
"Unable to send pending failure notification to "
|
log_data["message"] = "Unable to send pending failure notification for certificate {0} to security email " \
|
||||||
"{}.".format(data["security_email"]),
|
"{1}".format(pending_cert.name, pending_cert.owner)
|
||||||
exc_info=True,
|
current_app.logger.error(log_data, exc_info=True)
|
||||||
)
|
|
||||||
sentry.captureException()
|
sentry.captureException()
|
||||||
|
|
||||||
metrics.send(
|
metrics.send(
|
||||||
|
|
Loading…
Reference in New Issue