Add example plugin with documentation

This commit is contained in:
emanuele-f 2019-12-17 16:23:15 +01:00
parent ebd1d7ba35
commit 26c80529aa
18 changed files with 1058 additions and 9 deletions

View file

@ -54,12 +54,20 @@ function plugins_utils.listPlugins()
if ntop.exists(plugin_info) then
local metadata = dofile(plugin_info)
local mandatory_fields = {"title", "description", "author", "version"}
if(metadata == nil) then
traceError(TRACE_ERROR, TRACE_CONSOLE, string.format("Could not load plugin.lua in '%s'", plugin_name))
goto continue
end
for _, field in pairs(mandatory_fields) do
if(metadata[field] == nil) then
traceError(TRACE_ERROR, TRACE_CONSOLE, string.format("Missing mandatory field '%s' in plugin.lua of '%s'", field, plugin_name))
goto continue
end
end
if(metadata.disabled) then
-- The plugin is disabled, skip it
goto continue
@ -442,7 +450,7 @@ function plugins_utils.loadPlugins()
load_plugin_user_scripts(path_map, plugin) then
loaded_plugins[plugin.key] = plugin
else
traceError(TRACE_ERROR, TRACE_CONSOLE, string.format("Errors occurred while processing plugin %s", plugin.key))
traceError(TRACE_ERROR, TRACE_CONSOLE, string.format("Errors occurred while processing plugin '%s'", plugin.key))
end
::continue::
@ -610,4 +618,14 @@ end
-- ##############################################
-- @brief Retrieve metadata of the loaded plugins
-- @return the loaded plugins metadata
function plugins_utils.getLoadedPlugins()
load_metadata()
return(METADATA.plugins)
end
-- ##############################################
return(plugins_utils)