mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-05 02:16:39 +00:00
Updated host details l7 page (#6803)
This commit is contained in:
parent
0aa60f5001
commit
c1c7b09e47
12 changed files with 688 additions and 230 deletions
38
scripts/lua/rest/v2/get/host/l7/breed_data.lua
Normal file
38
scripts/lua/rest/v2/get/host/l7/breed_data.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
--
|
||||
-- (C) 2013-22 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
-- Imports
|
||||
require "lua_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
local graph_utils = require "graph_utils"
|
||||
|
||||
-- Local variables
|
||||
local host_ip = _GET["host"]
|
||||
local vlan = _GET["vlan"]
|
||||
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
|
||||
local max_data = 10
|
||||
local current_data = 0
|
||||
local rsp = {
|
||||
labels = {},
|
||||
series = {},
|
||||
colors = {},
|
||||
}
|
||||
|
||||
local ifstats = computeL7Stats(host_stats, true --[[ show breed ]], false --[[ show ndpi category ]])
|
||||
|
||||
for key, value in pairsByValues(ifstats, rev) do
|
||||
current_data = current_data + 1
|
||||
rsp["labels"][#rsp["labels"] + 1] = key
|
||||
rsp["series"][#rsp["series"] + 1] = value
|
||||
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
|
||||
|
||||
if current_data >= max_data then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, rsp)
|
||||
38
scripts/lua/rest/v2/get/host/l7/cat_data.lua
Normal file
38
scripts/lua/rest/v2/get/host/l7/cat_data.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
--
|
||||
-- (C) 2013-22 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
-- Imports
|
||||
require "lua_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
local graph_utils = require "graph_utils"
|
||||
|
||||
-- Local variables
|
||||
local host_ip = _GET["host"]
|
||||
local vlan = _GET["vlan"]
|
||||
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
|
||||
local max_data = 10
|
||||
local current_data = 0
|
||||
local rsp = {
|
||||
labels = {},
|
||||
series = {},
|
||||
colors = {},
|
||||
}
|
||||
|
||||
local ifstats = computeL7Stats(host_stats, false --[[ show breed ]], true --[[ show ndpi category ]])
|
||||
|
||||
for key, value in pairsByValues(ifstats, rev) do
|
||||
current_data = current_data + 1
|
||||
rsp["labels"][#rsp["labels"] + 1] = key
|
||||
rsp["series"][#rsp["series"] + 1] = value
|
||||
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(interface.getnDPICategoryId(key))
|
||||
|
||||
if current_data >= max_data then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, rsp)
|
||||
70
scripts/lua/rest/v2/get/host/l7/data.lua
Normal file
70
scripts/lua/rest/v2/get/host/l7/data.lua
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
--
|
||||
-- (C) 2013-22 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
-- Imports
|
||||
require "lua_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
|
||||
-- Local variables
|
||||
local host_ip = _GET["host"]
|
||||
local vlan = _GET["vlan"]
|
||||
local view = _GET["view"]
|
||||
local host = interface.getHostInfo(host_ip, vlan) or {}
|
||||
local total_bytes = 0
|
||||
local rsp = {}
|
||||
|
||||
-- Applications
|
||||
if view == 'applications' then
|
||||
local host_applications = host["ndpi"]
|
||||
|
||||
-- Calculate the total bytes sent and received, to calculate the percentages
|
||||
for _, v in pairs(host_applications) do
|
||||
total_bytes = total_bytes + v["bytes.rcvd"] + v["bytes.sent"]
|
||||
end
|
||||
|
||||
-- Now format the values
|
||||
for k, v in pairs(host_applications) do
|
||||
local tot_l7_bytes = v["bytes.sent"] + v["bytes.rcvd"]
|
||||
|
||||
rsp[#rsp + 1] = {
|
||||
application = {
|
||||
id = interface.getnDPIProtoId(k),
|
||||
label = k,
|
||||
},
|
||||
duration = v["duration"],
|
||||
bytes_sent = v["bytes.sent"],
|
||||
bytes_rcvd = v["bytes.rcvd"],
|
||||
tot_bytes = tot_l7_bytes,
|
||||
percentage = (tot_l7_bytes * 100) / total_bytes,
|
||||
}
|
||||
end
|
||||
else
|
||||
-- Categories
|
||||
local categories_utils = require "categories_utils"
|
||||
local host_categories = host["ndpi_categories"]
|
||||
|
||||
-- Calculate the total bytes sent and received, to calculate the percentages
|
||||
for _, v in pairs(host_categories) do
|
||||
total_bytes = total_bytes + v["bytes"]
|
||||
end
|
||||
|
||||
-- Now format the values
|
||||
for k, v in pairs(host_categories) do
|
||||
rsp[#rsp + 1] = {
|
||||
category = {
|
||||
id = interface.getnDPICategoryId(k),
|
||||
label = getCategoryLabel(k, v.category),
|
||||
},
|
||||
applications = categories_utils.get_category_protocols_list(v.category, true),
|
||||
duration = v["duration"],
|
||||
tot_bytes = v["bytes"],
|
||||
percentage = (v["bytes"] * 100) / total_bytes,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, rsp)
|
||||
38
scripts/lua/rest/v2/get/host/l7/proto_data.lua
Normal file
38
scripts/lua/rest/v2/get/host/l7/proto_data.lua
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
--
|
||||
-- (C) 2013-22 - ntop.org
|
||||
--
|
||||
|
||||
dirs = ntop.getDirs()
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
-- Imports
|
||||
require "lua_utils"
|
||||
local rest_utils = require "rest_utils"
|
||||
local graph_utils = require "graph_utils"
|
||||
|
||||
-- Local variables
|
||||
local host_ip = _GET["host"]
|
||||
local vlan = _GET["vlan"]
|
||||
local host_stats = interface.getHostInfo(host_ip, vlan) or {}
|
||||
local max_data = 10
|
||||
local current_data = 0
|
||||
local rsp = {
|
||||
labels = {},
|
||||
series = {},
|
||||
colors = {},
|
||||
}
|
||||
|
||||
local ifstats = computeL7Stats(host_stats, false --[[ show breed ]], false --[[ show ndpi category ]])
|
||||
|
||||
for key, value in pairsByValues(ifstats, rev) do
|
||||
current_data = current_data + 1
|
||||
rsp["labels"][#rsp["labels"] + 1] = key
|
||||
rsp["series"][#rsp["series"] + 1] = value
|
||||
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(interface.getnDPIProtoId(key))
|
||||
|
||||
if current_data >= max_data then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
rest_utils.answer(rest_utils.consts.success.ok, rsp)
|
||||
Loading…
Add table
Add a link
Reference in a new issue