mirror of
https://github.com/ntop/ntopng.git
synced 2026-10-24 07:20:20 +00:00
52 lines
No EOL
1.4 KiB
Lua
52 lines
No EOL
1.4 KiB
Lua
--
|
|
-- (C) 2019-26 - 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
|
|
|
|
-- ##############################################
|
|
|
|
-- id -> category index, built on first use
|
|
local categories_by_id = nil
|
|
|
|
function alert_category_utils.getCategoryById(id)
|
|
if not categories_by_id then
|
|
categories_by_id = {}
|
|
|
|
for cat_k, cat_v in pairs(alert_categories) do
|
|
-- Keep the first match as the original linear scan did
|
|
if categories_by_id[cat_v["id"]] == nil then
|
|
categories_by_id[cat_v["id"]] = cat_v
|
|
end
|
|
end
|
|
end
|
|
|
|
return categories_by_id[id] or alert_categories.other
|
|
end
|
|
|
|
-- ##############################################
|
|
|
|
return alert_category_utils |