mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
Enchanted inactive hosts page (#7562)
This commit is contained in:
parent
42c9542f6a
commit
5efa3bce40
7 changed files with 291 additions and 48 deletions
|
|
@ -13,7 +13,7 @@ local inactive_hosts_utils = {}
|
|||
-- ##########################################
|
||||
|
||||
-- This function return a list of inactive hosts, with all the informations
|
||||
function inactive_hosts_utils.getInactiveHosts(ifid)
|
||||
function inactive_hosts_utils.getInactiveHosts(ifid, filters)
|
||||
local redis_hash = string.format(OFFLINE_LOCAL_HOSTS_KEY, ifid)
|
||||
local available_keys = ntop.getHashKeysCache(redis_hash) or {}
|
||||
local networks_stats = interface.getNetworksStats()
|
||||
|
|
@ -25,6 +25,13 @@ function inactive_hosts_utils.getInactiveHosts(ifid)
|
|||
|
||||
if not isEmptyString(host_info_json) then
|
||||
local host_info = json.decode(host_info_json)
|
||||
|
||||
for filter, value in pairs(filters) do
|
||||
if tostring(host_info[filter]) ~= tostring(value) then
|
||||
goto skip
|
||||
end
|
||||
end
|
||||
|
||||
local mac_manufacturer = ntop.getMacManufacturer(host_info.mac) or {}
|
||||
|
||||
for n, ns in pairs(networks_stats) do
|
||||
|
|
@ -51,6 +58,8 @@ function inactive_hosts_utils.getInactiveHosts(ifid)
|
|||
manufacturer = mac_manufacturer.extended
|
||||
}
|
||||
end
|
||||
|
||||
::skip::
|
||||
end
|
||||
|
||||
return host_list
|
||||
|
|
@ -81,4 +90,100 @@ function inactive_hosts_utils.getInactiveHostsNumber(ifid)
|
|||
return table.len(available_keys)
|
||||
end
|
||||
|
||||
-- ##########################################
|
||||
|
||||
-- This function return a list of inactive hosts, with all the informations
|
||||
function inactive_hosts_utils.getVLANFilters(ifid)
|
||||
local redis_hash = string.format(OFFLINE_LOCAL_HOSTS_KEY, ifid)
|
||||
local available_keys = ntop.getHashKeysCache(redis_hash) or {}
|
||||
local vlan_list = {}
|
||||
local rsp = {}
|
||||
|
||||
for redis_key, _ in pairs(available_keys) do
|
||||
local host_info_json = ntop.getHashCache(redis_hash, redis_key)
|
||||
|
||||
if not isEmptyString(host_info_json) then
|
||||
local host_info = json.decode(host_info_json)
|
||||
if not(vlan_list[host_info.vlan]) then
|
||||
vlan_list[host_info.vlan] = 1
|
||||
else
|
||||
vlan_list[host_info.vlan] = vlan_list[host_info.vlan] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for vlan, count in pairsByKeys(vlan_list) do
|
||||
local vlan_name = ''
|
||||
if vlan == 0 then
|
||||
vlan_name = i18n('no_vlan')
|
||||
else
|
||||
vlan_name = getFullVlanName(vlan)
|
||||
end
|
||||
rsp[#rsp + 1] = {
|
||||
count = count,
|
||||
key = "vlan_id",
|
||||
value = vlan,
|
||||
label = tostring(vlan_name)
|
||||
}
|
||||
end
|
||||
table.insert(rsp, 1, {
|
||||
key = "vlan_id",
|
||||
value = "",
|
||||
label = i18n('flows_page.all_vlan_ids')
|
||||
})
|
||||
|
||||
return rsp
|
||||
end
|
||||
|
||||
-- ##########################################
|
||||
|
||||
-- This function return a list of inactive hosts, with all the informations
|
||||
function inactive_hosts_utils.getNetworkFilters(ifid)
|
||||
local redis_hash = string.format(OFFLINE_LOCAL_HOSTS_KEY, ifid)
|
||||
local available_keys = ntop.getHashKeysCache(redis_hash) or {}
|
||||
local networks_stats = interface.getNetworksStats()
|
||||
local network_list = {}
|
||||
local rsp = {}
|
||||
|
||||
for redis_key, _ in pairs(available_keys) do
|
||||
local host_info_json = ntop.getHashCache(redis_hash, redis_key)
|
||||
local network_name = ""
|
||||
|
||||
if not isEmptyString(host_info_json) then
|
||||
local host_info = json.decode(host_info_json)
|
||||
|
||||
if not(network_list[host_info.network]) then
|
||||
network_list[host_info.network] = 1
|
||||
else
|
||||
network_list[host_info.network] = network_list[host_info.network] + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for network, count in pairsByKeys(network_list) do
|
||||
local network_name
|
||||
for n, ns in pairs(networks_stats) do
|
||||
if ns.network_id == tonumber(network) then
|
||||
network_name = getFullLocalNetworkName(ns.network_key)
|
||||
end
|
||||
end
|
||||
|
||||
rsp[#rsp + 1] = {
|
||||
count = count,
|
||||
key = "network",
|
||||
value = network,
|
||||
label = tostring(network_name or network)
|
||||
}
|
||||
end
|
||||
table.insert(rsp, 1, {
|
||||
key = "network",
|
||||
value = "",
|
||||
label = i18n('flows_page.all_networks')
|
||||
})
|
||||
|
||||
return rsp
|
||||
end
|
||||
|
||||
-- ##########################################
|
||||
|
||||
return inactive_hosts_utils
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue