Module: check_mk
Branch: master
Commit: 230af936e731fa264a1dfe378334d19be4d25213
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=230af936e731fa…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Nov 9 13:26:39 2018 +0100
6678 Added new hostname painter with configurable colors
Change-Id: I01bb0bc6e1a0f03bb6096fd47b9d965000b384f3
---
.werks/6678 | 18 ++++++++++
cmk/gui/plugins/views/painters.py | 71 +++++++++++++++++++++++++++++++++++----
2 files changed, 82 insertions(+), 7 deletions(-)
diff --git a/.werks/6678 b/.werks/6678
new file mode 100644
index 0000000..b902905
--- /dev/null
+++ b/.werks/6678
@@ -0,0 +1,18 @@
+Title: The hostname painter now has configurable background colors
+Level: 1
+Component: multisite
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1541766366
+Class: feature
+
+In addition you can also configure that the background color changes if the host is in
downtime.
+The following coloring options are now available
+<ul>
+<li>Colorize background if host is up</li>
+<li>Colorize background if host is down</li>
+<li>Colorize background if host is unreachable</li>
+<li>Colorize background if host is pending</li>
+<li>Colorize background if host is in downtime</li>
+</ul>
diff --git a/cmk/gui/plugins/views/painters.py b/cmk/gui/plugins/views/painters.py
index b254b83..92eb0d5 100644
--- a/cmk/gui/plugins/views/painters.py
+++ b/cmk/gui/plugins/views/painters.py
@@ -79,6 +79,8 @@ from cmk.gui.valuespec import (
Timerange,
DropdownChoice,
DateFormat,
+ Dictionary,
+ ListChoice,
)
from . import (
@@ -1216,7 +1218,7 @@ def paint_host_black(row):
multisite_painters["host_black"] = {
- "title": _("Hostname, red background if down or unreachable"),
+ "title": _("Hostname, red background if down or unreachable
(Deprecated)"),
"short": _("Host"),
"columns": ["site", "host_name",
"host_state"],
"paint": paint_host_black,
@@ -1261,21 +1263,76 @@ def paint_host_with_state(row):
multisite_painters["host_with_state"] = {
- "title": _("Hostname, marked red if down"),
+ "title": _("Hostname, marked red if down (Deprecated)"),
"short": _("Host"),
"columns": ["site", "host_name",
"host_state", "host_has_been_checked"],
"paint": paint_host_with_state,
"sorter": 'site_host',
}
+
+def paint_hostname_configurable(row, cell):
+ params = cell.painter_parameters()
+ color_choices = params["color_choices"]
+
+ if row["host_has_been_checked"]:
+ state = row["host_state"]
+ else:
+ state = "p"
+
+ css = ["nobr"]
+ if "colorize_downtime" in color_choices and
row["host_scheduled_downtime_depth"] > 0:
+ css.extend(["hstate", "hstated"])
+
+ # Also apply other css classes, even if its already in downtime
+ for key, option_state in [
+ ("colorize_up", 0),
+ ("colorize_down", 1),
+ ("colorize_unreachable", 2),
+ ("colorize_pending", "p"),
+ ]:
+ if key in color_choices and state == option_state:
+ if "hstate" not in css:
+ css.append("hstate")
+ css.append("hstate%s" % option_state)
+ break
+
+ return " ".join(css), row["host_name"]
+
+
+def params_hostname_configurable():
+ elements = [
+ ("color_choices", ListChoice(
+ choices = [
+ ("colorize_up", _("Colorize background if host is
up")),
+ ("colorize_down", _("Colorize background if host is
down")),
+ ("colorize_unreachable", _("Colorize background if
host unreachable")),
+ ("colorize_pending", _("Colorize background if host is
pending")),
+ ("colorize_downtime", _("Colorize background if host
is downtime"))
+ ],
+ title=_("Coloring"),
+ help=_("Here you can configure the background color for specific
states. "
+ "The coloring for host in dowtime overrules all other
coloring.")
+ ))
+ ]
+
+ return Dictionary(
+ elements = elements,
+ title = _("Options"),
+ optional_keys = []
+ )
+
+
multisite_painters["host"] = {
- "title": _("Hostname"),
- "short": _("Host"),
- "columns": ["host_name"],
- "paint": lambda row: ("nobr", row["host_name"]),
- "sorter": 'site_host',
+ "title" : _("Hostname, with configurable colors"),
+ "short" : _("Host"),
+ "columns" : ["host_name", "host_state",
"host_has_been_checked", "host_scheduled_downtime_depth"],
+ "params": params_hostname_configurable,
+ "paint" : paint_hostname_configurable,
+ "sorter" : 'site_host',
}
+
multisite_painters["alias"] = {
"title": _("Host alias"),
"short": _("Alias"),