Skip to content

Commit

Permalink
Implementedd ntop.getLicenseLimits()
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaderi committed Sep 3, 2024
1 parent 8bfa56f commit 9ef0726
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
33 changes: 33 additions & 0 deletions src/LuaEngineNtop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7776,6 +7776,36 @@ static int ntop_toggle_new_delete_trace(lua_State *vm) {
return(ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_OK));
}

/* **************************************************************** */

static int ntop_get_license_limits(lua_State *vm) {
lua_newtable(vm);

lua_newtable(vm);
lua_push_uint32_table_entry(vm, "num_flow_exporters", ntop->getNumFlowExporters());
lua_push_uint32_table_entry(vm, "num_flow_exporter_interfaces", ntop->getNumFlowExportersInterfaces());
#if 0
lua_push_uint32_table_entry(vm, "num_host_pools", );
lua_push_uint32_table_entry(vm, "num_pool_members", );
lua_push_uint32_table_entry(vm, "num_profiles", );
#endif
lua_pushstring(vm, "current");
lua_insert(vm, -2);
lua_settable(vm, -3);

lua_newtable(vm);
lua_push_uint32_table_entry(vm, "num_flow_exporters", get_max_num_flow_exporters());
lua_push_uint32_table_entry(vm, "num_flow_exporter_interfaces", get_max_num_flow_exporters_interfaces());
lua_push_uint32_table_entry(vm, "num_host_pools", MAX_NUM_HOST_POOLS);
lua_push_uint32_table_entry(vm, "num_pool_members", MAX_NUM_POOL_MEMBERS);
lua_push_uint32_table_entry(vm, "num_profiles", MAX_NUM_PROFILES);
lua_pushstring(vm, "max");
lua_insert(vm, -2);
lua_settable(vm, -3);

return(ntop_lua_return_value(vm, __FUNCTION__, CONST_LUA_OK));
}

#if defined(NTOPNG_PRO)

/* **************************************************************** */
Expand Down Expand Up @@ -8316,6 +8346,9 @@ static luaL_Reg _ntop_reg[] = {
/* Debug */
{ "toggleNewDeleteTrace", ntop_toggle_new_delete_trace },

/* License */
{ "getLicenseLimits", ntop_get_license_limits },

#if defined(NTOPNG_PRO)
/* TODO: move to message_broker engine */
{ "publish", m_broker_publish },
Expand Down
22 changes: 11 additions & 11 deletions src/ParserInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ bool ParserInterface::processFlow(ParsedFlow *zflow) {
if ((zflow->vlan_id == 0) && ntop->getPrefs()->do_simulate_vlans())
zflow->vlan_id = rand() % SIMULATE_VLANS_MAX_VALUE;

#ifdef TRACE_EXPORTERS
ntop->getTrace()->traceEvent(TRACE_NORMAL,
"[unique_source_id: %u];device_ip: %u][probe_ip: %u][iface: %u->%u]",
unique_source_id, zflow->exporter_device_ip,
zflow->nprobe_ip, zflow->inIndex, zflow->outIndex);
#endif

#ifdef NTOPNG_PRO
if(unique_source_id != 0) {
if (!flow_interfaces_stats->checkExporters(unique_source_id,
Expand All @@ -101,11 +94,18 @@ bool ParserInterface::processFlow(ParsedFlow *zflow) {
static bool shown = false;

if(!shown) {
ntop->getTrace()->traceEvent(TRACE_NORMAL, "Flow dropped due to limits to the license");

ntop->getTrace()->traceEvent(TRACE_NORMAL,
"Flow dropped due to limits to the license. Exporters limit: %d (%d active)"
" | Interfaces limit: %d (%d active)",
get_max_num_flow_exporters(), ntop->getNumFlowExporters(),
get_max_num_flow_exporters_interfaces(), ntop->getNumFlowExportersInterfaces());
"Exporters t: %d/%d max | Exporter Interfaces: %d/%d max",
ntop->getNumFlowExporters(), get_max_num_flow_exporters(),
ntop->getNumFlowExportersInterfaces(), get_max_num_flow_exporters_interfaces());

ntop->getTrace()->traceEvent(TRACE_NORMAL,
"Discarded [unique_source_id: %u];device_ip: %u][probe_ip: %u][iface: %u->%u]",
unique_source_id, zflow->exporter_device_ip,
zflow->nprobe_ip, zflow->inIndex, zflow->outIndex);

ntop->getRedis()->set(EXPORTERS_EXCEEDED_LIMITS_KEY, "1");
shown = true;
}
Expand Down

0 comments on commit 9ef0726

Please sign in to comment.