fix: [diagnostic] socket subscribing multiple time and improved status

message
subzero
mokaddem 2019-06-21 16:19:57 +02:00
parent a9f9a67184
commit ddf7cbcfff
1 changed files with 14 additions and 14 deletions

View File

@ -171,14 +171,15 @@ def check_redis(spinner):
def check_zmq(spinner):
timeout = 15
context = zmq.Context()
socket = context.socket(zmq.SUB)
misp_instances = json.loads(cfg.get('RedisGlobal', 'misp_instances'))
misp_instances = json.loads(configuration_file.get('RedisGlobal', 'misp_instances'))
instances_status = {}
for misp_instance in misp_instances:
socket = context.socket(zmq.SUB)
socket.connect(misp_instance.get('zmq'))
socket.setsockopt_string(zmq.SUBSCRIBE, '')
poller = zmq.Poller()
flag_skip = False
start_time = time.time()
poller.register(socket, zmq.POLLIN)
for t in range(1, timeout+1):
@ -188,21 +189,23 @@ def check_zmq(spinner):
rcv_string = socket.recv()
if rcv_string.startswith(b'misp_json'):
instances_status[misp_instance.get('name')] = True
flag_skip = True
break
else:
pass
spinner.text = f'checking zmq of {misp_instance.get('name')} - elapsed time: {int(time.time() - start_time)}s'
instances_status[misp_instance.get('name')] = False
spinner.text = f'checking zmq of {misp_instance.get("name")} - elapsed time: {int(time.time() - start_time)}s'
if not flag_skip:
instances_status[misp_instance.get('name')] = False
results = [s for n, s in instances_status.items()]
if all(results):
return (True, '')
elif any(results):
return_text = 'Some connection to ZMQ streams failed.\n'
for name, status:
return_text += f'\t{name}: {'success' if status else 'failed'}\n'
return_text = 'Connection to ZMQ stream(s) failed.\n'
for name, status in instances_status.items():
return_text += f'\t{name}: {"success" if status else "failed"}\n'
return (True, return_text)
else:
return (False, '''Can\'t connect to the ZMQ stream.
return (False, '''Can\'t connect to the ZMQ stream(s).
\t Make sure the MISP ZMQ is running: `/servers/serverSettings/diagnostics`
\t Make sure your network infrastucture allows you to connect to the ZMQ''')
@ -215,11 +218,8 @@ def check_processes_status(spinner):
universal_newlines=True
)
for line in response.splitlines():
lines = line.split(' ')
if len(lines) == 2:
pid, p_name = lines
elif len(lines) ==3:
pid, _, p_name = lines
lines = line.split(' ', maxsplit=1)
pid, p_name = lines
if 'zmq_subscriber.py' in p_name:
pgrep_subscriber_output = line