ntopng/scripts/callbacks/system/syslog.lua
emanuele-f d037f9a9a4 Use new user scripts config and gui
The user scripts configuration can now be configured from the "User Scripts" entry under the cog
icon. It allows the creation of multiple configuration presets to be applied to hosts, networks and
interfaces.
2020-01-03 13:03:34 +01:00

56 lines
1.6 KiB
Lua

--
-- (C) 2019 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
require "lua_utils"
local user_scripts = require("user_scripts")
local syslog_modules = nil
local syslog_conf = nil
-- #################################################################
-- The function below ia called once (#pragma once)
function setup()
local ifid = interface.getId()
syslog_modules = user_scripts.load(ifid, user_scripts.script_types.syslog, "syslog")
local configsets = user_scripts.getConfigsets()
syslog_conf = user_scripts.getTargetConfig(configsets, "syslog", getInterfaceName(ifid))
end
-- #################################################################
-- The function below is called for each received alert
function handleEvent(name, message)
local event_handler = syslog_modules.hooks["handleEvent"][name]
-- TODO use syslog_conf
if(event_handler ~= nil) then
event_handler(message)
end
end
-- #################################################################
-- The function below ia called once (#pragma once)
function teardown()
local all_modules = syslog_modules.modules
for mod_name, syslog_module in pairs(syslog_modules) do
local script = all_modules[mod_name]
if syslog_module.teardown ~= nil then
local conf = user_scripts.getTargetHookConfig(syslog_conf, script)
if conf.enabled then
syslog_module.teardown(conf.script_conf)
end
end
end
end
-- #################################################################