Reworked host packets page and removed dscp page

This commit is contained in:
MatteoBiscosi 2022-11-09 16:44:12 +01:00
parent cfbb3306b3
commit 4ed6ae9d8a
10 changed files with 337 additions and 100 deletions

View file

@ -0,0 +1,40 @@
--
-- (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 rsp = {
labels = {},
series = {},
colors = {},
}
if host_stats then
local eth_stats = interface.getMacInfo(host_stats["mac"])
if eth_stats then
local arp_sent = eth_stats["arp_requests.sent"] + eth_stats["arp_replies.sent"]
local arp_rcvd = eth_stats["arp_requests.rcvd"] + eth_stats["arp_replies.rcvd"]
rsp["labels"][1] = i18n("sent")
rsp["series"][1] = arp_sent
rsp["colors"][1] = graph_utils.get_html_color(1)
rsp["labels"][2] = i18n("received")
rsp["series"][2] = arp_rcvd
rsp["colors"][2] = graph_utils.get_html_color(2)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,44 @@
--
-- (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 stats_utils = require "stats_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 rsp = {
labels = {},
series = {},
colors = {},
show = true
}
if host_stats and host_stats["pktStats.recv"] then
local serie = {}
local current_data = 0
local data = host_stats["pktStats.recv"]["size"]
for label, value in pairs(data or {}) do
serie[#serie + 1] = { label = label, value = value }
end
local collapsed = stats_utils.collapse_stats(serie, 1, 5 --[[ threshold ]])
for _, value in pairs(collapsed or {}) do
current_data = current_data + 1
rsp["labels"][#rsp["labels"] + 1] = value.label
rsp["series"][#rsp["series"] + 1] = value.value
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,43 @@
--
-- (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 stats_utils = require "stats_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 rsp = {
labels = {},
series = {},
colors = {},
}
if host_stats and host_stats["pktStats.sent"] then
local serie = {}
local current_data = 0
local data = host_stats["pktStats.sent"]["size"]
for label, value in pairs(data or {}) do
serie[#serie + 1] = { label = label, value = value }
end
local collapsed = stats_utils.collapse_stats(serie, 1, 5 --[[ threshold ]])
for _, value in pairs(collapsed or {}) do
current_data = current_data + 1
rsp["labels"][#rsp["labels"] + 1] = value.label
rsp["series"][#rsp["series"] + 1] = value.value
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -0,0 +1,55 @@
--
-- (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 current_data = 0
local rsp = {
labels = {},
series = {},
colors = {},
}
local pkt_distribution = {
['syn'] = 'SYN',
['synack'] = 'SYN/ACK',
['finack'] = 'FIN/ACK',
['rst'] = 'RST',
}
if host_stats and host_stats["pktStats.sent"] then
local serie = {}
local current_data = 0
local data = host_stats["pktStats.sent"]["tcp_flags"]
for label, value in pairs(data or {}) do
serie[label] = value
end
data = host_stats["pktStats.recv"]["tcp_flags"]
for label, value in pairs(data or {}) do
serie[label] = serie[label] + value
end
for label, value in pairs(serie or {}) do
current_data = current_data + 1
rsp["labels"][#rsp["labels"] + 1] = pkt_distribution[label]
rsp["series"][#rsp["series"] + 1] = value
rsp["colors"][#rsp["colors"] + 1] = graph_utils.get_html_color(current_data)
end
end
rest_utils.answer(rest_utils.consts.success.ok, rsp)