mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
refactor for endpoints and recipients (#4707)
This commit is contained in:
parent
06161556ac
commit
15772bd0fe
24 changed files with 129 additions and 117 deletions
60
scripts/lua/modules/notifications/recipients_rest_utils.lua
Normal file
60
scripts/lua/modules/notifications/recipients_rest_utils.lua
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
--
|
||||
-- (C) 2017-20 - ntop.org
|
||||
--
|
||||
local dirs = ntop.getDirs()
|
||||
|
||||
require "lua_utils"
|
||||
local alert_consts = require "alert_consts"
|
||||
local user_scripts = require "user_scripts"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local recipients_rest_utils = {}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Parses and validates a comma-separated list of user script category ids into a lua array
|
||||
-- @return A lua array of valid user script category ids
|
||||
function recipients_rest_utils.parse_user_script_categories(categories_string)
|
||||
local categories = {}
|
||||
|
||||
if isEmptyString(categories_string) then return categories end
|
||||
|
||||
-- Unfold the categories csv
|
||||
categories = categories_string:split(",") or {categories_string}
|
||||
|
||||
local res = {}
|
||||
for _, category_id in pairs(categories) do
|
||||
local category_id = tonumber(category_id)
|
||||
|
||||
for _, category in pairs(user_scripts.script_categories) do
|
||||
if category_id == category.id then
|
||||
res[#res + 1] = category_id
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return res
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Parses and validates a severity id string and returns it as a number
|
||||
-- @param minimum_severity_id_string An string with an integer severity id as found in `alert_consts.alert_severities`
|
||||
-- @return A valid integer severity id or nil when validation fails
|
||||
function recipients_rest_utils.parse_minimum_severity(minimum_severity_id_string)
|
||||
local minimum_severity_id = tonumber(minimum_severity_id_string)
|
||||
|
||||
for _, alert_severity in pairs(alert_consts.alert_severities) do
|
||||
if minimum_severity_id == alert_severity.severity_id then
|
||||
return minimum_severity_id
|
||||
end
|
||||
end
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
return recipients_rest_utils
|
||||
Loading…
Add table
Add a link
Reference in a new issue