Module: check_mk
Branch: master
Commit: d5f883ad87b1a5470efe4f65915a583f49d4fc12
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d5f883ad87b1a5…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jun 17 16:44:55 2015 +0200
Allow new color specifications in metrics - palette still missing, though
---
web/htdocs/metrics.py | 48 ++++++++++++++++++++++++++++++++++++---
web/plugins/metrics/check_mk.py | 2 +-
2 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 1e7882d..a67848b 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -34,7 +34,7 @@
# unit: The definition-dict of a unit like in unit_info
# graph_template: Template for a graph. Essentially a dict with the key
"metrics"
-import math, time
+import math, time, colorsys
import config, defaults, pagetypes, table
from lib import *
from valuespec import *
@@ -141,6 +141,48 @@ def metric_to_text(metric, value=None):
# A few helper function to be used by the definitions
+#.
+# .--Colors--------------------------------------------------------------.
+# | ____ _ |
+# | / ___|___ | | ___ _ __ ___ |
+# | | | / _ \| |/ _ \| '__/ __| |
+# | | |__| (_) | | (_) | | \__ \ |
+# | \____\___/|_|\___/|_| |___/ |
+# | |
+# +----------------------------------------------------------------------+
+# | Functions and constants dealing with colors |
+# '----------------------------------------------------------------------'
+
+cmk_color_palette = {
+ "24" : (0.5, 1.0, 1.0),
+ "25" : (0.7, 1.0, 1.0),
+}
+
+# 23/c -> #ff8040
+# #ff8040 -> #ff8040
+def parse_color_into_hexrgb(color_string):
+ if color_string[0] == "#":
+ return color_string
+ elif "/" in color_string:
+ cmk_color_index, color_shading = color_string.split("/")
+ hsv = list(cmk_color_palette[cmk_color_index])
+ if color_shading == 'a':
+ hsv[2] *= 0.6
+ elif color_shading == 'b':
+ hsv[2] *= 0.8
+ elif color_shading == 'd':
+ hsv[1] *= 0.8
+ elif color_shading == 'e':
+ hsv[1] *= 0.6
+ color_hexrgb = hsv_to_hexrgb(hsv)
+ return color_hexrgb
+ else:
+ return "#808080"
+
+
+def hsv_to_hexrgb(hsv):
+ return render_color(colorsys.hsv_to_rgb(*hsv))
+
# "#ff0080" -> (1.0, 0.0, 0.5)
def parse_color(color):
@@ -459,7 +501,7 @@ def evaluate_literal(expression, translated_metrics):
unit = translated_metrics[varname]["unit"]
if color == None:
- color = metric_info[varname]["color"]
+ color = parse_color_into_hexrgb(metric_info[varname]["color"])
return value, unit, color
@@ -912,7 +954,7 @@ def render_graph_pnp(graph_template, translated_metrics):
mi = metric_info[metric_name]
if not title:
title = mi["title"]
- color = mi["color"]
+ color = parse_color_into_hexrgb(mi["color"])
unit = unit_info[mi["unit"]]
if custom_color:
diff --git a/web/plugins/metrics/check_mk.py b/web/plugins/metrics/check_mk.py
index 48735ec..12d2d9c 100644
--- a/web/plugins/metrics/check_mk.py
+++ b/web/plugins/metrics/check_mk.py
@@ -433,7 +433,7 @@ metric_info["mem_lnx_vmalloc_chunk"] = {
metric_info["load1"] = {
"title" : _("CPU load average of last minute"),
"unit" : "",
- "color" : "#60c0e0",
+ "color" : "24/e",
}
metric_info["load5"] = {