Module: check_mk
Branch: master
Commit: 820b7070149faae2e94ddd87ff7d6ba4dbb8845c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=820b7070149faa…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon May 11 12:52:17 2015 +0200
Matrix layout: hilite cells if value differs from majority
---
.werks/2228 | 5 +++++
web/htdocs/views.css | 7 ++++++
web/plugins/views/layouts.py | 49 +++++++++++++++++++++++++++++++++++++-----
3 files changed, 56 insertions(+), 5 deletions(-)
diff --git a/.werks/2228 b/.werks/2228
index 3de2b19..82e2281 100644
--- a/.werks/2228
+++ b/.werks/2228
@@ -17,3 +17,8 @@ This new layout has been used to create two new views: a global view
<i>Search
performance data</i> in the topic <i>Metrics</i> and one that can be
accessed
in the details of a host group. Both show all services of the selected hosts
of of the search in a host by services matrix. Simply try it out!
+
+If one line in a matrix view has the same value for a majority of entries
+then all entries with differing values will be hilighted. That way you can
+use the matrix layout in order to find configuration differences between
+the same service on different hosts.
diff --git a/web/htdocs/views.css b/web/htdocs/views.css
index ed32cf1..69a0bc1 100644
--- a/web/htdocs/views.css
+++ b/web/htdocs/views.css
@@ -416,6 +416,13 @@ table.data.matrix tr.matrixhead td.left {
color: white;
}
+table.data.matrix tr.even0 td.minority {
+ background-color: #cff;
+}
+table.data.matrix tr.odd0 td.minority {
+ background-color: #dff;
+}
+
table.data.single td.gap {
background-color: transparent;
diff --git a/web/plugins/views/layouts.py b/web/plugins/views/layouts.py
index 25a69c3..43cfe49 100644
--- a/web/plugins/views/layouts.py
+++ b/web/plugins/views/layouts.py
@@ -520,6 +520,8 @@ multisite_layouts["table"] = {
def render_matrix(rows, view, group_painters, painters, num_columns,
_ignore_show_checkboxes):
+ majorities = matrix_find_majorities(rows, group_painters, painters)
+
for groups, unique_row_ids, matrix_cells in \
create_matrices(rows, group_painters, painters, num_columns):
@@ -549,20 +551,57 @@ def render_matrix(rows, view, group_painters, painters, num_columns,
_ignore_sho
if cell_row == None:
html.write("<td></td>")
else:
- if len(painters) == 2:
- paint(painters[1], cell_row)
- else:
+ if len(painters) > 2:
html.write("<td class=cell><table>")
- for p in painters[1:]:
+ for painter_nr, p in enumerate(painters[1:]):
+ tdclass, content = prepare_paint(p, cell_row)
+ gv = group_value(cell_row, [p])[0]
+ majority_value = majorities[row_id].get(painter_nr, None)
+ if majority_value != None and majority_value != gv:
+ tdclass += " minority"
+ if len(painters) > 2:
html.write("<tr>")
- paint(p, cell_row)
+ html.write('<td class="%s">%s</td>'
% (tdclass, content))
+ if len(painters) > 2:
html.write("</tr>")
+ if len(painters) > 2:
html.write("</table></td>")
html.write('</tr>')
html.write("</table>")
+def matrix_find_majorities(rows, group_painters, painters):
+ counts = {} # dict row_id -> painter_nr -> value -> count
+
+ for row in rows:
+ group_id = tuple(group_value(row, group_painters))
+ row_id = tuple(group_value(row, [ painters[0] ]))
+ for painter_nr, painter in enumerate(painters[1:]):
+ value = group_value(row, [painter])[0]
+ row_entry = counts.setdefault(row_id, {})
+ painter_entry = row_entry.setdefault(painter_nr, {})
+ painter_entry.setdefault(value, 0)
+ painter_entry[value] += 1
+
+ # Now find majorities for each row
+ majorities = {} # row_id -> painter_nr -> majority value
+ for row_id, row_entry in counts.items():
+ maj_entry = majorities.setdefault(row_id, {})
+ for painter_nr, painter_entry in row_entry.items():
+ maj_value = None
+ max_count = 0
+ for value, count in painter_entry.items():
+ if count == max_count:
+ maj_value = None # No majority
+ elif count > max_count and count >= 2:
+ maj_value = value
+ max_count = count
+ maj_entry[painter_nr] = maj_value
+
+
+ return majorities
+
# Create list of matrices to render
def create_matrices(rows, group_painters, painters, num_columns):