mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 23:49:33 +00:00
Only returns available categories for a user script subdir
This commit is contained in:
parent
0d70d7c8b9
commit
95061f331a
3 changed files with 44 additions and 10 deletions
|
|
@ -101,6 +101,13 @@ user_scripts.script_categories = {
|
|||
}
|
||||
}
|
||||
|
||||
-- Auto-assign an id to the categories
|
||||
local cat_id = 1
|
||||
for cat_k, cat_v in pairs(user_scripts.script_categories) do
|
||||
cat_v["id"] = cat_id
|
||||
cat_id = cat_id + 1
|
||||
end
|
||||
|
||||
-- Hook points for flow/periodic modules
|
||||
-- NOTE: keep in sync with the Documentation
|
||||
user_scripts.script_types = {
|
||||
|
|
@ -133,6 +140,24 @@ user_scripts.script_types = {
|
|||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Given a category found in a user script, this method checks whether the category is valid
|
||||
-- and, if not valid, it assigns to the plugin a default category
|
||||
local function checkCategory(category)
|
||||
if not category or not category["id"] then
|
||||
return user_scripts.script_categories.other
|
||||
end
|
||||
|
||||
for cat_k, cat_v in pairs(user_scripts.script_categories) do
|
||||
if category["id"] == cat_v["id"] then
|
||||
return cat_v
|
||||
end
|
||||
end
|
||||
|
||||
return user_scripts.script_categories.other
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Given a subdir, returns the corresponding script type
|
||||
function user_scripts.getScriptType(search_subdir)
|
||||
for _, script_type in pairs(user_scripts.script_types) do
|
||||
|
|
@ -498,13 +523,7 @@ function user_scripts.load(ifid, script_type, subdir, options)
|
|||
goto next_module
|
||||
end
|
||||
|
||||
if not user_script["category"] then
|
||||
-- Assign the default category other
|
||||
user_script.category = user_scripts.script_categories.other
|
||||
elseif not user_script["category"]["icon"] or not user_script["category"]["i18n_title"] then
|
||||
-- Category is found but not among the available categories. Let's reset it to other and print an error
|
||||
user_script.category = user_scripts.script_categories.other
|
||||
end
|
||||
user_script["category"] = checkCategory(user_script["category"])
|
||||
|
||||
if(rv.modules[mod_fname]) then
|
||||
traceError(TRACE_ERROR, TRACE_CONSOLE, string.format("Skipping duplicate module '%s'", mod_fname))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue