-- -- (C) 2013-17 - ntop.org -- dirs = ntop.getDirs() package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path require "lua_utils" require "graph_utils" require "historical_utils" sendHTTPHeader('text/html; charset=iso-8859-1') ifid = _GET["ifid"] direction = _GET["sflow_filter"] interface.select(ifid) host_info = url2hostinfo(_GET) host_ip = host_info["host"] host_vlan = host_info["vlan"] host = interface.getHostInfo(host_ip, host_vlan) host_ndpi_rrd_creation = ntop.getCache("ntopng.prefs.host_ndpi_rrd_creation") local now = os.time() local ago1h = now - 3600 local protos = interface.getnDPIProtocols() if(host == nil) then print("
Unable to find "..host_ip.." (data expired ?)
") return end local FILTER_SENT_ONLY = "sent" local FILTER_RECV_ONLY = "recv" vals = {} for k in pairs(host["ndpi"]) do vals[k] = k -- print(k) end table.sort(vals) local filter_pass = function(row) local isok if direction == FILTER_SENT_ONLY and row["bytes.rcvd"] ~= 0 then isok = false elseif direction == FILTER_RECV_ONLY and row["bytes.sent"] ~= 0 then isok = false else isok = true end return isok end local total_sent local total_recv if direction ~= nil then total_sent = 0 total_recv = 0 for _k in pairsByKeys(vals , desc) do k = vals[_k] if filter_pass(host["ndpi"][k]) then total_sent = total_sent + host["ndpi"][k]["bytes.sent"] total_recv = total_recv + host["ndpi"][k]["bytes.rcvd"] end end else total_sent = host["bytes.sent"] total_recv = host["bytes.rcvd"] end local total = total_sent + total_recv print("Total" .. bytesToSize(total_sent) .. "" .. bytesToSize(total_recv) .. "") print("") breakdownBar(total_sent, "Sent", total_recv, "Rcvd", 0, 100) print("\n") print("" .. bytesToSize(total).. "\n") for _k in pairsByKeys(vals , desc) do k = vals[_k] if filter_pass(host["ndpi"][k]) then print("") fname = getRRDName(ifid, hostinfo2hostkey(host_info), k..".rrd") if(ntop.exists(fname)) then print(""..k.." "..formatBreed(host["ndpi"][k]["breed"]).."") else print(k.." "..formatBreed(host["ndpi"][k]["breed"])) end t = host["ndpi"][k]["bytes.sent"]+host["ndpi"][k]["bytes.rcvd"] if((host["ndpi"][k]["bytes.sent"] == 0) and (host["ndpi"][k]["bytes.rcvd"] > 0)) then print(" ") end historicalProtoHostHref(getInterfaceId(ifname), host, nil, protos[k], nil) print('') print("" .. bytesToSize(host["ndpi"][k]["bytes.sent"]) .. "" .. bytesToSize(host["ndpi"][k]["bytes.rcvd"]) .. "") print("") breakdownBar(host["ndpi"][k]["bytes.sent"], "Sent", host["ndpi"][k]["bytes.rcvd"], "Rcvd", 0, 100) print("\n") print("" .. bytesToSize(t).. "" .. round((t * 100)/total, 2).. " %\n") end end if host_ndpi_rrd_creation ~= "1" then print(" NOTE:") end print("

")