ntopng/scripts/lua/find_host.lua
emanuele-f 4bc96c935a Host pools improvements
- Traffic Policy: get first available pool, not the "Not Assigned"
- Allow to change MAC address host pool from the MAC page
- When changing an IP address pool from the host page, change MAC address instead, if available
- Show the MAC manufacturer in the host pool memebers page and allow to set a filter with it
2017-05-22 12:47:10 +02:00

54 lines
1.1 KiB
Lua

--
-- (C) 2013-17 - ntop.org
--
dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
sendHTTPHeader('application/json')
max_num_to_find = 5
print [[
{
"interface" : "]] print(ifname) print [[",
"results": [
]]
query = _GET["query"]
if(query == nil) then query = "" end
num = 0
interface.select(ifname)
res = interface.findHost(query)
-- Also look at the custom names
local ip_to_name = ntop.getHashAllCache(getHostAltNamesKey()) or {}
for ip,name in pairs(ip_to_name) do
if string.contains(string.lower(name), string.lower(query)) then
res[ip] = hostVisualization(ip, name)
end
end
if(res ~= nil) then
for k, v in pairs(res) do
if isIPv6(k) and (not string.contains(v, "%[IPv6%]")) then
v = v.." [IPv6]"
end
if(v ~= "") then
if(num > 0) then print(",\n") end
print('\t{"name": "'..v..'", "ip": "'..k..'"}')
num = num + 1
end -- if
end -- for
end -- if
print [[
]
}
]]