[checkmk-commits] Check_MK Git: check_mk: Add output format JSON to web service

git version control git at mathias-kettner.de
Sat Feb 5 09:17:19 CET 2011


Module: check_mk
Branch: master
Commit: 5dfcc3b372540318cc31ddd3fa152936dad82f55
URL:    http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5dfcc3b372540318cc31ddd3fa152936dad82f55

Author: Mathias Kettner <mk at mathias-kettner.de>
Date:   Fri Feb  4 13:18:06 2011 +0100

Add output format JSON to web service

---

 ChangeLog                       |    7 ++++---
 web/plugins/views/webservice.py |   25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b3e96d8..eaf520a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,9 @@
 1.1.9i8:
     Multisite:
-    * New "web service" for retrieving data from views as Python
-      objects (similar to JSON). This allows to connect with
-      NagStaMon (requires patch in NagStaMon).
+    * New "web service" for retrieving data from views as JSON or 
+      Python objects. This allows to connect with NagStaMon 
+      (requires patch in NagStaMon). Simply add &output_format=json
+      or &output_format=python to your view URL.
 
     WATO:
     * Fixed problem appearing at restart on older Python version (RH)
diff --git a/web/plugins/views/webservice.py b/web/plugins/views/webservice.py
index 39621c7..98030ed 100644
--- a/web/plugins/views/webservice.py
+++ b/web/plugins/views/webservice.py
@@ -29,3 +29,28 @@ multisite_layouts["python"] = {
     "hide"   : True,
 }
 
+def render_json(data, view, group_painters, painters, num_columns):
+    columns, rows = data
+    html.write("[\n")
+    html.write(repr([p[0]["title"] for p in painters]))
+    for row in rows:
+        html.write(",\n[")
+        first = True
+        for p in painters:
+            if first:
+                first = False
+            else:
+                html.write(",")
+            tdclass, content = prepare_paint(p, row)
+            stripped = htmllib.strip_tags(content)
+            utf8 = stripped.encode("utf-8")
+            html.write(repr(utf8))
+        html.write("]")
+    html.write("\n]\n")
+
+multisite_layouts["json"] = {
+    "title"  : "JSON data output",
+    "render" : render_json,
+    "group"  : False,
+    "hide"   : True,
+}



More information about the checkmk-commits mailing list