2
-- (C) 2013-14 - ntop.org
6
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
10
sendHTTPHeader('text/html')
12
mode = _GET["mode"] --l4,l7,host
13
pid = tonumber(_GET["pid"])
17
if (debug) then setTraceLevel(TRACE_DEBUG) end
19
interface.find(ifname)
22
flows = interface.findPidFlows(pid)
23
elseif (name ~= nil) then
24
flows = interface.findNameFlows(name)
32
print('[ { "label": "No flows", "value": 1 } ]') -- No flows found
36
for k,f in pairs(flows) do
38
traceError(TRACE_DEBUG,TRACE_CONSOLE,"Cli:"..f["cli.ip"].." - Srv:"..f["srv.ip"])
40
if((host ~= nil) and ((f["cli.ip"] ~= host) and (f["srv.ip"] ~= host))) then
46
v = f["cli2srv.bytes"] + f["srv2cli.bytes"]
48
elseif(mode == "l4") then
51
v = f["cli2srv.bytes"] + f["srv2cli.bytes"]
52
elseif(mode == "host") then
53
if ((f["client_process"] ~= nil) and (f["client_process"]["name"] == name)) then
54
-- key = f["cli.source_id"].."-"..f["cli.ip"].."(client)"
55
key = f["cli.ip"].."(client)"
56
v = f["cli2srv.bytes"]
57
elseif ((f["server_process"] ~= nil) and (f["server_process"]["name"] == name)) then
58
-- key = f["srv.source_id"].."-"..f["srv.ip"].."(server)"
59
key = f["srv.ip"].."(server)"
60
v = f["srv2cli.bytes"]
64
if((key ~= nil) and (process == 1))then
65
if(apps[key] == nil) then apps[key] = 0 end
66
traceError(TRACE_DEBUG,TRACE_CONSOLE,"key: "..key..",value: "..apps[key])
67
apps[key] = apps[key] + v
72
-- Print up to this number of entries
75
-- Print entries whose value >= 5% of the total
76
threshold = (tot * 5) / 100
82
for key, value in pairs(apps) do
83
if((num ~= 0) and (value < threshold)) then
91
print("\t { \"label\": \"" .. key .."\", \"value\": ".. value .." }")
92
accumulate = accumulate + value
95
if(num == max_num_entries) then
100
if((num == 0) and (top_key ~= nil)) then
101
print("\t { \"label\": \"" .. top_key .."\", \"value\": ".. top_value ..", \"url\": \"/lua/host_details.lua?host=".. top_key .."\" }")
102
accumulate = accumulate + top_value
105
-- In case there is some leftover do print it as "Other"
106
if(accumulate < tot) then
107
if(num > 0) then print(",") end
108
print("\n\t { \"label\": \"Other\", \"value\": ".. (tot-accumulate) .." }")