Module: check_mk
Branch: master
Commit: b807740ecb9d91cb6168b269c411287e12f3148c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b807740ecb9d91…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Sep 8 17:15:06 2011 +0200
Service Perfdata Sorters are sorting correctly now
---
ChangeLog | 1 +
web/plugins/views/painters.py | 21 +++++++++++++--------
web/plugins/views/sorters.py | 20 ++++++++++----------
3 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f7c6aa5..4192dfb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,7 @@
* FIX: fix rescheduling of host check
* Added some missing i18n strings in general HTML functions
* Added display_option "w" to disable limit messages and livestatus errors
in views
+ * Service Perfdata Sorters are sorting correctly now
1.1.11i4:
Core, Setup, etc.:
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index f2df0b8..d1a1e52 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -314,21 +314,26 @@ multisite_painters["svc_perf_data"] = {
"paint" : lambda row: (None, row["service_perf_data"])
}
-def paint_perfdata_nth_value(row, n):
- perfdata = row["service_perf_data"]
+def get_perfdata_nth_value(row, n, remove_unit = False):
+ perfdata = row.get("service_perf_data")
+ if not perfdata:
+ return ''
try:
parts = perfdata.split()
if len(parts) <= n:
- return "", "" # too few values in perfdata
+ return "" # too few values in perfdata
varname, rest = parts[n].split("=")
number = rest.split(';')[0]
- # Remove unit. Why should we?
- # while len(number) > 0 and not number[-1].isdigit():
- # number = number[:-1]
- return "", number
+ # Remove unit. Why should we? In case of sorter (numeric)
+ if remove_unit:
+ while len(number) > 0 and not number[-1].isdigit():
+ number = number[:-1]
+ return number
except Exception, e:
- return "", str(e)
+ return str(e)
+def paint_perfdata_nth_value(row, n):
+ return "", get_perfdata_nth_value(row, n)
multisite_painters["svc_perf_val01"] = {
"title" : _("Service performance data - value number 1"),
diff --git a/web/plugins/views/sorters.py b/web/plugins/views/sorters.py
index 16482f3..b8cfae5 100644
--- a/web/plugins/views/sorters.py
+++ b/web/plugins/views/sorters.py
@@ -155,16 +155,16 @@ declare_1to1_sorter("svc_notifications_enabled",
cmp_simple_number)
declare_1to1_sorter("svc_is_active", cmp_simple_number)
declare_1to1_sorter("svc_group_memberlist", cmp_string_list)
declare_1to1_sorter("svc_acknowledged", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val01", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val02", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val03", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val04", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val05", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val06", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val07", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val08", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val09", cmp_simple_number)
-declare_1to1_sorter("svc_perf_val10", cmp_simple_number)
+
+def cmp_perfdata_nth_value(r1, r2, n):
+ return cmp(get_perfdata_nth_value(r1, n), get_perfdata_nth_value(r2, n))
+
+for n in range(1, 10):
+ multisite_sorters['svc_perf_val%02d' % n] = {
+ "title" : _("Service performance data - value number %02d"
% n),
+ "columns" : [ 'service_perf_data' ],
+ "cmp" : lambda r1, r2: cmp(get_perfdata_nth_value(r1, n - 1),
get_perfdata_nth_value(r2, n - 1))
+ }
# Host
declare_1to1_sorter("alias", cmp_simple_string)