Module: check_mk
Branch: master
Commit: 3ed9eda63fbba1f6b4f181b764954acf989897f4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3ed9eda63fbba1…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Nov 11 09:28:02 2013 +0100
FIX Reduced I/O on logins with access time recording or failed login counts
In previous versions, these optional features were loading the whole user
configuration just to read / change one attribute of one user, which is kept
in a single file. This mechanism has been recoded to only use this single
custom attribute file. Should reduce I/O in large installations during
multisite processing.
---
.werks/204 | 12 +++++++++++
ChangeLog | 1 +
web/htdocs/userdb.py | 55 +++++++++++++++++++++++++-------------------------
3 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/.werks/204 b/.werks/204
new file mode 100644
index 0000000..fbc2294
--- /dev/null
+++ b/.werks/204
@@ -0,0 +1,12 @@
+Title: Reduced I/O on logins with access time recording or failed login counts
+Level: 1
+Component: multisite
+Version: 1.2.3i7
+Date: 1384158368
+Class: fix
+
+In previous versions, these optional features were loading the whole user
+configuration just to read / change one attribute of one user, which is kept
+in a single file. This mechanism has been recoded to only use this single
+custom attribute file. Should reduce I/O in large installations during
+multisite processing.
diff --git a/ChangeLog b/ChangeLog
index 22dfc1f..6df9d74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -22,6 +22,7 @@
* 0046 FIX: Allowing "-" chars in var names again...
* 0049 FIX: Fixed check-mk-automation call on each new created apache thread...
* 0203 FIX: Changed sidebar reload interval to be more random...
+ * 0204 FIX: Reduced I/O on logins with access time recording or failed login
counts...
WATO:
* 0053 New rule for configuring the display_name of a service...
diff --git a/web/htdocs/userdb.py b/web/htdocs/userdb.py
index dab736f..794e64a 100644
--- a/web/htdocs/userdb.py
+++ b/web/htdocs/userdb.py
@@ -124,25 +124,14 @@ def user_locked(username):
def update_user_access_time():
if not config.save_user_access_times:
return
-
- users = load_users(lock = True)
- users[html.user]['last_seen'] = time.time()
- save_users(users)
+ save_custom_attr(html.user, 'last_seen', repr(time.time()))
def on_succeeded_login(username):
- users = load_users(lock = True)
- changed = False
+ num_failed = load_custom_attr(username, 'num_failed', saveint)
+ if num_failed != None and num_failed != 0:
+ save_custom_attr(username, 'num_failed', '0')
- if users[username].get('num_failed', 0) != 0:
- users[username]["num_failed"] = 0
- changed = True
-
- if config.save_user_access_times:
- users[username]['last_seen'] = time.time()
- changed = True
-
- if changed:
- save_users(users)
+ update_user_access_time()
def on_failed_login(username):
users = load_users(lock = True)
@@ -303,12 +292,14 @@ def load_users(lock = False):
id = d
# read special values from own files
- for val, conv_func in [ ('num_failed', saveint),
('last_seen', savefloat) ]:
- if id in result:
- try:
- result[id][val] = conv_func(file(dir + d + '/' + val +
'.mk').read().strip())
- except IOError:
- pass
+ if id in result:
+ num_failed = load_custom_attr(d, 'num_failed', saveint)
+ if num_failed != None:
+ result[id]['num_failed'] = num_failed
+
+ last_seen = load_custom_attr(d, 'last_seen', savefloat)
+ if last_seen != None:
+ result[id]['last_seen'] = last_seen
# read automation secrets and add them to existing
# users or create new users automatically
@@ -327,6 +318,17 @@ def load_users(lock = False):
return result
+def load_custom_attr(userid, key, conv_func, default = None):
+ basedir = defaults.var_dir + "/web/" + userid
+ try:
+ return conv_func(file(basedir + '/' + key +
'.mk').read().strip())
+ except IOError:
+ return default
+
+def save_custom_attr(userid, key, val):
+ basedir = defaults.var_dir + "/web/" + userid
+ create_user_file('%s/%s.mk' % (basedir, key),
'w').write('%s\n' % val)
+
def get_online_user_ids():
online_threshold = time.time() - config.user_online_maxage
users = []
@@ -422,17 +424,14 @@ def save_users(profiles):
os.remove(auth_file)
# Write out the users serial
- serial_file = user_dir + '/serial.mk'
- create_user_file(serial_file, 'w').write('%d\n' %
user.get('serial', 0))
+ save_custom_attr(id, 'serial', str(user.get('serial', 0)))
# Write out the users number of failed login
- failed_file = user_dir + '/num_failed.mk'
- create_user_file(failed_file, 'w').write('%d\n' %
user.get('num_failed', 0))
+ save_custom_attr(id, 'num_failed', str(user.get('num_failed',
0)))
# Write out the last seent time
if 'last_seen' in user:
- last_seen_file = user_dir + '/last_seen.mk'
- create_user_file(last_seen_file,
'w').write(repr(user['last_seen']) + '\n')
+ save_custom_attr(id, 'last_seen', repr(user['last_seen']))
# Remove settings directories of non-existant users.
# Beware: we removed this since it leads to violent destructions