Enchanted inactive hosts page (#7562)

This commit is contained in:
Matteo Biscosi 2023-06-21 15:53:45 +00:00
parent 42c9542f6a
commit 5efa3bce40
7 changed files with 291 additions and 48 deletions

View file

@ -0,0 +1,58 @@
--
-- (C) 2013-23 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
require "mac_utils"
local rest_utils = require "rest_utils"
local inactive_hosts_utils = require "inactive_hosts_utils"
local discover_utils = require "discover_utils"
if not isAdministratorOrPrintErr() then
rest_utils.answer(rest_utils.consts.err.not_granted)
return
end
-- =============================
local ifid = _GET["ifid"]
local action = _GET["action"]
local vlan_id = _GET["vlan_id"]
local network = _GET["network"]
if not isEmptyString(ifid) then
interface.select(ifid)
else
ifid = interface.getId()
end
if isEmptyString(action) then
return rest_utils.answer(rest_utils.consts.err.invalid_args)
end
local network_filters = {}
local vlan_filters = {}
network_filters = inactive_hosts_utils.getNetworkFilters(ifid)
vlan_filters = inactive_hosts_utils.getVLANFilters(ifid)
local rsp = {
{
action = "vlan_id",
label = i18n("vlan"),
tooltip = i18n("vlan_filter"),
name = "vlan_filter",
value = vlan_filters
},
{
action = "network",
label = i18n("network"),
tooltip = i18n("network_filter"),
name = "network_filter",
value = network_filters
},
}
rest_utils.answer(rest_utils.consts.success.ok, rsp)

View file

@ -18,6 +18,16 @@ end
-- =============================
local ifid = _GET["ifid"]
local filters = {
vlan = _GET["vlan_id"],
network = _GET["network"]
}
for filter, value in pairs(filters) do
if isEmptyString(value) then
filters[filter] = nil
end
end
if not isEmptyString(ifid) then
interface.select(ifid)
@ -26,7 +36,7 @@ else
end
local rsp = {}
local hosts = inactive_hosts_utils.getInactiveHosts(ifid)
local hosts = inactive_hosts_utils.getInactiveHosts(ifid, filters)
-- Check if at least an host is inactive
if table.len(hosts) > 0 then
@ -77,19 +87,24 @@ if table.len(hosts) > 0 then
}
end
if interface.getVLANInfo(rsp[key]["vlan_id"]) then
rsp[key]["vlan"] = {
rsp[key]["host"] = {
ip_address = {
name = rsp[key]["ip_address"],
value = rsp[key]["ip_address"],
url = '/lua/inactive_host_details.lua?serial_key=' .. rsp[key]["serial_key"]
},
}
if rsp[key]["vlan_id"] then
rsp[key]["host"]["vlan"] = {
name = rsp[key]["vlan"],
value = rsp[key]["vlan_id"],
url = '/lua/hosts_stats.lua?vlan=' .. rsp[key]["vlan_id"]
}
if interface.getVLANInfo(rsp[key]["vlan_id"]) then
rsp[key]["host"]["vlan"]["url"] = '/lua/hosts_stats.lua?vlan=' .. rsp[key]["vlan_id"]
end
end
rsp[key]["ip_address"] = {
name = rsp[key]["ip_address"],
value = rsp[key]["ip_address"],
url = '/lua/inactive_host_details.lua?serial_key=' .. rsp[key]["serial_key"]
}
rsp[key]["device_id"] = nil
rsp[key]["network_id"] = nil
rsp[key]["vlan_id"] = nil