Exemple #1
0
def send_pending_failure_notification(pending_cert,
                                      notify_owner=True,
                                      notify_security=True,
                                      notification_plugin=None):
    """
    Sends a report to certificate owners when their pending certificate failed to be created.

    :param pending_cert:
    :param notification_plugin:
    :return:
    """
    status = FAILURE_METRIC_STATUS

    if not notification_plugin:
        notification_plugin = plugins.get(
            current_app.config.get("LEMUR_DEFAULT_NOTIFICATION_PLUGIN",
                                   "email-notification"))

    data = pending_certificate_output_schema.dump(pending_cert).data
    data["security_email"] = current_app.config.get(
        "LEMUR_SECURITY_TEAM_EMAIL")

    if notify_owner:
        try:
            notification_plugin.send("failed", data, [data["owner"]],
                                     pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            current_app.logger.error(
                "Unable to send pending failure notification to {}.".format(
                    data["owner"]),
                exc_info=True,
            )
            sentry.captureException()

    if notify_security:
        try:
            notification_plugin.send("failed", data, data["security_email"],
                                     pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            current_app.logger.error(
                "Unable to send pending failure notification to "
                "{}.".format(data["security_email"]),
                exc_info=True,
            )
            sentry.captureException()

    metrics.send(
        "notification",
        "counter",
        1,
        metric_tags={
            "status": status,
            "event_type": "rotation"
        },
    )

    if status == SUCCESS_METRIC_STATUS:
        return True
Exemple #2
0
def send_pending_failure_notification(pending_cert,
                                      notify_owner=True,
                                      notify_security=True):
    """
    Sends a report to certificate owners when their pending certificate failed to be created.

    :param pending_cert:
    :param notify_owner:
    :param notify_security:
    :return:
    """

    data = pending_certificate_output_schema.dump(pending_cert).data
    data["security_email"] = current_app.config.get(
        "LEMUR_SECURITY_TEAM_EMAIL")

    email_recipients = []
    if notify_owner:
        email_recipients = email_recipients + [data["owner"]]

    if notify_security:
        email_recipients = email_recipients + data["security_email"]

    return send_default_notification("failed", data, email_recipients,
                                     pending_cert)
Exemple #3
0
def send_pending_failure_notification(pending_cert,
                                      notify_owner=True,
                                      notify_security=True):
    """
    Sends a report to certificate owners when their pending certificate failed to be created.

    :param pending_cert:
    :param notify_owner:
    :param notify_security:
    :return:
    """

    data = pending_certificate_output_schema.dump(pending_cert).data
    data["security_email"] = current_app.config.get(
        "LEMUR_SECURITY_TEAM_EMAIL")

    notify_owner_success = False
    if notify_owner:
        notify_owner_success = send_default_notification(
            "failed", data, [data["owner"]], pending_cert)

    notify_security_success = False
    if notify_security:
        notify_security_success = send_default_notification(
            "failed", data, data["security_email"], pending_cert)

    return notify_owner_success or notify_security_success
Exemple #4
0
def send_pending_failure_notification(pending_cert,
                                      notify_owner=True,
                                      notify_security=True,
                                      notification_plugin=None):
    """
    Sends a report to certificate owners when their pending certificate failed to be created.

    :param pending_cert:
    :param notification_plugin:
    :return:
    """
    status = FAILURE_METRIC_STATUS

    if not notification_plugin:
        notification_plugin = plugins.get(
            current_app.config.get('LEMUR_DEFAULT_NOTIFICATION_PLUGIN',
                                   'email-notification'))

    data = pending_certificate_output_schema.dump(pending_cert).data
    data["security_email"] = current_app.config.get(
        'LEMUR_SECURITY_TEAM_EMAIL')

    if notify_owner:
        try:
            notification_plugin.send('failed', data, [data['owner']],
                                     pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            current_app.logger.error(
                'Unable to send pending failure notification to {}.'.format(
                    data['owner']),
                exc_info=True)
            sentry.captureException()

    if notify_security:
        try:
            notification_plugin.send('failed', data, data["security_email"],
                                     pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            current_app.logger.error(
                'Unable to send pending failure notification to '
                '{}.'.format(data['security_email']),
                exc_info=True)
            sentry.captureException()

    metrics.send('notification',
                 'counter',
                 1,
                 metric_tags={
                     'status': status,
                     'event_type': 'rotation'
                 })

    if status == SUCCESS_METRIC_STATUS:
        return True
Exemple #5
0
def send_pending_failure_notification(pending_cert, notify_owner=True, notify_security=True, notification_plugin=None):
    """
    Sends a report to certificate owners when their pending certificate failed to be created.

    :param pending_cert:
    :param notification_plugin:
    :return:
    """
    status = FAILURE_METRIC_STATUS

    if not notification_plugin:
        notification_plugin = plugins.get(
            current_app.config.get('LEMUR_DEFAULT_NOTIFICATION_PLUGIN', 'email-notification')
        )

    data = pending_certificate_output_schema.dump(pending_cert).data
    data["security_email"] = current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL')

    if notify_owner:
        try:
            notification_plugin.send('failed', data, [data['owner']], pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            current_app.logger.error('Unable to send pending failure notification to {}.'.format(data['owner']),
                                     exc_info=True)
            sentry.captureException()

    if notify_security:
        try:
            notification_plugin.send('failed', data, data["security_email"], pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            current_app.logger.error('Unable to send pending failure notification to '
                                     '{}.'.format(data['security_email']),
                                     exc_info=True)
            sentry.captureException()

    metrics.send('notification', 'counter', 1, metric_tags={'status': status, 'event_type': 'rotation'})

    if status == SUCCESS_METRIC_STATUS:
        return True
Exemple #6
0
def send_pending_failure_notification(
    pending_cert, notify_owner=True, notify_security=True, notification_plugin=None
):
    """
    Sends a report to certificate owners when their pending certificate failed to be created.

    :param pending_cert:
    :param notification_plugin:
    :return:
    """
    function = f"{__name__}.{sys._getframe().f_code.co_name}"
    log_data = {
        "function": function,
        "message": f"Sending pending failure notification for pending certificate {pending_cert}",
        "notification_type": "failed",
        "certificate_name": pending_cert.name,
        "certificate_owner": pending_cert.owner,
    }
    status = FAILURE_METRIC_STATUS

    if not notification_plugin:
        notification_plugin = plugins.get(
            current_app.config.get(
                "LEMUR_DEFAULT_NOTIFICATION_PLUGIN", "email-notification"
            )
        )

    data = pending_certificate_output_schema.dump(pending_cert).data
    data["security_email"] = current_app.config.get("LEMUR_SECURITY_TEAM_EMAIL")

    if notify_owner:
        try:
            notification_plugin.send("failed", data, [data["owner"]], pending_cert)
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            log_data["recipient"] = data["owner"]
            log_data["message"] = f"Unable to send pending failure notification for certificate {pending_cert.name} " \
                                  f"to owner {pending_cert.owner}"
            current_app.logger.error(log_data, exc_info=True)
            sentry.captureException()

    if notify_security:
        try:
            notification_plugin.send(
                "failed", data, data["security_email"], pending_cert
            )
            status = SUCCESS_METRIC_STATUS
        except Exception as e:
            log_data["recipient"] = data["security_email"]
            log_data["message"] = f"Unable to send pending failure notification for certificate {pending_cert.name} " \
                                  f"to security email {pending_cert.owner}"
            current_app.logger.error(log_data, exc_info=True)
            sentry.captureException()

    metrics.send(
        "notification",
        "counter",
        1,
        metric_tags={"status": status, "event_type": "failed"},
    )

    if status == SUCCESS_METRIC_STATUS:
        return True