Module: check_mk
Branch: master
Commit: a58fb32bb127fb888aab5b89e8059d3401ba280f
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=a58fb32bb127fb…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Aug 24 16:37:26 2011 +0200
Fixed log_date sorter
---
web/plugins/views/sorters.py | 17 ++++++++++++++++-
1 files changed, 16 insertions(+), 1 deletions(-)
diff --git a/web/plugins/views/sorters.py b/web/plugins/views/sorters.py
index b2a3836..9e6f87a 100644
--- a/web/plugins/views/sorters.py
+++ b/web/plugins/views/sorters.py
@@ -250,7 +250,22 @@ declare_1to1_sorter("log_type",
cmp_simple_string)
declare_1to1_sorter("log_contact_name", cmp_simple_string)
declare_1to1_sorter("log_time", cmp_simple_number)
declare_1to1_sorter("log_lineno", cmp_simple_number)
-declare_1to1_sorter("log_date", cmp_simple_number)
+
+import time
+def get_day_start_timestamp(t):
+ st = time.localtime(int(t))
+ start = int(time.mktime(time.struct_time((st[0], st[1], st[2], 0, 0, 0, st[6], st[7],
st[8]))))
+ end = start + 86399
+ return start, end
+
+def cmp_date(column, r1, r2):
+ # need to calculate with the timestamp of the day. Using 00:00:00 at the given day.
+ # simply calculating with 86400 does not work because of timezone problems
+ r1_date = get_day_start_timestamp(r1[column])
+ r2_date = get_day_start_timestamp(r2[column])
+ return cmp(r2_date, r1_date)
+
+declare_1to1_sorter("log_date", cmp_date)
# Alert statistics
declare_simple_sorter("alerts_ok", _("Number of recoveries"),
"alerts_ok", cmp_simple_number)