Module: check_mk
Branch: master
Commit: 86ad0ce641650e8c66b06325ecb12823b13f8071
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=86ad0ce641650e…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Sun Oct 24 18:52:16 2010 +0200
Multisite: allow non-ASCII character in downtimes and comments
---
ChangeLog | 1 +
LIESMICH.zutun | 29 ++++-------------------------
web/htdocs/htmllib.py | 6 ++++++
web/htdocs/views.py | 22 ++++++++++------------
4 files changed, 21 insertions(+), 37 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 10ebf51..d1f8bbb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -27,6 +27,7 @@
size of external command buffer
* Fix links for items containing + (e.g. service descriptionen including
spaces)
+ * Allow non-ASCII character in downtimes and comments
1.1.8b3:
Core, Setup, etc.:
diff --git a/LIESMICH.zutun b/LIESMICH.zutun
index 5135fab..1ede43a 100644
--- a/LIESMICH.zutun
+++ b/LIESMICH.zutun
@@ -1,18 +1,12 @@
--------------------------------------------------------------------------------
UMLAUTPROBLEME (alle gemeinsam angehen)
--------------------------------------------------------------------------------
-Eingabe von Downtimes: Auch hier Umlaute abfangen wie bei Comments
-
Noch ein Problem mit Umlauten: Ein Drucker sendet per SNMP Latin1
kodierte Wert, z.B. Resttonerbehälter. Daraus baut Check_MK eine
Servicedesription, die in nagios/conf.d/check_mk_objects.cfg ein
Latin1-Zeichen enthält. Hier sollte unbedingt UTF-8 verwendet
werden. Nur: woher kennen wir die Kodierung vom Drucker??
-Sieht so aus, dass das Eurozeichen von Livestatus nicht korrekt kodiert
-wird. Wenn man commant_data=... und ein Euro drinnen hat, verschwindet
-es bei der Ausgabe mit python/json. CSV geht.
-
--------------------------------------------------------------------------------
BUGS beheben bis => 1.1.8
--------------------------------------------------------------------------------
@@ -32,28 +26,13 @@ doc/ aufräumen und komplett 1:1 installieren.
Clusters mit IP-Adressen: Der Host-Check soll die IP-Adresse verwenden,
wenn sie vorhanden ist.
-MULTISITE: Hallo zusammen, mir ist bei meinen Tests mit der Multisite
-GUI aufgefallen, dass keine Comments zu Services oder Hosts dargestellt
-werden. Comments zu Downtimes, werden hingegen ohne Probleme dargestellt.
-Unter der Default-View "Other - > Comments" wird ebenfalls kein Host
/Service
-dargestellt, obwohl Comments hinterlegt sind, welche in der Classic GUI auch
-dargestellt werden. Beim Versuch eine eigene View zu erstellen, ist mir
-dann auch aufgefallen, dass die Datasource Comments nicht zur Auswahl steht.
-Getestet habe ich dies mit den Versionen: 1.1.6.p1 und 1.1.8.b3 Hat jemand
-schon ähnliche Erfahrungen gesammelt? Vielleicht ist es ja auch nur ein
-Bedienerfehler meinerseits.
-
-Wie siehts denn mit dem utf-8 Problem aus. Kommt das noch in die 1.1.8 rein, bzw, raus
:-)
-Zum Ausprobieren reicht es per Nagios oder Thruk eine Downtime "€" zu setzen.
Mit Multisite kann man sie zwar
-nicht setzen, aber er zeigt sie auch falsch an.
-Btw, beim Comment setzen kommt:
-Please only use ASCII characters in your comment.
-Beim Versuch eine Downtime zu setzen:
-Internal error: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal
not in range(128) (Retry with debug mode)
-
--------------------------------------------------------------------------------
BUGS beheben ab 1.1.9i1
--------------------------------------------------------------------------------
+Livestatus: bestimmte UTF-8 Zeichen werden nicht korrekt kodiert, z.B. "€".
+Um das umzustellen, muss man wahrscheinlich einfach UTF-8 generell
+annehmen.
+
Wenn ein Counter Wrap passiert und der check selbst die Exception
nicht abfängt, dann wird das Ergebnis nicht an Nagios weitergeleitet.
Der Service wird auch nicht in die aggregierten Services eines Summary Hosts
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 54fba99..57ba466 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -66,6 +66,7 @@ class uriinfo:
def attrencode(value):
return cgi.escape(str(value), True)
+# This function returns a str object, never unicode!
def urlencode_vars(vars):
output = ""
for varname, value in vars:
@@ -83,6 +84,8 @@ def urlencode_vars(vars):
return output
def urlencode(value):
+ if type(value) == unicode:
+ value = value.encode("utf-8")
ret = ""
for c in value:
if c == " ":
@@ -418,6 +421,9 @@ class html:
def var(self, varname, deflt = None):
return self.req.vars.get(varname, deflt)
+ def var_utf8(self, varname, deflt = None):
+ return unicode(self.req.vars.get(varname, deflt), "utf-8")
+
def set_var(self, varname, value):
self.req.vars[varname] = value
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index ccd2e02..37a7be0 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -983,7 +983,9 @@ def show_view(view, show_heading = False, show_buttons = True):
if html.do_actions() and html.transaction_valid(): # submit button pressed,
no reload
try:
html.write("<tr class=form><td class=whiteborder
colspan=%d>" % colspan)
- has_done_actions = do_actions(datasource["infos"][0], rows,
html.makeuri([]))
+ # Create URI with all actions variables removed
+ backurl = html.makeuri([])
+ has_done_actions = do_actions(datasource["infos"][0], rows,
backurl)
html.write("</td></tr>")
except MKUserError, e:
html.show_error(e.message)
@@ -1511,25 +1513,19 @@ def nagios_host_service_action_command(what, dataset):
title = "<b>manually set check results to %s</b> for" %
statename
elif html.var("_acknowledge") and
config.may("action.acknowledge"):
- comment = html.var("_ack_comment")
+ comment = html.var_utf8("_ack_comment")
if not comment:
raise MKUserError("_ack_comment", "You need to supply a
comment.")
- try:
- command = "ACKNOWLEDGE_" + cmdtag +
"_PROBLEM;%s;2;1;0;%s" % \
+ command = "ACKNOWLEDGE_" + cmdtag + "_PROBLEM;%s;2;1;0;%s" %
\
(spec, html.req.user) + (";%s" % comment)
- except:
- raise MKUserError("_ack_comment", "Please only use ASCII
characters in your comment.")
title = "<b>acknowledge the problems</b> of"
elif html.var("_add_comment") and
config.may("action.addcomment"):
- comment = html.var("_comment")
+ comment = html.var_utf8("_comment")
if not comment:
raise MKUserError("_comment", "You need to supply a
comment.")
- try:
- command = "ADD_" + cmdtag + "_COMMENT;%s;1;%s" % \
+ command = "ADD_" + cmdtag + "_COMMENT;%s;1;%s" % \
(spec, html.req.user) + (";%s" % comment)
- except:
- raise MKUserError("_ack_comment", "Please only use ASCII
characters in your comment.")
title = "<b>add a comment to</b>"
elif html.var("_remove_ack") and
config.may("action.acknowledge"):
@@ -1591,7 +1587,7 @@ def nagios_host_service_action_command(what, dataset):
raise MKUserError(None, "Sorry. This command is not implemented.")
if down_to:
- comment = html.var("_down_comment")
+ comment = html.var_utf8("_down_comment")
if not comment:
raise MKUserError("_down_comment", "You need to supply a
comment for your downtime.")
command = (("SCHEDULE_" + cmdtag + "_DOWNTIME;%s;" % spec) \
@@ -1616,6 +1612,8 @@ def do_actions(what, rows, backurl):
for row in rows:
title, nagios_commands = nagios_action_command(what, row)
for command in nagios_commands:
+ if type(command) == unicode:
+ command = command.encode("utf-8")
html.live.command(command, row["site"])
count += 1