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)\ .filter(Notification.active == True).all() # noqa messages = [] for n in notifications: for certificate in n.certificates: if needs_notification(certificate): data = certificate_notification_output_schema.dump( certificate).data messages.append((data, n.options)) for data, options in messages: try: 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, notification_plugin=None): """ Sends a report to certificate owners when their certificate has been rotated. :param certificate: :param notification_plugin: :return: """ status = FAILURE_METRIC_STATUS 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: notification_plugin.send('rotation', data, [data['owner']]) status = SUCCESS_METRIC_STATUS except Exception as e: sentry.captureException() metrics.send('notification', 'counter', 1, metric_tags={'status': status, 'event_type': 'rotation'}) if status == SUCCESS_METRIC_STATUS: return True
def send_notification(event_type, data, targets, notification): """ Executes the plugin and handles failure. :param event_type: :param data: :param targets: :param notification: :return: """ try: notification.plugin.send(event_type, data, targets, notification.options) metrics.send('{0}_notification_sent'.format(event_type), 'counter', 1) return True except Exception as e: metrics.send('{0}_notification_failure'.format(event_type), 'counter', 1) current_app.logger.exception(e)
def send_notification(event_type, data, targets, notification): """ Executes the plugin and handles failure. :param event_type: :param data: :param targets: :param notification: :return: """ try: notification.plugin.send(event_type, data, targets, notification.options) metrics.send('{0}_notification_sent'.format(event_type), 'counter', 1) return True except Exception as e: sentry.captureException() metrics.send('{0}_notification_failure'.format(event_type), 'counter', 1) current_app.logger.exception(e)
def send_rotation_notification(certificate, notification_plugin=None): """ Sends a report to certificate owners when their certificate as been rotated. :param certificate: :return: """ 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: notification_plugin.send('rotation', data, [data['owner']]) metrics.send('rotation_notification_sent', 'counter', 1) return True except Exception as e: metrics.send('rotation_notification_failure', 'counter', 1) current_app.logger.exception(e)
def send_rotation_notification(certificate, notification_plugin=None): """ Sends a report to certificate owners when their certificate as been rotated. :param certificate: :return: """ 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: notification_plugin.send('rotation', data, [data['owner']]) metrics.send('rotation_notification_sent', 'counter', 1) return True except Exception as e: sentry.captureException() metrics.send('rotation_notification_failure', 'counter', 1) current_app.logger.exception(e)
def send_notification(event_type, data, targets, notification): """ Executes the plugin and handles failure. :param event_type: :param data: :param targets: :param notification: :return: """ status = FAILURE_METRIC_STATUS try: notification.plugin.send(event_type, data, targets, notification.options) status = SUCCESS_METRIC_STATUS except Exception as e: sentry.captureException() metrics.send('notification', 'counter', 1, metric_tags={'status': status, 'event_type': event_type}) if status == SUCCESS_METRIC_STATUS: return True