Integrate configsets with user scripts configurations

This commit is contained in:
emanuele-f 2019-12-16 17:35:17 +01:00
parent 30beb6d972
commit b5197ba452
6 changed files with 137 additions and 36 deletions

View file

@ -14,8 +14,8 @@ sendHTTPContentTypeHeader('application/json')
local stype = _GET["script_type"] or "traffic_element"
local subdir = _GET["script_subdir"] or "host"
local confset_id = tonumber(_GET["confset_id"] or user_scripts.DEFAULT_CONFIGSET_ID)
local script_key = _GET["script_key"]
local entity_value = _GET["entity_val"]
local script_type = user_scripts.script_types[stype]
@ -29,6 +29,13 @@ if(script_key == nil) then
return
end
local config_set = user_scripts.getConfigsets()[confset_id]
if(config_set == nil) then
traceError(TRACE_ERROR, TRACE_CONSOLE, "Unknown configset ID: " .. confset_id)
return
end
-- ################################################
@ -64,21 +71,19 @@ if(script.gui) then
end
end
for _, hook in pairs(script_type.hooks) do
local conf = user_scripts.getConfiguration(script, hook, entity_value)
local hooks_config = user_scripts.getConfigsetHooksConf(config_set, script, subdir)
if(conf ~= nil) then
local granularity_info = alert_consts.alerts_granularities[hook]
local label = nil
for hook, config in pairs(hooks_config) do
local granularity_info = alert_consts.alerts_granularities[hook]
local label = nil
if(granularity_info) then
label = i18n(granularity_info.i18n_title)
end
result.hooks[hook] = table.merge(conf, {
label = label,
})
if(granularity_info) then
label = i18n(granularity_info.i18n_title)
end
result.hooks[hook] = table.merge(config, {
label = label,
})
end
-- ################################################