Implements auto assignment of user script alert and status ids

This commit is contained in:
Simone Mainardi 2020-01-15 13:08:58 +01:00
parent d7528e1628
commit 48910b9f87
58 changed files with 55 additions and 68 deletions

View file

@ -9,10 +9,13 @@ local dirs = ntop.getDirs()
local AVAILABLE_CONSTS = {
flow = {
min_id = 0, max_id = 63, reuse_ids = true,
min_id = 1, max_id = 63, reuse_ids = true,
reserved_ids = {
status_normal = 0,
},
},
alert = {
min_id = 0, max_id = 255, reuse_ids = false
min_id = 0, max_id = 255, reuse_ids = false,
}
}
@ -129,7 +132,9 @@ function plugins_consts_utils.assign_requested_ids(const_type)
end
for _, req in ipairs(id_requests[const_type]) do
if cur_key_to_id[req] then
if AVAILABLE_CONSTS[const_type]["reserved_ids"] and AVAILABLE_CONSTS[const_type]["reserved_ids"][req] then
-- Id among those reserved, so id is already assigned and there is nothing to do
elseif cur_key_to_id[req] then
-- Id found: already assigned, nothing to do
found_ids[#found_ids + 1] = cur_key_to_id[req]
elseif #available_ids > 0 then
@ -187,6 +192,10 @@ function plugins_consts_utils.get_assigned_id(const_type, const_key)
return
end
if AVAILABLE_CONSTS[const_type]["reserved_ids"] and AVAILABLE_CONSTS[const_type]["reserved_ids"][const_key] then
return AVAILABLE_CONSTS[const_type]["reserved_ids"][const_key]
end
-- Avoid reading the whole hash, just read the single key to re-use also ntopng internal caching mechanism
local kname = assigned_id_key(const_type, const_key)
local assigned_id = tonumber(ntop.getPref(kname))