Added probe data page (#8510)

This commit is contained in:
Matteo Biscosi 2024-07-10 12:16:40 +02:00
parent a789c34c8b
commit e8ab07bd51
8 changed files with 298 additions and 134 deletions

View file

@ -1,7 +1,6 @@
--
-- (C) 2013-21 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
@ -19,52 +18,67 @@ local rest_utils = require("rest_utils")
local rc = rest_utils.consts.success.ok
local res = {}
local ifid = _GET["ifid"]
local ifid = _GET["ifid"] or interface.getId()
if isEmptyString(ifid) then
rc = rest_utils.consts.err.invalid_interface
rest_utils.answer(rc)
return
rc = rest_utils.consts.err.invalid_interface
rest_utils.answer(rc)
return
end
interface.select(ifid)
local ifstats = interface.getStats()
local probes_stats = ifstats.probes or {}
local timeseries_enabled = areFlowdevTimeseriesEnabled()
if interface.isView() then
local zmq_stats = {}
local exporters_stats = {}
for interface_id, _ in pairsByKeys(interface.getIfNames() or {}) do
interface.select(interface_id)
if interface.isViewed() then
local tmp = interface.getStats()
for k, v in pairs(tmp.probes or {}) do
v.exporters = tmp.exporters or {}
v.ifid = interface_id
probes_stats[k] = v
end
end
end
ifstats.probes = probes_stats
interface.select(ifstats.id)
end
for k, v in pairs(ifstats.probes or {}) do
local nprobe_interface = i18n("if_stats_overview.remote_probe_collector_mode")
local flow_drops = 0
local exported_flows = 0
local probe_active = false
if interface.getHostInfo(v["probe.ip"]) then
probe_active = true
end
if v["remote.name"] ~= "none" then
nprobe_interface = string.format("%s [%s]", v["remote.name"], bitsToSize(v["remote.ifspeed"]*1000000))
end
for _, values in pairs(v.exporters or ifstats.exporters or {}) do
flow_drops = flow_drops + values.num_drops
exported_flows = exported_flows + values.num_netflow_flows + values.num_sflow_flows
end
local nprobe_version = v["probe.probe_version"]
if not isEmptyString(v["probe.probe_os"]) then
nprobe_version = string.format("%s (%s)", nprobe_version, v["probe.probe_os"])
end
local nprobe_probe_ip = ip2detailshref(v["probe.ip"], 0, nil, v["probe.ip"], nil, true)
local nprobe_probe_public_ip
if not isEmptyString(v["probe.public_ip"]) then
nprobe_probe_public_ip = ip2detailshref(v["probe.public_ip"], 0, nil, v["probe.public_ip"], nil, true)
end
local nprobe_edition = v["probe.probe_edition"]
local nprobe_license = v["probe.probe_license"] or i18n("if_stats_overview.no_license")
local nprobe_maintenance = v["probe.probe_maintenance"] or i18n("if_stats_overview.expired_maintenance")
local record = {
column_nprobe_interface = nprobe_interface,
column_nprobe_version = nprobe_version,
column_nprobe_edition = nprobe_edition,
column_nprobe_license = nprobe_license,
column_nprobe_maintenance = nprobe_maintenance,
column_nprobe_probe_ip = nprobe_probe_ip,
column_nprobe_probe_public_ip = nprobe_probe_public_ip,
}
res[#res + 1] = record
res[#res + 1] = {
probe_interface = ternary((v["remote.name"] ~= "none"), v["remote.name"],
i18n("if_stats_overview.remote_probe_collector_mode")),
probe_version = v["probe.probe_version"],
probe_ip = v["probe.ip"],
probe_uuid = v["probe.uuid"],
probe_public_ip = v["probe.public_ip"],
probe_edition = v["probe.probe_edition"],
probe_license = v["probe.probe_license"] or i18n("if_stats_overview.no_license"),
probe_maintenance = v["probe.probe_maintenance"] or i18n("if_stats_overview.expired_maintenance"),
flow_exporters = table.len(v.exporters or ifstats.exporters or {} or {}),
dropped_flows = flow_drops,
exported_flows = exported_flows,
timeseries_enabled = timeseries_enabled,
ifid = v.ifid,
is_probe_active = probe_active
}
end
rest_utils.answer(rc, res)