Removed recipient selection from pools. Only severity and category are used as filters now. New filtering based on pool to be done.

This commit is contained in:
Alfredo Cardigliano 2022-02-18 11:45:16 +01:00
parent f5178d4329
commit 29c0ba4594
28 changed files with 110 additions and 707 deletions

View file

@ -68,76 +68,4 @@ end
-- ################################################################################
-- @brief Returns an array of recipient ids responsible for a given an `entity_id` and a `pool_id`
-- @param entity_id One of alert_consts.alert_entities
-- @param pool_id The pool id of an existing entity pool
-- @param alert_severity An integer alert severity id as found in `alert_severities`
-- @param category_id The category for which we want the recipients (one id of checks.check_categories)
-- @return An array of recipient ids
function pools_alert_utils.get_entity_recipients_by_pool_id(entity_id, pool_id, alert_severity, category_id)
local res = {}
local entity = alert_consts.alertEntityById(entity_id)
-- Obtain the pools instance for the given entity
local pools_instance = pools_alert_utils.get_entity_pools_by_id(entity_id)
if not pool_id then
pool_id = pools.DEFAULT_POOL_ID
end
if pools_instance then
-- tprint("found pool instance for "..entity.label)
-- See if the pools for the current instance are in cache
if not alert_entity_all_pools[entity_id] then
-- List of pools not yet cached, let's create it
alert_entity_all_pools[entity_id] = {}
local all_pools = pools_instance:get_all_pools()
-- It's handy to have the cache as a lua table with pool ids as keys and pool details as values
for _, pool in pairs(all_pools) do
alert_entity_all_pools[entity_id][pool.pool_id] = pool
end
end
-- Access the cache
local entity_pool = alert_entity_all_pools[entity_id][pool_id]
if entity_pool and entity_pool["recipients"] then
for _, recipient in pairs(entity_pool["recipients"]) do
local recipient_ok = false
if category_id and recipient["recipient_check_categories"] ~= nil then
-- Make sure the user script category belongs to the recipient user script categories
for _, check_category in pairs(recipient["recipient_check_categories"]) do
if check_category == category_id then
recipient_ok = true
end
end
else
-- if there's no user script, check on the category id is not enforced
recipient_ok = true
end
if recipient_ok then
if alert_severity and recipient["recipient_minimum_severity"] ~= nil and
alert_severity < recipient["recipient_minimum_severity"] then
-- If the current alert severity is less than the minimum requested severity
-- exclude the recipient
recipient_ok = false
end
end
if recipient_ok then
-- Prepare the result with all the recipients
res[#res + 1] = recipient.recipient_id
-- tprint(string.format("Adding recipient [%s][%s][%i]", recipient.recipient_name, entity.label, pool_id))
end
end
end
end
return res
end
-- ################################################################################
return pools_alert_utils