Fixes circular dependency when filtering

This commit is contained in:
Matteo Biscosi 2024-02-20 09:34:21 +00:00
parent 83634d06e1
commit 29a28ea203
5 changed files with 55 additions and 59 deletions

View file

@ -0,0 +1,44 @@
--
-- (C) 2019-24 - ntop.org
--
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
-- This is just a struct, try to keep this file without requires except for structs
local alert_categories = require "alert_categories"
local alert_category_utils = {}
-- ##############################################
-- @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 script a default category
function alert_category_utils.checkCategory(category)
if not category or not category["id"] then
return alert_categories.other
end
for cat_k, cat_v in pairs(alert_categories) do
if category["id"] == cat_v["id"] then
return cat_v
end
end
return alert_categories.other
end
-- ##############################################
function alert_category_utils.getCategoryById(id)
for cat_k, cat_v in pairs(alert_categories) do
if cat_v["id"] == id then
return cat_v
end
end
return alert_categories.other
end
-- ##############################################
return alert_category_utils