mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 07:59:35 +00:00
Added REST parameters, mac, pool, pool_id (#8807)
This commit is contained in:
parent
2aa46f98ac
commit
35e0a4d1e2
1 changed files with 77 additions and 72 deletions
|
|
@ -7,9 +7,9 @@ package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
|||
|
||||
require "lua_utils"
|
||||
require "flow_utils"
|
||||
local format_utils = require("format_utils")
|
||||
local json = require "dkjson"
|
||||
local rest_utils = require("rest_utils")
|
||||
local host_pools = require "host_pools"
|
||||
local rest_utils = require("rest_utils")
|
||||
local host_pools_instance = host_pools:create()
|
||||
|
||||
--
|
||||
-- Read list of active hosts
|
||||
|
|
@ -18,22 +18,22 @@ local rest_utils = require("rest_utils")
|
|||
-- NOTE: in case of invalid login, no error is returned but redirected to login
|
||||
--
|
||||
|
||||
local rc = rest_utils.consts.success.ok
|
||||
local res = {}
|
||||
local rc = rest_utils.consts.success.ok
|
||||
local res = {}
|
||||
|
||||
local ifid = _GET["ifid"]
|
||||
local ifid = _GET["ifid"]
|
||||
|
||||
-- Pagination:
|
||||
local all = _GET["all"]
|
||||
local currentPage = _GET["currentPage"]
|
||||
local perPage = _GET["perPage"]
|
||||
local sortColumn = _GET["sortColumn"] -- ip, name, since, last, alerts, country, vlan, num_flows, traffic, thpt
|
||||
local sortOrder = _GET["sortOrder"]
|
||||
local all = _GET["all"]
|
||||
local currentPage = _GET["currentPage"]
|
||||
local perPage = _GET["perPage"]
|
||||
local sortColumn = _GET["sortColumn"] -- ip, name, since, last, alerts, country, vlan, num_flows, traffic, thpt
|
||||
local sortOrder = _GET["sortOrder"]
|
||||
|
||||
-- Filters
|
||||
local mode = _GET["mode"] -- all local remote broadcast_domain filtered blacklisted dhcp
|
||||
local ipversion = _GET["version"]
|
||||
local protocol = _GET["protocol"]
|
||||
local mode = _GET["mode"] -- all local remote broadcast_domain filtered blacklisted dhcp
|
||||
local ipversion = _GET["version"]
|
||||
local protocol = _GET["protocol"]
|
||||
local traffic_type = _GET["traffic_type"]
|
||||
local asn = _GET["asn"]
|
||||
local vlan = _GET["vlan"]
|
||||
|
|
@ -55,20 +55,20 @@ interface.select(ifid)
|
|||
if not isEmptyString(_GET["sortColumn"]) then
|
||||
-- Backward compatibility
|
||||
_GET["sortColumn"] = "column_" .. _GET["sortColumn"]
|
||||
sortColumn = _GET["sortColumn"]
|
||||
sortColumn = _GET["sortColumn"]
|
||||
end
|
||||
|
||||
if(currentPage == nil) then
|
||||
if (currentPage == nil) then
|
||||
currentPage = 1
|
||||
else
|
||||
currentPage = tonumber(currentPage)
|
||||
end
|
||||
|
||||
if(perPage == nil) then
|
||||
if (perPage == nil) then
|
||||
perPage = getDefaultTableSize()
|
||||
else
|
||||
perPage = tonumber(perPage)
|
||||
tablePreferences("rows_number",perPage)
|
||||
tablePreferences("rows_number", perPage)
|
||||
end
|
||||
|
||||
local traffic_type_filter
|
||||
|
|
@ -85,9 +85,9 @@ end
|
|||
|
||||
interface.select(ifname)
|
||||
|
||||
local to_skip = (currentPage-1) * perPage
|
||||
local to_skip = (currentPage - 1) * perPage
|
||||
|
||||
if(sortOrder == "desc") then sOrder = false else sOrder = true end
|
||||
if (sortOrder == "desc") then sOrder = false else sOrder = true end
|
||||
|
||||
local filtered_hosts = false
|
||||
local blacklisted = false
|
||||
|
|
@ -115,11 +115,11 @@ if all ~= nil then
|
|||
end
|
||||
|
||||
local hosts_stats = hosts_retrv_function(false, sortColumn, perPage, to_skip, sOrder,
|
||||
country, os_, tonumber(vlan), tonumber(asn),
|
||||
tonumber(network), mac,
|
||||
tonumber(pool), tonumber(ipversion),
|
||||
tonumber(protocol), traffic_type_filter,
|
||||
filtered_hosts, blacklisted_hosts, anomalous, dhcp_hosts, cidr)
|
||||
country, os_, tonumber(vlan), tonumber(asn),
|
||||
tonumber(network), mac,
|
||||
tonumber(pool), tonumber(ipversion),
|
||||
tonumber(protocol), traffic_type_filter,
|
||||
filtered_hosts, blacklisted_hosts, anomalous, dhcp_hosts, cidr)
|
||||
|
||||
if hosts_stats == nil then
|
||||
rest_utils.answer(rest_utils.consts.err.not_found)
|
||||
|
|
@ -141,7 +141,7 @@ function get_host_name(h)
|
|||
h["name"] = h["mac"]
|
||||
end
|
||||
end
|
||||
return(h["name"])
|
||||
return (h["name"])
|
||||
end
|
||||
|
||||
local vals = {}
|
||||
|
|
@ -150,35 +150,35 @@ for key, value in pairs(hosts_stats) do
|
|||
num = num + 1
|
||||
postfix = string.format("0.%04u", num)
|
||||
|
||||
if(isEmptyString(sortColumn)) then
|
||||
if (isEmptyString(sortColumn)) then
|
||||
vals[key] = key
|
||||
elseif(sortColumn == "column_name") then
|
||||
elseif (sortColumn == "column_name") then
|
||||
hosts_stats[key]["name"] = get_host_name(hosts_stats[key])
|
||||
vals[hosts_stats[key]["name"]..postfix] = key
|
||||
elseif(sortColumn == "column_since") then
|
||||
vals[hosts_stats[key]["seen.first"]+postfix] = key
|
||||
elseif(sortColumn == "column_alerts") then
|
||||
vals[hosts_stats[key]["num_alerts"]+postfix] = key
|
||||
elseif(sortColumn == "column_last") then
|
||||
vals[hosts_stats[key]["seen.last"]+postfix] = key
|
||||
elseif(sortColumn == "column_country") then
|
||||
vals[hosts_stats[key]["country"]..postfix] = key
|
||||
elseif(sortColumn == "column_vlan") then
|
||||
vals[hosts_stats[key]["vlan"]..postfix] = key
|
||||
elseif(sortColumn == "column_num_flows") then
|
||||
local t = hosts_stats[key]["active_flows.as_client"]+hosts_stats[key]["active_flows.as_server"]
|
||||
vals[t+postfix] = key
|
||||
elseif(sortColumn == "column_num_dropped_flows") then
|
||||
vals[hosts_stats[key]["name"] .. postfix] = key
|
||||
elseif (sortColumn == "column_since") then
|
||||
vals[hosts_stats[key]["seen.first"] + postfix] = key
|
||||
elseif (sortColumn == "column_alerts") then
|
||||
vals[hosts_stats[key]["num_alerts"] + postfix] = key
|
||||
elseif (sortColumn == "column_last") then
|
||||
vals[hosts_stats[key]["seen.last"] + postfix] = key
|
||||
elseif (sortColumn == "column_country") then
|
||||
vals[hosts_stats[key]["country"] .. postfix] = key
|
||||
elseif (sortColumn == "column_vlan") then
|
||||
vals[hosts_stats[key]["vlan"] .. postfix] = key
|
||||
elseif (sortColumn == "column_num_flows") then
|
||||
local t = hosts_stats[key]["active_flows.as_client"] + hosts_stats[key]["active_flows.as_server"]
|
||||
vals[t + postfix] = key
|
||||
elseif (sortColumn == "column_num_dropped_flows") then
|
||||
local t = hosts_stats[key]["flows.dropped"] or 0
|
||||
vals[t+postfix] = key
|
||||
elseif(sortColumn == "column_traffic") then
|
||||
vals[hosts_stats[key]["bytes.sent"]+hosts_stats[key]["bytes.rcvd"]+postfix] = key
|
||||
elseif(sortColumn == "column_thpt") then
|
||||
vals[hosts_stats[key]["throughput_bps"]+postfix] = key
|
||||
elseif(sortColumn == "column_queries") then
|
||||
vals[hosts_stats[key]["queries.rcvd"]+postfix] = key
|
||||
elseif(sortColumn == "column_ip") then
|
||||
vals[hosts_stats[key]["ipkey"]+postfix] = key
|
||||
vals[t + postfix] = key
|
||||
elseif (sortColumn == "column_traffic") then
|
||||
vals[hosts_stats[key]["bytes.sent"] + hosts_stats[key]["bytes.rcvd"] + postfix] = key
|
||||
elseif (sortColumn == "column_thpt") then
|
||||
vals[hosts_stats[key]["throughput_bps"] + postfix] = key
|
||||
elseif (sortColumn == "column_queries") then
|
||||
vals[hosts_stats[key]["queries.rcvd"] + postfix] = key
|
||||
elseif (sortColumn == "column_ip") then
|
||||
vals[hosts_stats[key]["ipkey"] + postfix] = key
|
||||
else
|
||||
vals[key] = key
|
||||
end
|
||||
|
|
@ -202,7 +202,7 @@ for _key, _value in pairsByKeys(vals, funct) do
|
|||
record["first_seen"] = value["seen.first"]
|
||||
record["last_seen"] = value["seen.last"]
|
||||
record["vlan"] = value["vlan"]
|
||||
record["ip"] = stripVlan(key)
|
||||
record["ip"] = stripVlan(key)
|
||||
record["os"] = value["os"]
|
||||
record["num_alerts"] = value["num_alerts"]
|
||||
|
||||
|
|
@ -210,6 +210,11 @@ for _key, _value in pairsByKeys(vals, funct) do
|
|||
if host ~= nil then
|
||||
record["country"] = host["country"]
|
||||
record["is_blacklisted"] = host["is_blacklisted"]
|
||||
record["mac"] = host["mac"]
|
||||
record["pool"] = {
|
||||
id = host["host_pool_id"],
|
||||
name = host_pools_instance:get_pool_name(host["host_pool_id"])
|
||||
}
|
||||
end
|
||||
|
||||
local name = value["name"]
|
||||
|
|
@ -223,36 +228,36 @@ for _key, _value in pairsByKeys(vals, funct) do
|
|||
if value["ip"] ~= nil then
|
||||
local label = hostinfo2label(value)
|
||||
if label ~= value["ip"] and name ~= label then
|
||||
name = name .. " ["..label.."]"
|
||||
name = name .. " [" .. label .. "]"
|
||||
end
|
||||
end
|
||||
|
||||
record["name"] = name
|
||||
record["name"] = name
|
||||
|
||||
record["score"] = {}
|
||||
record["score"]["total"] = value["score"]
|
||||
record["score"]["as_client"] = value["score.as_client"]
|
||||
record["score"]["as_server"] = value["score.as_server"]
|
||||
record["thpt"] = {}
|
||||
record["thpt"]["pps"] = value["throughput_pps"]
|
||||
record["thpt"]["bps"] = value["throughput_bps"]*8
|
||||
record["score"] = {}
|
||||
record["score"]["total"] = value["score"]
|
||||
record["score"]["as_client"] = value["score.as_client"]
|
||||
record["score"]["as_server"] = value["score.as_server"]
|
||||
record["thpt"] = {}
|
||||
record["thpt"]["pps"] = value["throughput_pps"]
|
||||
record["thpt"]["bps"] = value["throughput_bps"] * 8
|
||||
|
||||
record["bytes"] = {}
|
||||
record["bytes"]["total"] = (value["bytes.sent"]+value["bytes.rcvd"])
|
||||
record["bytes"]["sent"] = value["bytes.sent"]
|
||||
record["bytes"]["recvd"] = value["bytes.rcvd"]
|
||||
record["bytes"] = {}
|
||||
record["bytes"]["total"] = (value["bytes.sent"] + value["bytes.rcvd"])
|
||||
record["bytes"]["sent"] = value["bytes.sent"]
|
||||
record["bytes"]["recvd"] = value["bytes.rcvd"]
|
||||
|
||||
record["is_localhost"] = value["localhost"]
|
||||
record["is_multicast"] = value["is_multicast"]
|
||||
record["is_broadcast"] = value["is_broadcast"]
|
||||
record["is_broadcast_domain"] = value["broadcast_domain_host"]
|
||||
record["is_localhost"] = value["localhost"]
|
||||
record["is_multicast"] = value["is_multicast"]
|
||||
record["is_broadcast"] = value["is_broadcast"]
|
||||
record["is_broadcast_domain"] = value["broadcast_domain_host"]
|
||||
|
||||
record["num_flows"] = {}
|
||||
record["num_flows"] = {}
|
||||
record["num_flows"]["total"] = (value["active_flows.as_client"] + value["active_flows.as_server"])
|
||||
record["num_flows"]["as_client"] = (value["active_flows.as_client"])
|
||||
record["num_flows"]["as_server"] = (value["active_flows.as_server"])
|
||||
|
||||
data[#data + 1] = record
|
||||
data[#data + 1] = record
|
||||
end -- for
|
||||
|
||||
res = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue