Module: check_mk
Branch: master
Commit: c7b95db7812b2b9c8c6746355d75fc3aed8c5f62
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c7b95db7812b2b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Feb 4 15:14:20 2011 +0100
Multisite: new display_option d/D
---
ChangeLog | 1 +
web/htdocs/htmllib.py | 7 ++++++-
web/htdocs/views.py | 38 ++++++++++++++++++++++----------------
web/plugins/views/webservice.py | 27 ++++++++++++++++++++++++---
4 files changed, 53 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6fd9ccd..5aefdb9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
* Acknowledgement of problem now has checkboxes for sticky,
send notification and persisten comment
* Downtimes: allow to specify fixed/flexible downtime
+ * new display_options d/D for switching on/off the tab "Display"
WATO:
* Fixed problem appearing at restart on older Python version (RH)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index ed32f1e..13f6a1c 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -456,7 +456,12 @@ class html:
self.write("\n")
def message(self, msg):
- self.write("<div class=success>%s</div>\n" % msg)
+ if self.output_format == "html":
+ self.write("<div class=success>%s</div>\n" % msg)
+ else:
+ self.write("MESSAGE: ")
+ self.write(strip_tags(msg))
+ self.write("\n")
def confirm(self, msg):
if self.var("_do_actions") == "No":
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index fb7d019..c9f48fb 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -935,7 +935,7 @@ def page_view(h):
# Display view with real data. This is *the* function everying
# is about.
def show_view(view, show_heading = False, show_buttons = True, show_footer = True):
- all_display_options = "HTBFCEOZRSIX"
+ all_display_options = "HTBFCEOZRSIXD"
# Parse display options and
if html.output_format == "html":
@@ -1064,7 +1064,7 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
if show_buttons and 'B' in display_options:
show_context_links(view, hide_filters)
- need_navi = show_buttons and ('F' in display_options or 'C' in
display_options or 'O' in display_options or 'E' in display_options)
+ need_navi = show_buttons and ('D' in display_options or 'F' in
display_options or 'C' in display_options or 'O' in display_options or
'E' in display_options)
if need_navi:
html.write("<table class=navi><tr>\n")
@@ -1080,7 +1080,7 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
html.write("<td class=minigap></td>\n")
# Painter-Options
- if len(painter_options) > 0 and config.may("painter_options"):
+ if 'D' in display_options and len(painter_options) > 0 and
config.may("painter_options"):
toggle_button("painter_options", False, "Display")
html.write("<td class=minigap></td>\n")
@@ -1130,24 +1130,29 @@ def show_view(view, show_heading = False, show_buttons = True,
show_footer = Tru
if 'F' in display_options and len(show_filters) > 0 and not
html.do_actions():
show_filter_form(filter_isopen, show_filters)
- # Actions
- if 'C' in display_options and len(rows) > 0:
- if html.do_actions() and html.transaction_valid(): # submit button pressed,
no reload
- try:
+ # Actions
+ if len(rows) > 0:
+ if html.do_actions() and html.transaction_valid(): # submit button pressed, no
reload
+ try:
+ if 'C' in display_options:
html.write("<tr class=form><td
class=whiteborder>")
- # Create URI with all actions variables removed
- backurl = html.makeuri([])
- has_done_actions = do_actions(datasource["infos"][0], rows,
backurl)
+ # Create URI with all actions variables removed
+ backurl = html.makeuri([])
+ has_done_actions = do_actions(datasource["infos"][0], rows,
backurl)
+ if 'C' in display_options:
html.write("</td></tr>")
- except MKUserError, e:
- html.show_error(e.message)
+ except MKUserError, e:
+ html.show_error(e.message)
+ if 'C' in display_options:
html.write("</td></tr>")
- html.add_user_error(e.varname, e.message)
+ html.add_user_error(e.varname, e.message)
+ if 'C' in display_options:
show_action_form(True, datasource)
- else:
- show_action_form(False, datasource)
+ elif 'C' in display_options:
+ show_action_form(False, datasource)
+ if need_navi:
if 'O' in display_options and len(painter_options) > 0 and
config.may("painter_options"):
show_painter_options(painter_options)
@@ -1834,7 +1839,8 @@ def do_actions(what, rows, backurl):
message = "Successfully sent %d commands to Nagios." % count
if config.debug:
message += "The last one was: <pre>%s</pre>" % command
- message += '<br><a href="%s">Back to
view</a>' % backurl
+ if html.output_format == "html": # sorry for this hack
+ message += '<br><a href="%s">Back to
view</a>' % backurl
html.message(message)
elif count == 0:
html.message("No matching service. No command sent.")
diff --git a/web/plugins/views/webservice.py b/web/plugins/views/webservice.py
index 98030ed..d9dab8b 100644
--- a/web/plugins/views/webservice.py
+++ b/web/plugins/views/webservice.py
@@ -16,7 +16,7 @@ def render_python(data, view, group_painters, painters, num_columns):
for row in rows:
html.write("[")
for p in painters:
- tdclass, content = prepare_paint(p, row)
+ tdclass, content = p[0]["paint"](row)
html.write(repr(htmllib.strip_tags(content)))
html.write(",")
html.write("],")
@@ -29,6 +29,26 @@ multisite_layouts["python"] = {
"hide" : True,
}
+
+json_escape = re.compile(r'[\x00-\x1f\\"\b\f\n\r\t]')
+ESCAPE_DCT = {
+ '\\': '\\\\',
+ '"': '\\"',
+ '\b': '\\b',
+ '\f': '\\f',
+ '\n': '\\n',
+ '\r': '\\r',
+ '\t': '\\t',
+}
+for i in range(0x20):
+ ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i))
+
+def encode_string_json(s):
+ def replace(match):
+ return ESCAPE_DCT[match.group(0)]
+ return '"' + ESCAPE.sub(replace, s) + '"'
+
+
def render_json(data, view, group_painters, painters, num_columns):
columns, rows = data
html.write("[\n")
@@ -41,10 +61,11 @@ def render_json(data, view, group_painters, painters, num_columns):
first = False
else:
html.write(",")
- tdclass, content = prepare_paint(p, row)
+ tdclass, content = p[0]["paint"](row)
stripped = htmllib.strip_tags(content)
utf8 = stripped.encode("utf-8")
- html.write(repr(utf8))
+ utf8 += r'\"'
+ html.write(encode_string_json(utf8))
html.write("]")
html.write("\n]\n")