mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Move unassigned devices to the host pools page and allow to filter active/inactive devices
This commit is contained in:
parent
c47b4f2bcd
commit
b2e09822ad
7 changed files with 111 additions and 64 deletions
|
|
@ -20,7 +20,7 @@ local sortColumn = _GET["sortColumn"]
|
|||
local sortOrder = _GET["sortOrder"]
|
||||
|
||||
local vlan = _GET["vlan"]
|
||||
local manufacturer = _GET["manufacturer"]
|
||||
local devices_mode = _GET["unassigned_devices"]
|
||||
|
||||
local sortPrefs = "unknown_devices"
|
||||
|
||||
|
|
@ -75,11 +75,16 @@ elseif sortColumn == "column_last_seen" then
|
|||
sortField = "seen.last"
|
||||
elseif sortColumn == "column_name" then
|
||||
sortField = "name"
|
||||
else
|
||||
elseif sortColumn == "column_mac" then
|
||||
sortField = "mac"
|
||||
else
|
||||
-- sort in memory MACs first, off memory after
|
||||
sortField = "in_memory_mac"
|
||||
sortOrder = "desc"
|
||||
end
|
||||
|
||||
-- First data source: memory
|
||||
-- NB: we must fetch this data even if mode is "inactive_only", to properly filter redis data
|
||||
local macs_stats = interface.getMacsInfo(nil, nil, nil, nil,
|
||||
tonumber(vlan),
|
||||
true --[[ sourceMacsOnly ]],
|
||||
|
|
@ -89,6 +94,7 @@ if (macs_stats ~= nil) then
|
|||
macs_stats = macs_stats.macs
|
||||
|
||||
for key, device in pairs(macs_stats) do
|
||||
device.in_memory_mac = "1" .. device["mac"]
|
||||
mac_to_device[device["mac"]] = device
|
||||
|
||||
if sortField == "name" then
|
||||
|
|
@ -96,7 +102,9 @@ if (macs_stats ~= nil) then
|
|||
end
|
||||
|
||||
mac_to_sort[device["mac"]] = device[sortField]
|
||||
total_rows = total_rows + 1
|
||||
if devices_mode ~= "inactive_only" then
|
||||
total_rows = total_rows + 1
|
||||
end
|
||||
end
|
||||
else
|
||||
macs_stats = {}
|
||||
|
|
@ -105,18 +113,22 @@ end
|
|||
macs_stats = nil
|
||||
|
||||
-- Second data source: redis
|
||||
local keys = ntop.getKeysCache("ntopng.serialized_macs.ifid_"..(ifstats.id).."__*@"..vlan)
|
||||
for key in pairs(keys or {}) do
|
||||
local device = json.decode(ntop.getCache(key))
|
||||
if (device ~= nil) and (not mac_to_device[device["mac"]]) and (tostring(interface.findMacPool(device["mac"], vlan) or 0) == host_pools_utils.DEFAULT_POOL_ID) then
|
||||
mac_to_device[device["mac"]] = device
|
||||
if devices_mode ~= "active_only" then
|
||||
local keys = ntop.getKeysCache("ntopng.serialized_macs.ifid_"..(ifstats.id).."__*@"..vlan)
|
||||
for key in pairs(keys or {}) do
|
||||
local device = json.decode(ntop.getCache(key))
|
||||
|
||||
if sortField == "name" then
|
||||
mac_to_device[device["mac"]]["name"] = getDeviceName(device["mac"])
|
||||
if (device ~= nil) and (not mac_to_device[device["mac"]]) and (tostring(interface.findMacPool(device["mac"], vlan) or 0) == host_pools_utils.DEFAULT_POOL_ID) then
|
||||
device.in_memory_mac = "0" .. device["mac"]
|
||||
mac_to_device[device["mac"]] = device
|
||||
|
||||
if sortField == "name" then
|
||||
mac_to_device[device["mac"]]["name"] = getDeviceName(device["mac"])
|
||||
end
|
||||
|
||||
mac_to_sort[device["mac"]] = device[sortField]
|
||||
total_rows = total_rows + 1
|
||||
end
|
||||
|
||||
mac_to_sort[device["mac"]] = device[sortField]
|
||||
total_rows = total_rows + 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -134,11 +146,13 @@ end
|
|||
for mac, _ in pairsByValues(mac_to_sort, sort_function) do
|
||||
i = i + 1
|
||||
|
||||
if i > to_skip then
|
||||
local device = mac_to_device[mac]
|
||||
local device = mac_to_device[mac]
|
||||
local in_memory = (device["manufacturer"] ~= nil)
|
||||
local filter_out = ((not in_memory) and devices_mode == "active_only") or (in_memory and devices_mode == "inactive_only")
|
||||
|
||||
if (i > to_skip) and (not filter_out) then
|
||||
local record = {}
|
||||
local in_memory = (device["manufacturer"] ~= nil)
|
||||
|
||||
|
||||
if in_memory then
|
||||
record["column_mac"] = mac2link(device["mac"])
|
||||
else
|
||||
|
|
@ -150,6 +164,7 @@ for mac, _ in pairsByValues(mac_to_sort, sort_function) do
|
|||
record["column_first_seen"] = formatEpoch(device["seen.first"]) .. " [" .. secondsToTime(now - device["seen.first"]) .. " " .. i18n("details.ago").."]"
|
||||
record["column_last_seen"] = formatEpoch(device["seen.last"]) .. " [" .. secondsToTime(now - device["seen.last"]) .. " " .. i18n("details.ago").."]"
|
||||
-- record["manufacturer"] = device["manufacturer"] or ntop.getMacManufacturer(device["mac"])
|
||||
|
||||
res[#res + 1] = record
|
||||
|
||||
num = num + 1
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue