Module: check_mk
Branch: master
Commit: 28e68bf89caa4684daaf25c31dbc4479c7a22225
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=28e68bf89caa46…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Sep 16 17:47:34 2016 +0200
mkeventd now also support "OutputFormat: json" and produces an error when
requesting unsupported formats
---
bin/mkeventd | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/bin/mkeventd b/bin/mkeventd
index 66c0658..33ded08 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -38,6 +38,11 @@ from cmk.regex import regex, is_regex
import cmk.defines as defines
import cmk.daemon
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
VERSION="1.4.0i1"
# .--Declarations--------------------------------------------------------.
@@ -2996,16 +3001,26 @@ class StatusServer:
response = None
else:
- raise MKClientError("Invalid method %s (allowed are GET, COMMAND
and REPLICATE)" % method)
+ raise MKClientError("Invalid method %s (allowed are GET, COMMAND
"
+ "and REPLICATE)" % method)
if output_format == "plain":
for line in response:
socket.sendall("\t".join([to_utf8(quote_tab(c)) for c
in line]))
socket.sendall("\n")
- else:
+
+ elif output_format == "json":
+ socket.sendall(json.dumps(response))
+ socket.sendall("\n")
+
+ elif output_format == "python":
socket.sendall(repr(response))
socket.sendall("\n")
+ else:
+ raise MKClientError("Invalid output format \"%s\"
"
+ "(allowed are python, json and plain)" %
output_format)
+
socket.close()
# locked with lock_eventstatus