Module: check_mk
Branch: master
Commit: 8fc2638cd56a6b0121c043f0999174f74ab18f8a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8fc2638cd56a6b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Jul 29 08:17:01 2016 +0200
3726 FIX Web API: Fixed default output format - using JSON as intended
The WATO Web API was using Python as default output format since version
1.2.8b8 and commit 36142e6d, which was not intended.
The Web API is able to output JSON and Python formated data, which can be
toggled using the variable <tt>output_format=json</tt> or
<tt>output_format=python</tt>. The default has now been changed back to
be JSON.
In case you created scripts against this API since 1.2.8b8, did not use
a JSON parser to load the data and used something like <tt>eval()</tt>
in Python instead, you will have to change your scripts. You can either
add the variable <tt>output_format=python</tt> or replace your
<tt>eval()</tt>
with <tt>json.loads()</tt> in Python.
---
.werks/3726 | 22 ++++++++++++++++++++++
ChangeLog | 1 +
web/htdocs/webapi.py | 6 +++++-
3 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/.werks/3726 b/.werks/3726
new file mode 100644
index 0000000..05e7684
--- /dev/null
+++ b/.werks/3726
@@ -0,0 +1,22 @@
+Title: Web API: Fixed default output format - using JSON as intended
+Level: 2
+Component: wato
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.4.0i1
+Date: 1469772716
+
+The WATO Web API was using Python as default output format since version
+1.2.8b8 and commit 36142e6d, which was not intended.
+
+The Web API is able to output JSON and Python formated data, which can be
+toggled using the variable <tt>output_format=json</tt> or
+<tt>output_format=python</tt>. The default has now been changed back to
+be JSON.
+
+In case you created scripts against this API since 1.2.8b8, did not use
+a JSON parser to load the data and used something like <tt>eval()</tt>
+in Python instead, you will have to change your scripts. You can either
+add the variable <tt>output_format=python</tt> or replace your
<tt>eval()</tt>
+with <tt>json.loads()</tt> in Python.
diff --git a/ChangeLog b/ChangeLog
index 2e7777b..5873df9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -509,6 +509,7 @@
* 3557 FIX: Web API: get_host/get_all_hosts action now also returns the nodes of
cluster host
* 3718 FIX: Changes not needing a core restart are not showing up pending changes
anymore...
* 3719 FIX: Fixed possible wrong encoding of audit log messages when editing global
settings
+ * 3726 FIX: Web API: Fixed default output format - using JSON as intended...
Notifications:
* 3263 Notifications: allow users to restrict by their contact groups...
diff --git a/web/htdocs/webapi.py b/web/htdocs/webapi.py
index 5440e90..02dd0a3 100644
--- a/web/htdocs/webapi.py
+++ b/web/htdocs/webapi.py
@@ -59,13 +59,17 @@ def load_plugins(force):
def page_api():
try:
+ # The API uses JSON format by default and python as optional alternative
+ output_format = html.var("output_format", "json")
+ if output_format not in [ "json", "python" ]:
+ html.set_output_format("json")
+ raise MKUserError(None, "Only \"json\" and
\"python\" are supported as output formats")
if not config.user.get("automation_secret"):
raise MKAuthException("The WATO API is only available for automation
users")
config.need_permission("wato.use")
config.need_permission("wato.api_allowed")
-
action = html.var('action')
if action not in api_actions:
raise MKUserError(None, "Unknown API action %s" %
html.attrencode(action))