diff --git a/include/Ntop.h b/include/Ntop.h index cc97eba816..56ff1a3055 100644 --- a/include/Ntop.h +++ b/include/Ntop.h @@ -78,7 +78,7 @@ class Ntop { float cpu_load; bool is_started; std::set *new_malicious_ja3, *malicious_ja3, *malicious_ja3_shadow; - FifoStringsQueue *sqlite_alerts_queue, *alerts_notifications_queue; + FifoStringsQueue *sqlite_alerts_queue, *alerts_notifications_queue, *internal_alerts_queue; #ifdef NTOPNG_PRO #ifndef WIN32 @@ -441,6 +441,7 @@ class Ntop { inline void setnDPICleanupNeeded(bool needed) { ndpi_cleanup_needed = needed; } inline FifoStringsQueue* getSqliteAlertsQueue() { return(sqlite_alerts_queue); } inline FifoStringsQueue* getAlertsNotificationsQueue() { return(alerts_notifications_queue); } + inline FifoStringsQueue* getInternalAlertsQueue() { return(internal_alerts_queue); } void sendNetworkInterfacesTermination(); inline time_t getLastStatsReset() { return(last_stats_reset); } diff --git a/include/ntop_defines.h b/include/ntop_defines.h index c819c4431f..c9351740cd 100644 --- a/include/ntop_defines.h +++ b/include/ntop_defines.h @@ -501,10 +501,10 @@ #define CONST_INFLUXDB_FILE_QUEUE "ntopng.influx_file_queue" #define CONST_INFLUXDB_FLUSH_TIME 10 /* sec */ #define CONST_INFLUXDB_MAX_DUMP_SIZE 4194304 /* 4 MB */ -#define CONST_ALERT_STORE_QUEUE "ntopng.push_alerts_queue" #define CONST_FLOW_ALERT_EVENT_QUEUE "ntopng.cache.ifid_%d.flow_alerts_events_queue" #define SQLITE_ALERTS_QUEUE_SIZE 512 #define ALERTS_NOTIFICATIONS_QUEUE_SIZE 4096 +#define INTERNAL_ALERTS_QUEUE_SIZE 1024 #define CONST_REMOTE_TO_REMOTE_MAX_QUEUE 32 #define CONST_SQL_QUEUE "ntopng.sql_queue" #define CONST_SQL_BATCH_SIZE 32 @@ -836,8 +836,6 @@ #define ALERTS_MANAGER_SEVERITY_FIELD "alert_severity" #define STATS_MANAGER_STORE_NAME "top_talkers.db" -#define ALERTS_MANAGER_NOTIFICATION_QUEUE_NAME "ntopng.alerts.notifications_queue" - #define CONST_MAX_NUM_THREADED_ACTIVITIES 64 #define STARTUP_SCRIPT_PATH "startup.lua" #define BOOT_SCRIPT_PATH "boot.lua" /* Executed as root before networking is setup */ diff --git a/scripts/lua/modules/alert_utils.lua b/scripts/lua/modules/alert_utils.lua index c16a224836..030522adf6 100644 --- a/scripts/lua/modules/alert_utils.lua +++ b/scripts/lua/modules/alert_utils.lua @@ -19,7 +19,6 @@ local alert_endpoints = require "alert_endpoints_utils" local flow_consts = require "flow_consts" local user_scripts = require "user_scripts" -local store_alerts_queue = "ntopng.push_alerts_queue" local shaper_utils = nil if(ntop.isnEdge()) then @@ -2728,8 +2727,7 @@ function checkStoreAlertsFromC(deadline) end while(os.time() <= deadline) do - -- TODO add max_length check and alert - local message = ntop.lpopCache(store_alerts_queue) + local message = ntop.popInternalAlerts() if((message == nil) or (message == "")) then break diff --git a/src/AlertsQueue.cpp b/src/AlertsQueue.cpp index 8d6154cf3a..4a9f506cfe 100644 --- a/src/AlertsQueue.cpp +++ b/src/AlertsQueue.cpp @@ -35,7 +35,7 @@ void AlertsQueue::pushAlertJson(const char *atype, json_object *alert) { json_object_object_add(alert, "alert_type", json_object_new_string(atype)); json_object_object_add(alert, "alert_tstamp", json_object_new_int64(time(NULL))); - ntop->getRedis()->rpush(CONST_ALERT_STORE_QUEUE, (char *)json_object_to_json_string(alert), 1024 /* Trim */); + ntop->getInternalAlertsQueue()->enqueue(json_object_to_json_string(alert)); } /* **************************************************** */ diff --git a/src/LuaEngine.cpp b/src/LuaEngine.cpp index 157468eb57..8f4edc1478 100644 --- a/src/LuaEngine.cpp +++ b/src/LuaEngine.cpp @@ -9474,6 +9474,20 @@ static int ntop_pop_alert_notification(lua_State* vm) { /* ****************************************** */ +static int ntop_pop_internal_alerts(lua_State* vm) { + char *internal_alerts = ntop->getInternalAlertsQueue()->dequeue(); + + if(internal_alerts) { + lua_pushstring(vm, internal_alerts); + free(internal_alerts); + } else + lua_pushnil(vm); + + return(CONST_LUA_OK); +} + +/* ****************************************** */ + // ***API*** static int ntop_flow_is_blacklisted(lua_State* vm) { Flow *f = ntop_flow_get_context_flow(vm); @@ -11307,6 +11321,7 @@ static const luaL_Reg ntop_reg[] = { { "popSqliteAlert", ntop_pop_sqlite_alert }, { "pushAlertNotification", ntop_push_alert_notification }, { "popAlertNotification", ntop_pop_alert_notification }, + { "popInternalAlerts", ntop_pop_internal_alerts }, /* nEdge */ #ifdef HAVE_NEDGE diff --git a/src/Ntop.cpp b/src/Ntop.cpp index b0b5250138..3cb4c3ffdd 100644 --- a/src/Ntop.cpp +++ b/src/Ntop.cpp @@ -79,6 +79,7 @@ Ntop::Ntop(char *appName) { sqlite_alerts_queue = new FifoStringsQueue(SQLITE_ALERTS_QUEUE_SIZE); alerts_notifications_queue = new FifoStringsQueue(ALERTS_NOTIFICATIONS_QUEUE_SIZE); + internal_alerts_queue = new FifoStringsQueue(INTERNAL_ALERTS_QUEUE_SIZE); resolvedHostsBloom = new Bloom(NUM_HOSTS_RESOLVED_BITS); @@ -220,6 +221,7 @@ Ntop::~Ntop() { if(resolvedHostsBloom) delete resolvedHostsBloom; delete sqlite_alerts_queue; delete alerts_notifications_queue; + delete internal_alerts_queue; if(ndpi_struct) { ndpi_exit_detection_module(ndpi_struct);