mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Extends host_get_json to optionally include host flows statistics
This commit is contained in:
parent
18e8e57db5
commit
f8298cbb58
1 changed files with 41 additions and 2 deletions
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
--
|
||||
-- (C) 2013-15 - ntop.org
|
||||
--
|
||||
|
|
@ -6,8 +7,17 @@ dirs = ntop.getDirs()
|
|||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
require "lua_utils"
|
||||
local json = require ("dkjson")
|
||||
|
||||
-- whether to return host statistics: on by default
|
||||
local host_stats = _GET["host_stats"]
|
||||
|
||||
-- whether to return statistics regarding host flows: off by default
|
||||
local host_stats_flows = _GET["host_stats_flows"]
|
||||
local host_stats_flows_num = _GET["host_stats_flows_num"]
|
||||
|
||||
host_info = url2hostinfo(_GET)
|
||||
host = _GET["host"]
|
||||
|
||||
if(host_info["host"] == nil) then
|
||||
sendHTTPHeader('text/html; charset=iso-8859-1')
|
||||
|
|
@ -28,5 +38,34 @@ if(host == nil) then
|
|||
return
|
||||
else
|
||||
sendHTTPHeader('application/json')
|
||||
print(host["json"])
|
||||
end
|
||||
local hj = {}
|
||||
-- hosts stats are on by default, one must explicitly disable them
|
||||
if host_stats == nil or host_stats == "" or host_stats == "true" or host_stats == "1" then
|
||||
hj = json.decode(host["json"])
|
||||
end
|
||||
|
||||
-- host flow stats are off by default and must be explicitly enabled
|
||||
if host_stats_flows ~= nil and host_stats_flows ~= "" then
|
||||
if host_stats_flows_num == nil or tonumber(host_stats_flows_num) == nil then
|
||||
-- default the number of flows returned to 20 ...
|
||||
host_stats_flows_num = 20
|
||||
else
|
||||
-- ... unless otherwise specified
|
||||
host_stats_flows_num = tonumber(host_stats_flows_num)
|
||||
end
|
||||
local total = 0
|
||||
local flows = interface.getFlowsInfo(host, nil, "column_bytes", host_stats_flows_num, 0, false)
|
||||
flows,total = aggregateFlowsStats(flows)
|
||||
for i, fl in ipairs(flows) do
|
||||
flows[i] = {
|
||||
["srv.ip"] = fl["srv.ip"], ["cli.ip"] = fl["cli.ip"],
|
||||
["srv.port"] = fl["srv.port"], ["cli.port"] = fl["cli.port"],
|
||||
["proto.ndpi_id"] = fl["proto.ndpi_id"], ["proto.ndpi"] = fl["proto.ndpi"],
|
||||
["bytes"] = fl["bytes"]
|
||||
}
|
||||
end
|
||||
hj["flows"] = flows
|
||||
hj["flows_count"] = math.min(total, host_stats_flows_num)
|
||||
end
|
||||
print(json.encode(hj, nil))
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue