mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-06 03:34:49 +00:00
parent
4779f80fa8
commit
aca088ea13
14 changed files with 194 additions and 87 deletions
|
|
@ -621,7 +621,13 @@ local function formatRawFlow(record, flow_json, skip_add_links)
|
|||
time_bounds = {getAlertTimeBounds(record)}
|
||||
end
|
||||
|
||||
local decoded = json.decode(flow_json) or {}
|
||||
local decoded
|
||||
|
||||
if(type(flow_json) == "table") then
|
||||
decoded = flow_json
|
||||
else
|
||||
decoded = json.decode(flow_json) or {}
|
||||
end
|
||||
|
||||
if((type(decoded["status_info"]) == "string") and
|
||||
(string.sub(decoded["status_info"], 1, 1) == "{")) then
|
||||
|
|
@ -2132,17 +2138,19 @@ end
|
|||
|
||||
function formatAlertMessage(ifid, alert)
|
||||
local msg
|
||||
local alert_json = alert["alert_json"]
|
||||
local configsets = user_scripts.getConfigsets()
|
||||
|
||||
if isEmptyString(alert_json) then
|
||||
alert_json = {}
|
||||
elseif(string.sub(alert_json, 1, 1) == "{") then
|
||||
alert_json = json.decode(alert_json)
|
||||
end
|
||||
|
||||
if(alert.alert_entity == alert_consts.alertEntity("flow") or (alert.alert_entity == nil)) then
|
||||
msg = formatRawFlow(alert, alert["alert_json"])
|
||||
msg = formatRawFlow(alert, alert_json)
|
||||
else
|
||||
msg = alert["alert_json"]
|
||||
if isEmptyString(msg) then
|
||||
msg = {}
|
||||
elseif(string.sub(msg, 1, 1) == "{") then
|
||||
msg = json.decode(msg)
|
||||
end
|
||||
|
||||
msg = alert_json
|
||||
local description = alertTypeDescription(alert.alert_type)
|
||||
|
||||
if(type(description) == "string") then
|
||||
|
|
@ -2157,6 +2165,17 @@ function formatAlertMessage(ifid, alert)
|
|||
return("")
|
||||
end
|
||||
|
||||
local info = alert_json.alert_generation or (alert_json.status_info and alert_json.status_info.alert_generation)
|
||||
|
||||
if(info and msg and isAdministrator()) then
|
||||
-- Ensure that the configset still exists
|
||||
if configsets[info.confset_id] then
|
||||
msg = msg .. ' <a href="'.. ntop.getHttpPrefix() ..'/lua/admin/edit_configset.lua?confset_id='..
|
||||
info.confset_id ..'&subdir='.. info.subdir ..'&user_script='.. info.script_key ..'#all">'..
|
||||
'<i class="fas fa-cog" title="'.. i18n("edit_configuration") ..'"></i></a>'
|
||||
end
|
||||
end
|
||||
|
||||
return(msg)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ local str_2_periodicity = {
|
|||
}
|
||||
|
||||
local known_alerts = {}
|
||||
local current_script = nil
|
||||
local current_configset_id = nil
|
||||
|
||||
-- ##############################################
|
||||
|
||||
|
|
@ -94,6 +96,27 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
function alerts_api.addAlertGenerationInfo(alert_json, current_script, current_configset_id)
|
||||
if alert_json and current_script and current_configset_id then
|
||||
-- Add information about the script who generated this alert
|
||||
alert_json.alert_generation = {
|
||||
script_key = current_script.key,
|
||||
subdir = current_script.subdir,
|
||||
confset_id = current_configset_id,
|
||||
}
|
||||
else
|
||||
-- NOTE: there are currently some internally generated alerts which
|
||||
-- do not use the user_scripts api (e.g. the ntopng startup)
|
||||
--tprint(debug.traceback())
|
||||
end
|
||||
end
|
||||
|
||||
local function addAlertGenerationInfo(alert_json)
|
||||
alerts_api.addAlertGenerationInfo(alert_json, current_script, current_configset_id)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
--! @brief Stores a single alert (or event) into the alerts database
|
||||
--! @param entity_info data returned by one of the entity_info building functions
|
||||
--! @param type_info data returned by one of the type_info building functions
|
||||
|
|
@ -104,6 +127,10 @@ function alerts_api.store(entity_info, type_info, when)
|
|||
local ifid = interface.getId()
|
||||
local granularity_sec = type_info.alert_granularity and type_info.alert_granularity.granularity_seconds or 0
|
||||
local granularity_id = type_info.alert_granularity and type_info.alert_granularity.granularity_id or -1
|
||||
|
||||
type_info.alert_type_params = type_info.alert_type_params or {}
|
||||
addAlertGenerationInfo(type_info.alert_type_params)
|
||||
|
||||
local alert_json = json.encode(type_info.alert_type_params)
|
||||
local subtype = type_info.alert_subtype or ""
|
||||
when = when or os.time()
|
||||
|
|
@ -231,6 +258,9 @@ function alerts_api.trigger(entity_info, type_info, when, cur_alerts)
|
|||
|
||||
when = when or os.time()
|
||||
|
||||
type_info.alert_type_params = type_info.alert_type_params or {}
|
||||
addAlertGenerationInfo(type_info.alert_type_params)
|
||||
|
||||
local alert_json = json.encode(type_info.alert_type_params)
|
||||
local triggered
|
||||
local alert_key_name = get_alert_triggered_key(type_info)
|
||||
|
|
@ -1206,4 +1236,13 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
function alerts_api.invokeScriptHook(user_script, configset_id, hook_fn, p1, p2, p3)
|
||||
current_script = user_script
|
||||
current_configset_id = configset_id
|
||||
|
||||
return(hook_fn(p1, p2, p3))
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
return(alerts_api)
|
||||
|
|
|
|||
|
|
@ -1078,7 +1078,7 @@ function user_scripts.getTargetConfig(configsets, subdir, target)
|
|||
return({})
|
||||
end
|
||||
|
||||
return(conf.config[subdir] or {})
|
||||
return conf.config[subdir] or {}, conf.id
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -1090,7 +1090,7 @@ function user_scripts.getDefaultConfig(configsets, subdir)
|
|||
return({})
|
||||
end
|
||||
|
||||
return(conf.config[subdir] or {})
|
||||
return conf.config[subdir] or {}, conf.id
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -1119,7 +1119,7 @@ function user_scripts.getHostTargetConfigset(configsets, subdir, ip_target)
|
|||
return({})
|
||||
end
|
||||
|
||||
return(conf.config[subdir] or {})
|
||||
return conf.config[subdir] or {}, conf.id
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue