mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-01 00:19: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
|
|
@ -1,57 +1,28 @@
|
|||
--
|
||||
-- (C) 2019-20 - ntop.org
|
||||
-- (C) 2020 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
local alert_keys = require "alert_keys"
|
||||
local alert_creators = require "alert_creators"
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Make sure to import the Superclass!
|
||||
local alert = require "alert"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_unexpected_new_device = classes.class(alert)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
alert_unexpected_new_device.meta = {
|
||||
alert_key = alert_keys.ntopng.alert_unexpected_new_device,
|
||||
i18n_title = "unexpected_new_device.alert_unexpected_new_device_title",
|
||||
icon = "fas fa-exclamation",
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function alert_unexpected_new_device:init(device, mac)
|
||||
-- Call the paren constructor
|
||||
self.super:init()
|
||||
|
||||
self.alert_type_params = {
|
||||
device = device,
|
||||
mac = mac,
|
||||
}
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
function alert_unexpected_new_device.format(ifid, alert, alert_type_params)
|
||||
-- Pro description
|
||||
local function formatUnexpectedNewDevice(ifid, alert, info)
|
||||
-- Pro description
|
||||
if(ntop.isPro()) then
|
||||
package.path = dirs.installdir .. "/pro/scripts/lua/modules/?.lua;" .. package.path
|
||||
local snmp_location = require "snmp_location"
|
||||
|
||||
has_snmp_location = snmp_location.host_has_snmp_location(alert_type_params.mac)
|
||||
has_snmp_location = snmp_location.host_has_snmp_location(info.mac)
|
||||
-- The host has an snmp location
|
||||
if has_snmp_location then
|
||||
local access_port = snmp_location.get_host_access_port(alert_type_params.mac)
|
||||
local access_port = snmp_location.get_host_access_port(info.mac)
|
||||
|
||||
if access_port then
|
||||
return(i18n("unexpected_new_device.status_unexpected_new_device_description_pro", {
|
||||
mac_address = alert_type_params.device,
|
||||
mac_address = info.device,
|
||||
host_url = getMacUrl(alert.alert_entity_val),
|
||||
port = access_port.id,
|
||||
port_url = snmpIfaceUrl(access_port.snmp_device_ip, access_port.id),
|
||||
|
|
@ -65,11 +36,31 @@ function alert_unexpected_new_device.format(ifid, alert, alert_type_params)
|
|||
|
||||
-- Non enterprise software or the host hasn't an snmp location
|
||||
return(i18n("unexpected_new_device.status_unexpected_new_device_description", {
|
||||
mac_address = alert_type_params.device,
|
||||
mac_address = info.device,
|
||||
host_url = getMacUrl(alert.alert_entity_val),
|
||||
}))
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local function createUnexpectedNewDevice(alert_severity, device, mac)
|
||||
local unexpected_new_device_type = {
|
||||
alert_severity = alert_severity,
|
||||
alert_type_params = {
|
||||
device = device,
|
||||
mac = mac,
|
||||
},
|
||||
}
|
||||
|
||||
return unexpected_new_device_type
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return alert_unexpected_new_device
|
||||
return {
|
||||
alert_key = alert_keys.ntopng.alert_unexpected_new_device,
|
||||
i18n_title = "unexpected_new_device.alert_unexpected_new_device_title",
|
||||
i18n_description = formatUnexpectedNewDevice,
|
||||
icon = "fas fa-exclamation",
|
||||
creator = createUnexpectedNewDevice,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,14 +70,14 @@ local function check_allowed_mac(params)
|
|||
|
||||
-- Check if the new mac address is expected or not
|
||||
if not mac_list[mac] then
|
||||
local alert = alert_consts.alert_types.alert_unexpected_new_device.create(
|
||||
device,
|
||||
mac
|
||||
alerts_api.store(
|
||||
alerts_api.macEntity(mac),
|
||||
alert_consts.alert_types.alert_unexpected_new_device.create(
|
||||
alert_severities.warning,
|
||||
device,
|
||||
mac
|
||||
)
|
||||
)
|
||||
|
||||
alert:set_severity(alert_severities.warning)
|
||||
|
||||
alert:store(alerts_api.macEntity(mac))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue