mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-01 00:19:33 +00:00
Rework flow scripts into user scripts
This commit is contained in:
parent
8ceacb37f6
commit
52d2051d4c
9 changed files with 187 additions and 109 deletions
45
scripts/callbacks/user_scripts/loader.lua
Normal file
45
scripts/callbacks/user_scripts/loader.lua
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
--
|
||||
-- (C) 2016-17 - ntop.org
|
||||
--
|
||||
|
||||
--
|
||||
-- This is the user scripts loader. It exposes to the C side the callbacks from
|
||||
-- the user scripts.
|
||||
--
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
local scripts_dir = dirs.installdir .. "/scripts/callbacks/user_scripts/"..script_context
|
||||
|
||||
local scripts_callbacks = {}
|
||||
|
||||
if ntop.isdir(scripts_dir) then
|
||||
package.path = scripts_dir.."/?.lua;" .. package.path
|
||||
|
||||
for _,script in pairs(ntop.readdir(scripts_dir)) do
|
||||
if (script ~= nil) then
|
||||
local module_name = script:match("([^.]+).lua")
|
||||
if module_name ~= nil then
|
||||
local module_callbacks = require(module_name)
|
||||
|
||||
for callback_name, callback in pairs(module_callbacks) do
|
||||
if _G[callback_name] == nil then
|
||||
|
||||
-- Define the global hook called by the C side
|
||||
_G[callback_name] = function (...)
|
||||
-- Note: order is not currently preserved
|
||||
for _, callback in pairs(scripts_callbacks[callback_name]) do
|
||||
callback(unpack(arg or {}))
|
||||
end
|
||||
end
|
||||
|
||||
scripts_callbacks[callback_name] = {}
|
||||
end
|
||||
|
||||
-- Add the callback to be called
|
||||
scripts_callbacks[callback_name][#scripts_callbacks[callback_name] + 1] = callback
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue