mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-03 01:10:10 +00:00
Implement ntopng plugins
Plugins are a convenient way to group together related lua scripts. Their primary use case is to group user scripts and their alert/status definition. The builtin ntopng user scripts and definitions are now packed into plugins directories. In future, we will support loading of user created plugins. Plugins are loaded at startup into some runtime directories and then used. Other changes provided by this commit include: - Add sample flow logger plugin - Initial support for system user scripts - Rename edge to threshold - Migrate system probes to user scripts/plugins - Migrate scripts to more explicit alerts_api.checkThresholdAlert api
This commit is contained in:
parent
df245fad3a
commit
a3432e00e8
218 changed files with 2070 additions and 2097 deletions
|
|
@ -0,0 +1,70 @@
|
|||
--
|
||||
-- (C) 2019 - ntop.org
|
||||
--
|
||||
|
||||
local user_scripts = require("user_scripts")
|
||||
|
||||
-- Script state
|
||||
local f = nil
|
||||
|
||||
local script = {
|
||||
-- This module is disabled by default
|
||||
default_enabled = false,
|
||||
|
||||
-- The default configuration of this script
|
||||
default_value = {
|
||||
log_mode = "console", -- console | file
|
||||
log_file = "/tmp/flows_log",
|
||||
},
|
||||
|
||||
-- See below
|
||||
hooks = {},
|
||||
|
||||
-- Allow user script configuration from the GUI
|
||||
gui = {
|
||||
-- Localization strings, from the "locales" directory of the plugin
|
||||
i18n_title = "flow_logger.title",
|
||||
i18n_description = "flow_logger.description",
|
||||
|
||||
-- TODO: draw config gui
|
||||
}
|
||||
}
|
||||
|
||||
-- #################################################################
|
||||
|
||||
function script.teardown()
|
||||
if(f ~= nil) then
|
||||
-- Close the log file
|
||||
f:close()
|
||||
f = nil
|
||||
end
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
-- Defines an hook which is executed every time a procotol of a flow is detected
|
||||
function script.hooks.protocolDetected(now, conf)
|
||||
local line = string.format("%s %s\n", os.date("%d/%b/%Y %X"), shortFlowLabel(flow.getInfo()))
|
||||
|
||||
if(conf.log_mode == "file") then
|
||||
if(f == nil) then
|
||||
local err
|
||||
|
||||
f, err = io.open(conf.log_file, "a")
|
||||
|
||||
if(f == nil) then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, err)
|
||||
end
|
||||
end
|
||||
|
||||
if(f ~= nil) then
|
||||
f:write(line)
|
||||
end
|
||||
else
|
||||
print(line)
|
||||
end
|
||||
end
|
||||
|
||||
-- #################################################################
|
||||
|
||||
return script
|
||||
Loading…
Add table
Add a link
Reference in a new issue