From e79e9dfc7a705e1fa38cbb0308bbe960bf3b6b6c Mon Sep 17 00:00:00 2001 From: Simone Mainardi Date: Fri, 3 Jun 2016 16:25:45 +0200 Subject: [PATCH] Refreshes alert status after UI changes Fixes #595 Fixes #598 --- include/Host.h | 2 ++ scripts/lua/host_details.lua | 3 ++ src/Lua.cpp | 54 ++++++++++++++++++++++++++++++++---- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/include/Host.h b/include/Host.h index 4338ca08e3..199f71a93c 100644 --- a/include/Host.h +++ b/include/Host.h @@ -151,6 +151,8 @@ class Host : public GenericHost { inline void incNumDNSQueriesRcvd(u_int16_t query_type) { if(dns) dns->incNumDNSQueriesRcvd(query_type); }; inline void incNumDNSResponsesSent(u_int32_t ret_code) { if(dns) dns->incNumDNSResponsesSent(ret_code); }; inline void incNumDNSResponsesRcvd(u_int32_t ret_code) { if(dns) dns->incNumDNSResponsesRcvd(ret_code); }; + inline void disableAlerts() { trigger_host_alerts = false; }; + inline void enableAlerts() { trigger_host_alerts = true; }; inline bool triggerAlerts() { return(trigger_host_alerts); }; inline NetworkStats* getNetworkStats(int16_t networkId){ return(iface->getNetworkStats(networkId)); }; diff --git a/scripts/lua/host_details.lua b/scripts/lua/host_details.lua index 700eab9742..6f7c895e1a 100644 --- a/scripts/lua/host_details.lua +++ b/scripts/lua/host_details.lua @@ -1812,8 +1812,11 @@ elseif (page == "config") then if(trigger_alerts ~= nil) then if(trigger_alerts == "true") then ntop.delHashCache("ntopng.prefs.alerts", host_ip) + ntop.enableHostAlerts(host_ip, host_vlan) else ntop.setHashCache("ntopng.prefs.alerts", host_ip, trigger_alerts) + tprint(ntop) + ntop.disableHostAlerts(host_ip, host_vlan) end end end diff --git a/src/Lua.cpp b/src/Lua.cpp index f0a7f1501e..1cccb90692 100644 --- a/src/Lua.cpp +++ b/src/Lua.cpp @@ -1298,6 +1298,48 @@ static int ntop_host_reset_periodic_stats(lua_State* vm) { /* ****************************************** */ +static int ntop_host_trigger_alerts(lua_State* vm, bool trigger) { + NetworkInterfaceView *ntop_interface = getCurrentInterface(vm); + char *host_ip; + u_int16_t vlan_id = 0; + char buf[64]; + Host *h; + + ntop->getTrace()->traceEvent(TRACE_INFO, "%s() called", __FUNCTION__); + + if(ntop_lua_check(vm, __FUNCTION__, 1, LUA_TSTRING)) return(CONST_LUA_ERROR); + get_host_vlan_info((char*)lua_tostring(vm, 1), &host_ip, &vlan_id, buf, sizeof(buf)); + + /* Optional VLAN id */ + if(lua_type(vm, 2) == LUA_TNUMBER) + vlan_id = (u_int16_t)lua_tonumber(vm, 2); + + if((!ntop_interface) + || ((h = ntop_interface->findHostsByIP(get_allowed_nets(vm), host_ip, vlan_id)) == NULL)) + return(CONST_LUA_ERROR); + + if(trigger) + h->enableAlerts(); + else + h->disableAlerts(); + + return(CONST_LUA_OK); +} + +/* ****************************************** */ + +static int ntop_host_enable_alerts(lua_State* vm) { + return ntop_host_trigger_alerts(vm, true); +} + +/* ****************************************** */ + +static int ntop_host_disable_alerts(lua_State* vm) { + return ntop_host_trigger_alerts(vm, false); +} + +/* ****************************************** */ + static int ntop_correalate_host_activity(lua_State* vm) { NetworkInterfaceView *ntop_interface = getCurrentInterface(vm); char *host_ip; @@ -4442,11 +4484,13 @@ static const luaL_Reg ntop_reg[] = { { "getLocalNetworks", ntop_get_local_networks }, /* Alerts */ - { "getNumQueuedAlerts", ntop_get_num_queued_alerts }, - { "getQueuedAlerts", ntop_get_queued_alerts }, - { "deleteQueuedAlert", ntop_delete_queued_alert }, - { "flushAllQueuedAlerts", ntop_flush_all_queued_alerts }, - { "queueAlert", ntop_queue_alert }, + { "getNumQueuedAlerts", ntop_get_num_queued_alerts }, + { "getQueuedAlerts", ntop_get_queued_alerts }, + { "deleteQueuedAlert", ntop_delete_queued_alert }, + { "flushAllQueuedAlerts", ntop_flush_all_queued_alerts }, + { "queueAlert", ntop_queue_alert }, + { "enableHostAlerts", ntop_host_enable_alerts }, + { "disableHostAlerts", ntop_host_disable_alerts }, #ifdef NTOPNG_PRO { "sendNagiosAlert", ntop_nagios_send_alert }, { "withdrawNagiosAlert", ntop_nagios_withdraw_alert },