Fix corner cases in alert_elephant_flow.format

This commit is contained in:
Alfredo Cardigliano 2024-08-05 18:00:22 +02:00
parent e522eebf6b
commit 206b86544f

View file

@ -58,25 +58,35 @@ function alert_elephant_flow.format(ifid, alert, alert_type_params)
local threshold = ""
local res = ""
if alert_type_params then
if alert_type_params and (alert_type_params["l2r_bytes"] or alert_type_params["r2l_bytes"]) then
local l2r_bytes = bytesToSize(alert_type_params["l2r_bytes"])
local r2l_bytes = bytesToSize(alert_type_params["r2l_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"])
if alert_type_params["l2r_bytes"] and
alert_type_params["l2r_threshold"] and
alert_type_params["l2r_threshold"] > 0 and
alert_type_params["l2r_bytes"] > alert_type_params["l2r_threshold"] then
local l2r_threshold = bytesToSize(alert_type_params["l2r_threshold"])
l2r_bytes = l2r_bytes .." > "..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"])
if alert_type_params["r2l_bytes"] and
alert_type_params["r2l_threshold"] and
alert_type_params["l2r_threshold"] > 0 and
alert_type_params["r2l_bytes"] > alert_type_params["r2l_threshold"] then
local r2l_threshold = bytesToSize(alert_type_params["r2l_threshold"])
r2l_bytes = r2l_bytes .. " > "..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"])
if alert["json"] then
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
end
return res