Module: check_mk
Branch: master
Commit: e1ae2035b396c525bf6a091c84c8594a50f7c829
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e1ae2035b396c5…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 21 16:23:42 2016 +0100
3337 FIX Improved error handling of invalid perfdata in the GUI
---
.werks/3337 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/metrics.py | 21 +++++++++++++++------
web/plugins/views/painters.py | 10 ++++++++--
4 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/.werks/3337 b/.werks/3337
new file mode 100644
index 0000000..ceec461
--- /dev/null
+++ b/.werks/3337
@@ -0,0 +1,10 @@
+Title: Improved error handling of invalid perfdata in the GUI
+Level: 1
+Component: multisite
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1458573804
+
+
diff --git a/ChangeLog b/ChangeLog
index 188325f..c10db31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -126,6 +126,7 @@
* 3313 FIX: Set correct mime type when exporting CSV and other non-HTML formats
* 3315 FIX: Builtin icon visibility now can be correctly reset...
* 3336 FIX: Fixed possible crash on werk list page...
+ * 3337 FIX: Improved error handling of invalid perfdata in the GUI
WATO:
* 3244 WATO BI Module: swap order of aggregation function and child node
selection...
diff --git a/web/htdocs/metrics.py b/web/htdocs/metrics.py
index 2403fc0..c6fd8a5 100644
--- a/web/htdocs/metrics.py
+++ b/web/htdocs/metrics.py
@@ -309,6 +309,9 @@ def split_perf_data(perf_data_string):
# Convert perf_data_string into perf_data, extract check_command
+# This methods must not return None or anything else. It mustr strictly
+# return a tuple of perf_data list and the check_command. In case of
+# errors during parsing it returns an empty list for the perf_data.
def parse_perf_data(perf_data_string, check_command=None):
# Strip away arguments like in "check_http!-H mathias-kettner.de"
# FIXME: check_command=None? Fails here!
@@ -322,7 +325,7 @@ def parse_perf_data(perf_data_string, check_command=None):
parts = split_perf_data(perf_data_string)
except ValueError, e:
html.log("Failed to parse perfdata string: %s" % perf_data_string)
- return None, check_command
+ return [], check_command
# Try if check command is appended to performance data
# in a PNP like style
@@ -351,16 +354,18 @@ def parse_perf_data(perf_data_string, check_command=None):
# separate value from unit
i = 0
- while i < len(value_text) and (isdigit(value_text[i]) or value_text[i] in
['.', ',', '-']):
+ while i < len(value_text) and (isdigit(value_text[i])
+ or value_text[i] in ['.', ',',
'-']):
i += 1
+
unit_name = value_text[i:]
- value = value_text[:i]
+ value = float_or_int(value_text[:i])
perf_data.append((varname, value, unit_name, warn, crit, min, max))
except:
+ html.log("Failed to parse perfdata: %s" % perf_data_string)
if config.debug:
raise
- perf_data = None
return perf_data, check_command
@@ -388,6 +393,10 @@ def perfvar_translation(perfvar_nr, perfvar_name, check_command):
}
+def translate_perf_data(perf_data_string, check_command=None):
+ perf_data, check_command = parse_perf_data(perf_data_string, check_command)
+ return translate_metrics(perf_data, check_command)
+
# Convert Ascii-based performance data as output from a check plugin
# into floating point numbers, do scaling if neccessary.
@@ -399,7 +408,7 @@ def translate_metrics(perf_data, check_command):
color_index = 0
for nr, entry in enumerate(perf_data):
varname = entry[0]
- value_text = entry[1]
+ value = entry[1]
translation_entry = perfvar_translation(nr, varname, check_command)
metric_name = translation_entry["name"]
@@ -420,7 +429,7 @@ def translate_metrics(perf_data, check_command):
mi["color"] = parse_color_into_hexrgb(mi["color"])
new_entry = {
- "value" : float_or_int(value_text) *
translation_entry["scale"],
+ "value" : value * translation_entry["scale"],
"orig_name" : varname,
"scale" : translation_entry["scale"], # needed for
graph definitions
"scalar" : {},
diff --git a/web/plugins/views/painters.py b/web/plugins/views/painters.py
index 1daba9a..af517e9 100644
--- a/web/plugins/views/painters.py
+++ b/web/plugins/views/painters.py
@@ -586,8 +586,14 @@ multisite_painters["svc_perf_data"] = {
}
def paint_service_metrics(row):
- translated_metrics =
metrics.translate_metrics(*metrics.parse_perf_data(row["service_perf_data"],
row["service_check_command"]))
- return "", metrics.render_metrics_table(translated_metrics,
row["host_name"], row["service_description"])
+ translated_metrics = metrics.translate_perf_data(row["service_perf_data"],
+
row["service_check_command"])
+
+ if row["service_perf_data"] and not translated_metrics:
+ return "", _("Failed to parse performance data string: %s") %
row["service_perf_data"]
+
+ return "", metrics.render_metrics_table(translated_metrics,
row["host_name"],
+ row["service_description"])
multisite_painters["svc_metrics"] = {
"title" : _("Service Metrics"),