Module: check_mk
Branch: master
Commit: 05740de424b1668df33a241cd298600c5ecd4de9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=05740de424b166…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Wed Dec 12 15:53:08 2018 +0100
Tiny polishing for previous XML output commit.
Change-Id: Ic3834b7fc6c68390414128f57aff0c5df7ff0bc0
---
cmk/gui/webapi.py | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/cmk/gui/webapi.py b/cmk/gui/webapi.py
index 89cd3c3..6949a2c 100644
--- a/cmk/gui/webapi.py
+++ b/cmk/gui/webapi.py
@@ -80,7 +80,7 @@ def load_plugins(force):
config.builtin_role_ids)
-FORMATTERS = {
+_FORMATTERS = {
"json": (
json.dumps,
lambda response: json.dumps(response, sort_keys=True, indent=4,
separators=(',', ': '))),
@@ -95,11 +95,13 @@ FORMATTERS = {
def page_api():
try:
pretty_print = False
- if html.output_format not in FORMATTERS:
+ if not html.request.has_var("output_format"):
+ html.set_output_format("json")
+ if html.output_format not in _FORMATTERS:
html.set_output_format("python")
raise MKUserError(
None, "Only %s are supported as output formats" % " and
".join(
- '"%s"' % f for f in FORMATTERS))
+ '"%s"' % f for f in _FORMATTERS))
# TODO: Add some kind of helper for boolean-valued variables?
pretty_print_var = html.request.var("pretty_print",
"no").lower()
@@ -182,4 +184,4 @@ def page_api():
"result": _("Unhandled exception: %s") %
traceback.format_exc(),
}
- html.write(FORMATTERS[html.output_format][1 if pretty_print else 0](response))
+ html.write(_FORMATTERS[html.output_format][1 if pretty_print else 0](response))