Module: check_mk
Branch: master
Commit: abfe2257fb9ed6c220501810fbe3999f5ad39169
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=abfe2257fb9ed6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Feb 6 08:51:54 2017 +0100
LDAP sync: Create only a single WATO change entry per LDAP sync run
Change-Id: I48220c027a47d37b142c74250638ada075ae62be
---
web/plugins/userdb/ldap.py | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/web/plugins/userdb/ldap.py b/web/plugins/userdb/ldap.py
index ea6b2d0..5c10d00 100644
--- a/web/plugins/userdb/ldap.py
+++ b/web/plugins/userdb/ldap.py
@@ -928,6 +928,8 @@ class LDAPUserConnector(UserConnector):
import wato
users = load_users(lock = True)
+ changes = []
+
def load_user(user_id):
if user_id in users:
user = copy.deepcopy(users[user_id])
@@ -944,8 +946,7 @@ class LDAPUserConnector(UserConnector):
if user_connection_id == connection_id and self.strip_suffix(user_id) not in
ldap_users:
del users[user_id] # remove the user
if config.wato_enabled:
- wato.add_change("edit-users",
- _("LDAP [%s]: Removed user %s") % (connection_id,
user_id), add_user=False)
+ changes.append(_("LDAP [%s]: Removed user %s") %
(connection_id, user_id))
for user_id, ldap_user in ldap_users.items():
mode_create, user = load_user(user_id)
@@ -986,10 +987,8 @@ class LDAPUserConnector(UserConnector):
changed = self.find_changed_user_keys(intersect, users[user_id], user) #
returns a dict
users[user_id] = user # Update the user record
- if mode_create:
- if config.wato_enabled:
- wato.add_change("edit-users",
- _("LDAP [%s]: Created user %s") %
(connection_id, user_id), add_user=False)
+ if mode_create and config.wato_enabled:
+ changes.append(_("LDAP [%s]: Created user %s") %
(connection_id, user_id))
else:
details = []
if added:
@@ -1017,13 +1016,13 @@ class LDAPUserConnector(UserConnector):
details.append(('Changed %s from %s to %s' % (key,
old_value, new_value)))
if details and config.wato_enabled:
- wato.add_change("edit-users",
- _("LDAP [%s]: Modified user %s (%s)") %
(connection_id, user_id, ', '.join(details)),
- add_user=False)
+ changes.append(_("LDAP [%s]: Modified user %s (%s)") %
(connection_id, user_id, ', '.join(details)))
duration = time.time() - start_time
self.log('SYNC FINISHED - Duration: %0.3f sec' % duration)
+ wato.add_change("edit-users", "\n".join(changes),
add_user=False)
+
# delete the fail flag file after successful sync
try:
os.unlink(self._sync_fail_file)