Module: check_mk
Branch: master
Commit: c704f5ed1883420eebd08bfdfe0f019326814e4c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c704f5ed188342…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jan 19 15:32:18 2016 +0100
#2927 FIX Fix links to logwatch logfiles in case of several special characters in the
name
If you have logfile that contain brackets then now the icon from the logwatch service
to the GUI works.
---
.werks/2927 | 10 ++++++++++
ChangeLog | 1 +
web/htdocs/htmllib.py | 6 +++++-
web/htdocs/logwatch.py | 34 +++++++++++++++++++++++++++++++---
web/plugins/wato/bi.py | 5 +++++
5 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/.werks/2927 b/.werks/2927
new file mode 100644
index 0000000..c43a353
--- /dev/null
+++ b/.werks/2927
@@ -0,0 +1,10 @@
+Title: Fix links to logwatch logfiles in case of several special characters in the name
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i4
+Date: 1453213894
+Class: fix
+
+If you have logfile that contain brackets then now the icon from the logwatch service
+to the GUI works.
diff --git a/ChangeLog b/ChangeLog
index caa14c9..373c413 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -188,6 +188,7 @@
* 2888 FIX: citrix_controller.licensing: ignoring double data from piggy backs
* 2899 FIX: ps: Finally improved performance impact of perfdata when having a lot of
processes...
* 2917 FIX: cisco_asa_failover: Will no longer discover on devices where failover is
disabled...
+ * 2927 FIX: Fix links to logwatch logfiles in case of several special characters in
the name...
Multisite:
* 2684 Added icons for downloading agent data / walks of hosts...
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index a354f3b..c334b13 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1382,7 +1382,11 @@ class html(GUITester):
def debug(self, *x):
import pprint
for element in x:
- self.lowlevel_write("<pre>%s</pre>\n" %
self.attrencode(pprint.pformat(element)))
+ try:
+ formatted = pprint.pformat(element)
+ except UnicodeDecodeError:
+ formatted = repr(element)
+ self.lowlevel_write("<pre>%s</pre>\n" %
self.attrencode(formatted))
def has_cookie(self, varname):
diff --git a/web/htdocs/logwatch.py b/web/htdocs/logwatch.py
index ba8ed0e..64e34e2 100644
--- a/web/htdocs/logwatch.py
+++ b/web/htdocs/logwatch.py
@@ -30,6 +30,8 @@ import views
stylesheets = [ 'pages', 'status', 'logwatch' ]
+nagios_illegal_chars = '`;~!$%^&*|\'"<>?,()='
+
def level_name(level):
if level == 'W': return 'WARN'
elif level == 'C': return 'CRIT'
@@ -49,13 +51,16 @@ def level_state(level):
# | ___) | | | | (_) \ V V / | |__| (_) | (_| \__ \ |
# | |____/|_| |_|\___/ \_/\_/ |_____\___/ \__, |___/ |
# | |___/ |
-# +----------------------------------------------------------------------+
-# | |
# '----------------------------------------------------------------------'
def page_show():
host = html.var('host')
filename = html.var('file')
+ if "/" in host:
+ return
+
+ # Fix problem when URL is missing certain illegal characters
+ filename = form_file_to_ext(find_matching_logfile(host, form_file_to_int(filename)))
# Acknowledging logs is supported on
# a) all logs on all hosts
@@ -160,7 +165,30 @@ def ack_button(host = None, int_filename = None):
else:
label = _("Clear Logs")
- html.context_button(label, html.makeactionuri([('_ack', '1')]),
'delete')
+ urivars = [('_ack', '1')]
+ if int_filename:
+ urivars.append(("file", int_filename))
+ html.context_button(label, html.makeactionuri(urivars), 'delete')
+
+
+# Tackle problem, where some characters are missing in the service
+# description
+def find_matching_logfile(host, filename):
+ dir_path = defaults.logwatch_dir + '/' + host + '/'
+ if os.path.exists(dir_path + filename):
+ return filename # Most common case
+
+ for logfile_name in os.listdir(dir_path):
+ if remove_illegal_service_characters(logfile_name) == filename:
+ return logfile_name
+
+ # Not found? Fall back to original name. Logfile might be cleared.
+ return filename
+
+
+def remove_illegal_service_characters(filename):
+ return "".join([ c for c in filename if c not in nagios_illegal_chars ])
+
def show_file(host, filename):
diff --git a/web/plugins/wato/bi.py b/web/plugins/wato/bi.py
index 9b119a3..9c5b12c 100644
--- a/web/plugins/wato/bi.py
+++ b/web/plugins/wato/bi.py
@@ -1080,6 +1080,11 @@ class ModeBIRules(ModeBI):
def page(self):
+ path = defaults.var_dir + "/foobar"
+ wert = { u"öms": u"Hälooöⴰⴱⴲⴳⴴⴵⴶ", "x" : range(10),
"ö" : "Ja" }
+ config.write_settings_file(path, wert)
+ wert2 = eval(file(path).read())
+ html.debug((wert, wert2, wert==wert2))
if not self._pack["aggregations"] and not
self._pack["rules"]:
new_url = self.url_to_pack([("mode", "bi_edit_rule")])
menu_items = [