-- -- (C) 2014-19 - ntop.org -- local dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path local alerts_api = require "alerts_api" local format_utils = require "format_utils" local user_scripts = require "user_scripts" local ts_utils = require("ts_utils") local flow_callbacks_utils = {} local ifid = interface.getId() -- ############################################## local function print_callbacks_config_table(descr, expert_view) print[[]] print[[]] print[[]] print[[]] print[[]] if(expert_view) then print[[]] end print[[]] print[[]] print[[]] print[[]] print('\n') for mod_k, user_script in pairsByKeys(descr.modules, asc) do local hooks_benchmarks = user_script.benchmark or {} local num_hooks = table.len(hooks_benchmarks) local title local description local rowspan = "" if(user_script.gui) then title = i18n(user_script.gui.i18n_title) or user_script.gui.i18n_title description = i18n(user_script.gui.i18n_description) or user_script.gui.i18n_description else title = user_script.key description = "" end if(expert_view and (num_hooks > 0)) then rowspan = string.format(' rowspan="%d"', num_hooks) end print("") print("") print("") if(expert_view) then if(num_hooks > 0) then local ctr = 0 for mod_fn, mod_benchmark in pairsByKeys(hooks_benchmarks, asc) do print("") print("") print("") print("") ctr = ctr + 1 if(ctr ~= num_hooks) then print("") end end else print("") end else if(num_hooks > 0) then -- Accumulate the stats for each hook local total_duration = 0 local num_calls = 0 local sum_avg_speed = 0 local count_avg_speed = 0 for mod_fn, mod_benchmark in pairsByKeys(user_script.benchmark or {}, asc) do total_duration = total_duration + mod_benchmark["tot_elapsed"] num_calls = num_calls + mod_benchmark["tot_num_calls"] sum_avg_speed = sum_avg_speed + mod_benchmark["avg_speed"] count_avg_speed = count_avg_speed + 1 end local avg_speed = (sum_avg_speed / count_avg_speed) print("") print("") print("") else print("") end end end print("") print[[
]] print(i18n("flow_callbacks.callback")) print[[]] print(i18n("chart")) print[[]] print(i18n("flow_callbacks.callback_config")) print[[]] print(i18n("flow_callbacks.callback_function")) print[[]] print(i18n("flow_callbacks.last_duration")) print[[]] print(i18n("flow_callbacks.last_num_calls")) print[[]] print(i18n("flow_callbacks.last_calls_per_sec")) print[[
".. title .."
") print(""..description..".
") if(ts_utils.exists("user_script:duration", {ifid=ifid, user_script=mod_k, subdir="flow"})) then print('') end print("") if(user_script.gui and user_script.gui.input_builder) then print(user_script.gui.input_builder(user_script)) else print('') end print("".. mod_fn .."".. format_utils.secondsToTime(mod_benchmark["tot_elapsed"]) .."".. format_utils.formatValue(mod_benchmark["tot_num_calls"]) .."".. format_utils.formatValue(round(mod_benchmark["avg_speed"], 0)) .."
".. format_utils.secondsToTime(total_duration) .."".. format_utils.formatValue(num_calls) .."".. format_utils.formatValue(round(avg_speed, 0)) .."
]] end -- ################################# function flow_callbacks_utils.print_callbacks_config() local show_advanced_prefs = false if(_GET["show_advanced_prefs"] == "1") then show_advanced_prefs = true end local ifid = interface.getId() local descr = user_scripts.load(user_scripts.script_types.flow, ifid, "flow", nil, true --[[ also return disabled ]]) print [[
]] if table.len(_POST) > 0 then for mod_key, user_script in pairs(descr.modules) do local pref_key = "enabled_" .. mod_key local val = _POST[pref_key] if(val ~= nil) then if(val == "on") then user_scripts.enableModule(ifid, "flow", mod_key) user_script.enabled = true else user_scripts.disableModule(ifid, "flow", mod_key) user_script.enabled = false end end end end print[[
]] print_callbacks_config_table(descr, show_advanced_prefs) print[[]] print[[]] print[[
]] print[[
]] local cls_on = "btn btn-sm" local cls_off = cls_on if show_advanced_prefs then cls_on = cls_on..' btn-primary active' cls_off = cls_off..' btn-default' else cls_on = cls_on..' btn-default' cls_off = cls_off..' btn-primary active' end print('') print('') print[[
]] print("
" .. i18n("flow_callbacks.notes") .. ":
") end return flow_callbacks_utils