new: [app:diagnostic] Added ZMQ diagnostic and message count

This commit is contained in:
Sami Mokaddem 2024-07-01 14:54:33 +02:00
parent 0ee3f7ac13
commit b6822f17d7
2 changed files with 29 additions and 2 deletions

View file

@ -14,6 +14,9 @@ import db
import misp_api import misp_api
ZMQ_MESSAGE_COUNT = 0
# Initialize ZeroMQ context and subscriber socket # Initialize ZeroMQ context and subscriber socket
context = gzmq.Context() context = gzmq.Context()
zsocket = context.socket(gzmq.SUB) zsocket = context.socket(gzmq.SUB)
@ -124,6 +127,8 @@ def get_context(data: dict) -> dict:
def getDiagnostic() -> dict: def getDiagnostic() -> dict:
global ZMQ_MESSAGE_COUNT
diagnostic = {} diagnostic = {}
misp_version = misp_api.getVersion() misp_version = misp_api.getVersion()
if misp_version is None: if misp_version is None:
@ -132,15 +137,19 @@ def getDiagnostic() -> dict:
diagnostic['version'] = misp_version diagnostic['version'] = misp_version
misp_settings = misp_api.getSettings() misp_settings = misp_api.getSettings()
diagnostic['settings'] = misp_settings diagnostic['settings'] = misp_settings
diagnostic['zmq_message_count'] = ZMQ_MESSAGE_COUNT
return diagnostic return diagnostic
# Function to forward zmq messages to Socket.IO # Function to forward zmq messages to Socket.IO
def forward_zmq_to_socketio(): def forward_zmq_to_socketio():
global ZMQ_MESSAGE_COUNT
while True: while True:
message = zsocket.recv_string() message = zsocket.recv_string()
topic, s, m = message.partition(" ") topic, s, m = message.partition(" ")
try: try:
ZMQ_MESSAGE_COUNT += 1
handleMessage(topic, s, m) handleMessage(topic, s, m)
except Exception as e: except Exception as e:
print(e) print(e)
@ -157,4 +166,4 @@ if __name__ == "__main__":
eventlet.spawn_n(forward_zmq_to_socketio) eventlet.spawn_n(forward_zmq_to_socketio)
# Run the Socket.IO server # Run the Socket.IO server
eventlet.wsgi.server(eventlet.listen(('0.0.0.0', 4000)), app) eventlet.wsgi.server(eventlet.listen(('0.0.0.0', 3000)), app)

View file

@ -8,6 +8,8 @@
const diagnosticLoading = computed(() => Object.keys(diagnostic.value).length == 0) const diagnosticLoading = computed(() => Object.keys(diagnostic.value).length == 0)
const isMISPOnline = computed(() => diagnostic.value.version?.version !== undefined) const isMISPOnline = computed(() => diagnostic.value.version?.version !== undefined)
const isZMQActive = computed(() => diagnostic.value.zmq_message_count > 0)
const ZMQMessageCount = computed(() => diagnostic.value.zmq_message_count)
function changeSelectionState(state_enabled, exec_uuid) { function changeSelectionState(state_enabled, exec_uuid) {
changeExerciseSelection(exec_uuid, state_enabled); changeExerciseSelection(exec_uuid, state_enabled);
@ -76,7 +78,7 @@
<FontAwesomeIcon :icon="faSuitcaseMedical" class="mr-1"></FontAwesomeIcon> <FontAwesomeIcon :icon="faSuitcaseMedical" class="mr-1"></FontAwesomeIcon>
Diagnostic Diagnostic
</h3> </h3>
<h4 class="font-semibold ml-1 my-2"> <h4 class="font-semibold ml-1 my-3">
<strong>MISP Status:</strong> <strong>MISP Status:</strong>
<span class="ml-2"> <span class="ml-2">
<span :class="{ <span :class="{
@ -92,6 +94,22 @@
</span> </span>
</span> </span>
</h4> </h4>
<h4 class="font-semibold ml-1 my-3">
<strong>ZMQ Status:</strong>
<span class="ml-2">
<span :class="{
'rounded-lg py-1 px-2': true,
'dark:bg-neutral-800 bg-neutral-400 text-slate-800 dark:text-slate-200': diagnosticLoading,
'dark:bg-green-700 bg-green-500 text-slate-800 dark:text-slate-200': !diagnosticLoading && isZMQActive,
'dark:bg-red-700 bg-red-700 text-slate-200 dark:text-slate-200': !diagnosticLoading && !isZMQActive,
}">
<span v-if="diagnosticLoading" class="loading loading-dots loading-sm h-4 inline-block align-middle"></span>
<span v-else class="font-bold">
{{ !isZMQActive ? 'No message received yet' : `ZMQ Active (${ZMQMessageCount} messages)` }}
</span>
</span>
</span>
</h4>
<template v-if="diagnosticLoading || isMISPOnline"> <template v-if="diagnosticLoading || isMISPOnline">
<h4 class="font-semibold ml-1"><strong>MISP Settings:</strong></h4> <h4 class="font-semibold ml-1"><strong>MISP Settings:</strong></h4>