diff --git a/lemur/certificates/schemas.py b/lemur/certificates/schemas.py index 072cb653..ea9616bc 100644 --- a/lemur/certificates/schemas.py +++ b/lemur/certificates/schemas.py @@ -207,7 +207,8 @@ class CertificateNotificationOutputSchema(LemurOutputSchema): name = fields.String() owner = fields.Email() user = fields.Nested(UserNestedOutputSchema) - replaces = fields.Nested(CertificateNestedOutputSchema, many=True) + validity_end = ArrowDateTime(attribute='not_after') + replaced = fields.Nested(CertificateNestedOutputSchema, many=True) endpoints = fields.Nested(EndpointNestedOutputSchema, many=True, missing=[]) diff --git a/lemur/notifications/messaging.py b/lemur/notifications/messaging.py index cfff37b7..49f4dbac 100644 --- a/lemur/notifications/messaging.py +++ b/lemur/notifications/messaging.py @@ -24,6 +24,7 @@ def send_expiration_notifications(): This function will check for upcoming certificate expiration, and send out notification emails at given intervals. """ + sent = 0 for plugin in plugins.all(plugin_type='notification'): notifications = database.db.session.query(Notification)\ .filter(Notification.plugin_name == plugin.slug)\ @@ -36,16 +37,18 @@ def send_expiration_notifications(): data = certificate_notification_output_schema.dump(certificate).data messages.append((data, n.options)) - for data, targets, options in messages: + for data, options in messages: try: - plugin.send('expiration', data, targets, options) + plugin.send('expiration', data, [data['owner']], options) metrics.send('expiration_notification_sent', 'counter', 1) + sent += 1 except Exception as e: metrics.send('expiration_notification_failure', 'counter', 1) current_app.logger.exception(e) + return sent -def send_rotation_notification(certificate): +def send_rotation_notification(certificate, notification_plugin=None): """ Sends a report to certificate owners when their certificate as been rotated. @@ -53,12 +56,13 @@ def send_rotation_notification(certificate): :param certificate: :return: """ - plugin = plugins.get(current_app.config.get('LEMUR_DEFAULT_NOTIFICATION_PLUGIN')) + if not notification_plugin: + notification_plugin = plugins.get(current_app.config.get('LEMUR_DEFAULT_NOTIFICATION_PLUGIN')) data = certificate_notification_output_schema.dump(certificate).data try: - plugin.send('rotation', data, [data.owner]) + notification_plugin.send('rotation', data, [data['owner']]) metrics.send('rotation_notification_sent', 'counter', 1) except Exception as e: metrics.send('rotation_notification_failure', 'counter', 1) diff --git a/lemur/plugins/bases/notification.py b/lemur/plugins/bases/notification.py index 36e94ef3..d1b63c44 100644 --- a/lemur/plugins/bases/notification.py +++ b/lemur/plugins/bases/notification.py @@ -16,7 +16,7 @@ class NotificationPlugin(Plugin): """ type = 'notification' - def send(self): + def send(self, notification_type, message, targets, options, **kwargs): raise NotImplementedError @@ -48,5 +48,5 @@ class ExpirationNotificationPlugin(NotificationPlugin): def options(self): return list(self.default_options) + self.additional_options - def send(self): + def send(self, notification_type, message, targets, options, **kwargs): raise NotImplementedError diff --git a/lemur/plugins/lemur_email/plugin.py b/lemur/plugins/lemur_email/plugin.py index 65e2ee09..c98cd2a2 100644 --- a/lemur/plugins/lemur_email/plugin.py +++ b/lemur/plugins/lemur_email/plugin.py @@ -85,10 +85,10 @@ class EmailNotificationPlugin(ExpirationNotificationPlugin): raise InvalidConfiguration('Email sender type {0} is not recognized.') @staticmethod - def send(template_name, message, targets, **kwargs): - subject = 'Lemur: Expiration Notification' + def send(notification_type, message, targets, options, **kwargs): + subject = 'Lemur: {0} Notification'.format(notification_type.capitalize()) - body = render_html(template_name, message) + body = render_html(notification_type, message) s_type = current_app.config.get("LEMUR_EMAIL_SENDER", 'ses').lower() diff --git a/lemur/plugins/lemur_email/templates/expiration.html b/lemur/plugins/lemur_email/templates/expiration.html index 969d229f..8c2f8eab 100644 --- a/lemur/plugins/lemur_email/templates/expiration.html +++ b/lemur/plugins/lemur_email/templates/expiration.html @@ -79,18 +79,18 @@
- {{ message.name }}
+ {{ certificate.name }}
- {{ message.endpoints | length }} Endpoints - {{ message.owner }} - {{ message.not_after | time }} - Details + {{ certificate.endpoints | length }} Endpoints + {{ certificate.owner }} + {{ certificate.validityEnd | time }} + Details |
||||
- Your certificate(s) have been rotated! + Your certificate has been rotated! | ||||
- Impacted Certificate: - | -||||
|
||||
- Impacted Endpoints: + | + Replaced by: | |||
+ | + |
+ {{ certificate.replaced.name }}
+ + + {{ certificate.replaced[0].owner }} + {{ certificate.replaced[0].validityEnd | time }} + Details + + |
+
- {{ message.name }}
+ {{ endpoint.name }}
- {{ message.endpoints | length }} Endpoints - {{ message.owner }} - {{ message.not_after | time }} - Details + {{ endpoint.dnsname }} | {{ endpoint.port }} + Details |