mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 07:29:32 +00:00
Migrates alerts to an object-oriented implementation
This commit is contained in:
parent
f412783c12
commit
101c53336e
30 changed files with 970 additions and 910 deletions
|
|
@ -2,39 +2,51 @@
|
|||
-- (C) 2019-20 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_keys = require "alert_keys"
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Make sure to import the Superclass!
|
||||
local alert = require "alert"
|
||||
|
||||
-- #######################################################
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Prepare an alert table used to generate the alert
|
||||
-- @param alert_severity A severity as defined in `alert_severities`
|
||||
-- @param alert_granularity A granularity as defined in `alert_consts.alerts_granularities`
|
||||
-- @param last_error A string with the lastest influxdb error
|
||||
-- @return A table with the alert built
|
||||
local function createInfluxdbError(alert_severity, alert_granularity, last_error)
|
||||
local threshold_type = {
|
||||
alert_severity = alert_severity,
|
||||
alert_granularity = alert_granularity,
|
||||
alert_type_params = {
|
||||
error_msg = last_error
|
||||
},
|
||||
}
|
||||
local alert_influxdb_error = classes.class(alert)
|
||||
|
||||
return threshold_type
|
||||
end
|
||||
-- ##############################################
|
||||
|
||||
-- #######################################################
|
||||
|
||||
local function formatInfluxdbErrorMessage(ifid, alert, status)
|
||||
return(status.error_msg)
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return {
|
||||
alert_influxdb_error.meta = {
|
||||
alert_key = alert_keys.ntopng.alert_influxdb_error,
|
||||
i18n_title = "alerts_dashboard.influxdb_error",
|
||||
i18n_description = formatInfluxdbErrorMessage,
|
||||
icon = "fas fa-database",
|
||||
creator = createInfluxdbError,
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Prepare an alert table used to generate the alert
|
||||
-- @param last_error A string with the lastest influxdb error
|
||||
-- @return A table with the alert built
|
||||
function alert_influxdb_error:init(last_error)
|
||||
-- Call the paren constructor
|
||||
self.super:init()
|
||||
|
||||
self.alert_type_params = {
|
||||
error_msg = last_error
|
||||
}
|
||||
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_influxdb_error.format(ifid, alert, alert_type_params)
|
||||
return(alert_type_params.error_msg)
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return alert_influxdb_error
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue