mirror of https://github.com/MISP/misp-dashboard
chg: [diagnostic] Added support of multiple subscribers - WiP
parent
cbbdf7cbfc
commit
a9f9a67184
|
@ -172,22 +172,35 @@ def check_zmq(spinner):
|
||||||
timeout = 15
|
timeout = 15
|
||||||
context = zmq.Context()
|
context = zmq.Context()
|
||||||
socket = context.socket(zmq.SUB)
|
socket = context.socket(zmq.SUB)
|
||||||
socket.connect(configuration_file.get('RedisGlobal', 'zmq_url'))
|
misp_instances = json.loads(cfg.get('RedisGlobal', 'misp_instances'))
|
||||||
socket.setsockopt_string(zmq.SUBSCRIBE, '')
|
instances_status = {}
|
||||||
poller = zmq.Poller()
|
for misp_instance in misp_instances:
|
||||||
|
socket.connect(misp_instance.get('zmq'))
|
||||||
|
socket.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||||
|
poller = zmq.Poller()
|
||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
poller.register(socket, zmq.POLLIN)
|
poller.register(socket, zmq.POLLIN)
|
||||||
for t in range(1, timeout+1):
|
for t in range(1, timeout+1):
|
||||||
socks = dict(poller.poll(timeout=1*1000))
|
socks = dict(poller.poll(timeout=1*1000))
|
||||||
if len(socks) > 0:
|
if len(socks) > 0:
|
||||||
if socket in socks and socks[socket] == zmq.POLLIN:
|
if socket in socks and socks[socket] == zmq.POLLIN:
|
||||||
rcv_string = socket.recv()
|
rcv_string = socket.recv()
|
||||||
if rcv_string.startswith(b'misp_json'):
|
if rcv_string.startswith(b'misp_json'):
|
||||||
return (True, '')
|
instances_status[misp_instance.get('name')] = True
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
spinner.text = f'checking zmq - elapsed time: {int(time.time() - start_time)}s'
|
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
|
||||||
|
|
||||||
|
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 (True, return_text)
|
||||||
else:
|
else:
|
||||||
return (False, '''Can\'t connect to the ZMQ stream.
|
return (False, '''Can\'t connect to the ZMQ stream.
|
||||||
\t➥ Make sure the MISP ZMQ is running: `/servers/serverSettings/diagnostics`
|
\t➥ Make sure the MISP ZMQ is running: `/servers/serverSettings/diagnostics`
|
||||||
|
|
Loading…
Reference in New Issue