Fixes behavior anomaly alert key not found

This commit is contained in:
MatteoBiscosi 2021-06-23 22:55:08 +02:00
parent fd40e51428
commit 47497ca666
5 changed files with 45 additions and 37 deletions

View file

@ -7,6 +7,7 @@
local other_alert_keys = require "other_alert_keys"
local classes = require "classes"
local alert = require "alert"
local behavior_utils = require("behavior_utils")
-- ##############################################
@ -29,7 +30,7 @@ alert_behavior_anomaly.meta = {
-- @param lower_bound The lower bound of the measurement
-- @param upper_bound The upper bound of the measurement
-- @return A table with the alert built
function alert_behavior_anomaly:init(entity, type_of_behavior, value, upper_bound, lower_bound, family_key, timeseries_id --[[ This last 3 params are used to build up the href to the timeseries lately, if available ]])
function alert_behavior_anomaly:init(entity, type_of_behavior, value, upper_bound, lower_bound, family_key, timeseries_id)
-- Call the parent constructor
self.super:init()
@ -63,29 +64,26 @@ function alert_behavior_anomaly.format(ifid, alert, alert_type_params)
-- Generating the href for the timeserie
if ntop.isEnterpriseL() then
if alert_type_params["family_key"] and alert_type_params["timeseries_id"] then
local alert_utils = require("alert_utils")
-- 10 minutes before and 10 minutes after the alert
local alert_time = tonumber(alert.tstamp)
local curr_time = '&epoch_begin=' .. tonumber(alert_time - 600) .. '&epoch_end=' .. tonumber(alert_time + 600)
local timeseries_table = alert_utils.get_behavior_timeseries_utils(alert_type_params["family_key"])
local timeseries_table = behavior_utils.get_behavior_timeseries_utils(alert_type_params["family_key"])
href = timeseries_table["page_path"] .. "?" .. timeseries_table["timeseries_id"] .. "=" .. alert_type_params["timeseries_id"] ..
"&ifid=" .. ifid .. "&page=historical&ts_schema=" .. timeseries_table["schema_id"] .. "%3A" .. alert_type_params.type_of_behavior ..
"&zoom=30m" .. curr_time
href = timeseries_table["page_path"] .. "?" .. timeseries_table["timeseries_id"] .. "=" .. alert_type_params["timeseries_id"] ..
"&ifid=" .. ifid .. "&page=historical&ts_schema=" .. timeseries_table["schema_id"] .. "%3A" .. alert_type_params.type_of_behavior ..
"&zoom=30m" .. curr_time
end
end
return(i18n("alerts_dashboard.unexpected_behavior_anomaly_description",
{
entity = alert_type_params.entity or "",
type_of_behavior = type_of_behavior,
value = alert_type_params.value or 0,
lower_bound = alert_type_params.lower_bound or 0,
upper_bound = alert_type_params.upper_bound or 0,
href = href,
}))
return(i18n("alerts_dashboard.unexpected_behavior_anomaly_description", {
entity = alert_type_params.entity or "",
type_of_behavior = type_of_behavior,
value = alert_type_params.value or 0,
lower_bound = alert_type_params.lower_bound or 0,
upper_bound = alert_type_params.upper_bound or 0,
href = href,
}))
end
-- #######################################################