-- -- (C) 2013-17 - ntop.org -- dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path require "lua_utils" require "flow_utils" local json = require ("dkjson") sendHTTPHeader('text/html; charset=iso-8859-1') local debug = false ----------------------------------- function setAggregatedFlow(p_id,p_ip_address,p_value,p_what) if (what_array[p_id] == nil) then what_array[p_id] = {} what_array[p_id]["value"] = 0 what_array[p_id]["url"] = url..p_what.."&host="..p_ip_address end if ((how_is_process == 1) or (how_is_latency == 1))then if ( what_array[p_id]["value"] == 0) then what_array[p_id]["value"] = p_value end else what_array[p_id]["value"] = what_array[p_id]["value"] + p_value end end ----------------------------------- function getAggretationValue(flow,flow_key,type) l_how = 0; process_key = "client_process" bytes_key = "cli2srv.bytes" if (type == "server") then process_key = "server_process" bytes_key = "srv2cli.bytes" end if (how_is_process == 1) then l_how = flow[process_key][how] elseif (how_is_latency == 1) then flow_more_info = interface.findFlowByKey(flow_key) local info, pos, err = json.decode(flow_more_info["moreinfo.json"], 1, nil) for k,v in pairs(info) do if("Application latency (residual usec)" == getFlowKey(k)) then l_how = tonumber(handleCustomFlowField(k, v)) end end else l_how = flow[bytes_key] end return l_how; end ----------------------------------- function setType(p_type) if((p_type == nil) or (p_type == "memory")) then how = "actual_memory" how_is_process = 1 elseif (p_type == "bytes") then how = "bytes" elseif (p_type == "latency") then how_is_latency = 1 how = "Application latency (residual usec)" end if (debug) then io.write("How:"..how.."\n"); end end ----------------------------------- function setMode(p_mode) if((p_mode == nil) or (p_mode == "user")) then what = "user_name" url = ntop.getHttpPrefix().."/lua/get_user_info.lua?username=" elseif (p_mode == "process") then what = "name" url = ntop.getHttpPrefix().."/lua/get_process_info.lua?pid_name=" end if (debug) then io.write("what:"..what..",url:"..url.."\n"); end end ----------------------------------- function setFilter(p_filter) if((p_filter == nil) or (p_filter == "All")) then filter_client = 1 filter_server = 1 elseif (p_filter == "Client") then filter_client = 1 elseif (p_filter == "Server") then filter_server = 1 end if (debug) then io.write("Client:"..filter_client..", Server:"..filter_server.."\n"); end end ----------------------------------- mode = _GET["sflowdistro_mode"] -- memory(actual-memory),bytes,latency type = _GET["distr"] -- user,process(proc_name) host = _GET["host"] filter = _GET["sflow_filter"] -- all,client,server interface.select(ifname) if(host == nil) then print("