Fixes elephant and long-lived flow alerts visualization

Fixes #5646
This commit is contained in:
Simone Mainardi 2021-07-09 12:12:17 +02:00
parent 69f82c7f76
commit eb41fd4c8f
4 changed files with 41 additions and 40 deletions

View file

@ -12,6 +12,7 @@ local flow_alert_keys = require "flow_alert_keys"
local classes = require "classes"
-- Make sure to import the Superclass!
local alert = require "alert"
local json = require "dkjson"
-- ##############################################
@ -44,7 +45,31 @@ end
-- @param alert_type_params Table `alert_type_params` as built in the `:init` method
-- @return A human-readable string
function alert_elephant_flow.format(ifid, alert, alert_type_params)
return formatElephantAlertType(alert_type_params)
local threshold = ""
local res = i18n("flow_details.elephant_flow")
if alert_type_params then
local l2r_bytes = bytesToSize(alert_type_params["l2r_bytes"])
if alert_type_params["l2r_bytes"] > alert_type_params["l2r_threshold"] and alert_type_params["l2r_threshold"] > 0 then
l2r_bytes = l2r_bytes .." > "..bytesToSize(alert_type_params["l2r_threshold"])
end
local r2l_bytes = bytesToSize(alert_type_params["r2l_bytes"])
if alert_type_params["r2l_bytes"] > alert_type_params["r2l_threshold"] and alert_type_params["l2r_threshold"] > 0 then
r2l_bytes = r2l_bytes .. " > "..bytesToSize(alert_type_params["r2l_threshold"])
end
res = string.format("%s<sup><i class='fas fa-info-circle' aria-hidden='true' title='"..i18n("flow_details.elephant_flow_descr").."'></i></sup>", res)
res = string.format("%s %s", res, i18n("flow_details.elephant_exceeded", {l2r = l2r_bytes, r2l = r2l_bytes}))
end
local alert_json = json.decode(alert["json"])
if alert_json and not isEmptyString(alert_json["info"]) then
res = string.format("%s [%s]", res, alert_json["info"])
end
return res
end
-- #######################################################

View file

@ -19,7 +19,7 @@ local alert_internals = classes.class(alert)
alert_internals.meta = {
alert_key = flow_alert_keys.flow_alert_internals,
i18n_title = "flow_details.not_purged",
i18n_title = "flow_checks_config.not_purged",
icon = "fas fa-fw fa-exclamation",
}

View file

@ -9,6 +9,7 @@ local flow_alert_keys = require "flow_alert_keys"
local classes = require "classes"
-- Make sure to import the Superclass!
local alert = require "alert"
local json = require "dkjson"
-- ##############################################
@ -43,18 +44,21 @@ function alert_longlived.format(ifid, alert, alert_type_params)
local threshold = ""
local res = i18n("flow_details.longlived_flow")
if not alert_type_params then
return res
if alert_type_params then
if alert_type_params["longlived.threshold"] then
threshold = alert_type_params["longlived.threshold"]
end
res = string.format("%s<sup><i class='fas fa-fw fa-info-circle' aria-hidden='true' title='"..i18n("flow_details.longlived_flow_descr").."'></i></sup>", res)
if threshold ~= "" then
res = string.format("%s [%s]", res, i18n("flow_details.longlived_exceeded", {amount = secondsToTime(threshold)}))
end
end
if alert_type_params["longlived.threshold"] then
threshold = alert_type_params["longlived.threshold"]
end
res = string.format("%s<sup><i class='fas fa-fw fa-info-circle' aria-hidden='true' title='"..i18n("flow_details.longlived_flow_descr").."'></i></sup>", res)
if threshold ~= "" then
res = string.format("%s [%s]", res, i18n("flow_details.longlived_exceeded", {amount = secondsToTime(threshold)}))
local alert_json = json.decode(alert["json"])
if alert_json and not isEmptyString(alert_json["info"]) then
res = string.format("%s [%s]", res, alert_json["info"])
end
return res