From 3378cec752294c8214a92f6aff6df842c8485a63 Mon Sep 17 00:00:00 2001 From: Nicolas Dupeux Date: Wed, 16 May 2018 09:38:29 +0200 Subject: [PATCH 1/2] Correctly handle keepalive option --- module/livestatus_client_thread.py | 5 ++++- module/livestatus_obj.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/module/livestatus_client_thread.py b/module/livestatus_client_thread.py index 3f659bf..eadb941 100644 --- a/module/livestatus_client_thread.py +++ b/module/livestatus_client_thread.py @@ -227,7 +227,7 @@ def handle_wait_query(self, wait, query): def handle_request(self, request_data): - response, _ = self.livestatus.handle_request(request_data) + response, keepalive = self.livestatus.handle_request(request_data) try: if not isinstance(response, (LiveStatusListResponse, type(b''))): @@ -244,6 +244,9 @@ def handle_request(self, request_data): output, _ = response.respond() self.send_response(output) + if keepalive != 'on': + self.request_stop() + def run(self): assert isinstance(self.livestatus, LiveStatus) self.livestatus.db.open() diff --git a/module/livestatus_obj.py b/module/livestatus_obj.py index 83a6954..ba0f2f7 100644 --- a/module/livestatus_obj.py +++ b/module/livestatus_obj.py @@ -110,7 +110,7 @@ def handle_request_and_fail(self, data): return '', False cur_idx = 0 - keepalive = False + keepalive = 'off' for query in queries: # process the command(s), if any. # as they are sorted alphabetically, once we get one which isn't a 'command'.. @@ -123,7 +123,7 @@ def handle_request_and_fail(self, data): cur_idx += 1 if 'wait' in queries_type: - keepalive = True + keepalive = 'on' # we return 'wait' first and 'query' second.. output = list(reversed(queries[cur_idx:])) elif len(queries[cur_idx:]): From 39a70859a77788fb5701d17b48a8907665e8f9e7 Mon Sep 17 00:00:00 2001 From: Nicolas Dupeux Date: Wed, 13 Jun 2018 08:55:52 +0200 Subject: [PATCH 2/2] Handle implicit keepalive for COMMAND query https://mathias-kettner.de/checkmk_livestatus.html#Sending%20commands%20via%20Livestatus """ COMMAND automatically implies keep alive and behave like GET when KeepAlive is set to on. That way you can mix GET and COMMAND quries in one connection. """ --- module/livestatus_obj.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/module/livestatus_obj.py b/module/livestatus_obj.py index ba0f2f7..4c4d957 100644 --- a/module/livestatus_obj.py +++ b/module/livestatus_obj.py @@ -117,6 +117,9 @@ def handle_request_and_fail(self, data): if query.my_type != 'command': break # then we are done. query.process_query() + # According to mk_livestatus documentation + # COMMAND automatically implies keep alive and behave like GET when KeepAlive is set to on. + keepalive = 'on' # according to Check_Mk, COMMAND doesn't require a response (argh!), # that is no response or more simply: an empty response: output = ''