mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Migrates alerts to an object-oriented implementation
This commit is contained in:
parent
c1a7ff08ae
commit
fbc283f12f
108 changed files with 2793 additions and 1737 deletions
|
|
@ -1,64 +1,77 @@
|
|||
--
|
||||
-- (C) 2019 - ntop.org
|
||||
-- (C) 2019-20 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_keys = require "alert_keys"
|
||||
package.path = dirs.installdir .. "/scripts/lua/modules/?.lua;" .. package.path
|
||||
|
||||
-- #######################################################
|
||||
local status_keys = require "flow_keys"
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Make sure to import the Superclass!
|
||||
local alert = require "alert"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_snmp_topology_changed = classes.class(alert)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
alert_snmp_topology_changed.meta = {
|
||||
alert_key = alert_keys.ntopng.alert_snmp_topology_changed,
|
||||
i18n_title = i18n("snmp.lldp_topology_changed"),
|
||||
icon = "fas fa-topology-alt",
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Prepare an alert table used to generate the alert
|
||||
-- @param alert_severity A severity as defined in `alert_severities`
|
||||
-- @param alert_subtype A string indicating the subtype for this alert, one of 'arc_added', 'arc_removed'
|
||||
-- @param alert_granularity A granularity as defined in `alert_consts.alerts_granularities`
|
||||
-- @param node1 A string with the name of the first of the two peers involved in the change
|
||||
-- @param ip1 A string with the ip of the first of the two peers involved in the change
|
||||
-- @param node2 A string with the name of the second of the two peers involved in the change
|
||||
-- @param ip2 A string with the ip of the second of the two peers involved in the change
|
||||
-- @return A table with the alert built
|
||||
local function createTopologyChanged(alert_severity, alert_subtype, alert_granularity, node1, ip1, node2, ip2)
|
||||
local built = {
|
||||
alert_subtype = alert_subtype,
|
||||
alert_severity = alert_severity,
|
||||
alert_granularity = alert_granularity,
|
||||
alert_type_params = {
|
||||
node1 = node1, ip1 = ip1,
|
||||
node2 = node2, ip2 = ip2,
|
||||
},
|
||||
}
|
||||
function alert_snmp_topology_changed:init(node1, ip1, node2, ip2)
|
||||
-- Call the parent constructor
|
||||
self.super:init()
|
||||
|
||||
return built
|
||||
self.alert_type_params = {
|
||||
node1 = node1, ip1 = ip1,
|
||||
node2 = node2, ip2 = ip2,
|
||||
}
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
local function formatTopologyChanged(ifid, alert, alert_info)
|
||||
-- @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_snmp_topology_changed.format(ifid, alert, alert_type_params)
|
||||
if not ntop.isPro() then
|
||||
return ""
|
||||
end
|
||||
|
||||
if(alert.alert_subtype == "arc_added") then
|
||||
return(i18n("alert_messages.lldp_arc_added", {
|
||||
node1 = alert_info.node1,
|
||||
node2 = alert_info.node2,
|
||||
url1 = snmpDeviceUrl(alert_info.ip1),
|
||||
url2 = snmpDeviceUrl(alert_info.ip2),
|
||||
node1 = alert_type_params.node1,
|
||||
node2 = alert_type_params.node2,
|
||||
url1 = snmpDeviceUrl(alert_type_params.ip1),
|
||||
url2 = snmpDeviceUrl(alert_type_params.ip2),
|
||||
}))
|
||||
else
|
||||
return(i18n("alert_messages.lldp_arc_removed", {
|
||||
node1 = alert_info.node1,
|
||||
node2 = alert_info.node2,
|
||||
url1 = snmpDeviceUrl(alert_info.ip1),
|
||||
url2 = snmpDeviceUrl(alert_info.ip2),
|
||||
node1 = alert_type_params.node1,
|
||||
node2 = alert_type_params.node2,
|
||||
url1 = snmpDeviceUrl(alert_type_params.ip1),
|
||||
url2 = snmpDeviceUrl(alert_type_params.ip2),
|
||||
}))
|
||||
end
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return {
|
||||
alert_key = alert_keys.ntopng.alert_snmp_topology_changed,
|
||||
i18n_title = i18n("snmp.lldp_topology_changed"),
|
||||
i18n_description = formatTopologyChanged,
|
||||
icon = "fas fa-topology-alt",
|
||||
creator = createTopologyChanged,
|
||||
}
|
||||
return alert_snmp_topology_changed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue