From 98318953cdb2daf69cf387edb66b5602f530bf9b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 9 Apr 2021 12:17:27 +0200 Subject: [PATCH] sources/ldap: create event when user integrity error occurs Signed-off-by: Jens Langhammer --- authentik/sources/ldap/sync/users.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/authentik/sources/ldap/sync/users.py b/authentik/sources/ldap/sync/users.py index 5100189b5..55ffbca1c 100644 --- a/authentik/sources/ldap/sync/users.py +++ b/authentik/sources/ldap/sync/users.py @@ -7,6 +7,7 @@ from django.db.utils import IntegrityError from pytz import UTC from authentik.core.models import User +from authentik.events.models import Event, EventAction from authentik.sources.ldap.sync.base import LDAP_UNIQUENESS, BaseLDAPSynchronizer @@ -48,13 +49,16 @@ class UserLDAPSynchronizer(BaseLDAPSynchronizer): } ) except IntegrityError as exc: - self._logger.warning("Failed to create user", exc=exc) - self._logger.warning( - ( + Event.new( + EventAction.CONFIGURATION_ERROR, + message=( + f"Failed to create user: {str(exc)} " "To merge new user with existing user, set the user's " f"Attribute '{LDAP_UNIQUENESS}' to '{uniq}'" - ) - ) + ), + source=self._source, + dn=user_dn, + ).save() else: self._logger.debug( "Synced User", user=ak_user.username, created=created