Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle keepalive option #78

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion module/livestatus_client_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -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''))):
Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions module/livestatus_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,23 @@ 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'..
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 = ''
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:]):
Expand Down