ntopng/scripts/lua/get_pool_data.lua
2026-09-11 11:04:35 +02:00

36 lines
877 B
Lua

--
-- (C) 2013-26 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
package.path = dirs.installdir .. "/scripts/lua/modules/pools/?.lua;" .. package.path
require "lua_utils"
local host_pools = require "host_pools"
local json = require("dkjson")
local auth = require "auth"
sendHTTPContentTypeHeader('text/html')
-- sendHTTPHeader('application/json')
local pool = tonumber(_GET["pool"])
-- Make sure the user is allowed to access this pool
if not auth.is_allowed_host_pool(pool) then
print(json.encode({}, nil))
return
end
-- Instantiate host pools
local host_pools_instance = host_pools:create()
local n = interface.getHostPoolStats(pool)
local res = {}
for k, v in pairs(n) do
res = host_pools_instance:hostpool2record(interface.getId(), k, v)
break
end
print(json.encode(res, nil))