mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Revert "Migrates alerts to an object-oriented implementation"
This reverts commit fbc283f12f.
This commit is contained in:
parent
fbc283f12f
commit
e24ef4ef35
108 changed files with 1741 additions and 2797 deletions
|
|
@ -2,69 +2,35 @@
|
|||
-- (C) 2019-20 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_keys = require "alert_keys"
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
local json = require("dkjson")
|
||||
local alert_keys = require "alert_keys"
|
||||
local alert_creators = require "alert_creators"
|
||||
local format_utils = require "format_utils"
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Make sure to import the Superclass!
|
||||
local alert = require "alert"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_threshold_cross = classes.class(alert)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
alert_threshold_cross.meta = {
|
||||
alert_key = alert_keys.ntopng.alert_threshold_cross,
|
||||
i18n_title = "alerts_dashboard.threashold_cross",
|
||||
icon = "fas fa-arrow-circle-up",
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Prepare an alert table used to generate the alert
|
||||
-- @param metric Same as `alert_subtype`
|
||||
-- @param value A number indicating the measure which crossed the threshold
|
||||
-- @param operator A string indicating the operator used when evaluating the threshold, one of "gt", ">", "<"
|
||||
-- @param threshold A number indicating the threshold compared with `value` using operator
|
||||
-- @return A table with the alert built
|
||||
function alert_threshold_cross:init(metric, value, operator, threshold)
|
||||
-- Call the paren constructor
|
||||
self.super:init()
|
||||
|
||||
self.alert_type_params = alert_creators.createThresholdCross(metric, value, operator, threshold)
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
-- @brief Format an alert into a human-readable string
|
||||
-- @param ifid The integer interface id of the generated alert
|
||||
-- @param alert The alert description table, including alert data such as the generating entity, timestamp, granularity, type
|
||||
-- @param alert_type_params Table `alert_type_params` as built in the `:init` method
|
||||
-- @return A human-readable string
|
||||
function alert_threshold_cross.format(ifid, alert, alert_type_params)
|
||||
local function formatThresholdCross(ifid, alert, threshold_info)
|
||||
local alert_consts = require("alert_consts")
|
||||
local entity = alert_consts.formatAlertEntity(ifid, alert_consts.alertEntityRaw(alert["alert_entity"]), alert["alert_entity_val"])
|
||||
local engine_label = alert_consts.alertEngineLabel(alert_consts.alertEngine(alert_consts.sec2granularity(alert["alert_granularity"])))
|
||||
|
||||
return i18n("alert_messages.threshold_crossed", {
|
||||
granularity = engine_label,
|
||||
metric = alert_type_params.metric,
|
||||
metric = threshold_info.metric,
|
||||
entity = entity,
|
||||
host_category = format_utils.formatAddressCategory((json.decode(alert.alert_json)).alert_generation.host_info),
|
||||
value = string.format("%u", math.ceil(alert_type_params.value)),
|
||||
op = "&".. (alert_type_params.operator or "gt") ..";",
|
||||
threshold = alert_type_params.threshold,
|
||||
value = string.format("%u", math.ceil(threshold_info.value)),
|
||||
op = "&".. (threshold_info.operator or "gt") ..";",
|
||||
threshold = threshold_info.threshold,
|
||||
})
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return alert_threshold_cross
|
||||
return {
|
||||
alert_key = alert_keys.ntopng.alert_threshold_cross,
|
||||
i18n_title = "alerts_dashboard.threashold_cross",
|
||||
i18n_description = formatThresholdCross,
|
||||
icon = "fas fa-arrow-circle-up",
|
||||
creator = alert_creators.createThresholdCross,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue