mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Added device connection/disconnection alert (#6801)
This commit is contained in:
parent
ad7a312249
commit
d6471d8dac
15 changed files with 105 additions and 116 deletions
|
|
@ -19,7 +19,7 @@ local alert_device_connection = classes.class(alert)
|
|||
-- ##############################################
|
||||
|
||||
alert_device_connection.meta = {
|
||||
alert_key = other_alert_keys.alert_device_connection,
|
||||
alert_key = other_alert_keys.alert_device_connection_disconnection,
|
||||
i18n_title = "alerts_dashboard.device_connection",
|
||||
icon = "fas fa-fw fa-sign-in",
|
||||
entities = {
|
||||
|
|
@ -50,7 +50,7 @@ end
|
|||
-- @return A human-readable string
|
||||
function alert_device_connection.format(ifid, alert, alert_type_params)
|
||||
return(i18n("alert_messages.device_has_connected", {
|
||||
device = info.device,
|
||||
device = alert_type_params.device,
|
||||
url = getMacUrl(alert.entity_val),
|
||||
}))
|
||||
end
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
--
|
||||
-- (C) 2019-22 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local other_alert_keys = require "other_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_entities = require "alert_entities"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_device_disconnection = classes.class(alert)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
alert_device_disconnection.meta = {
|
||||
alert_key = other_alert_keys.alert_device_disconnection,
|
||||
i18n_title = "alerts_dashboard.device_disconnection",
|
||||
icon = "fas fa-fw fa-sign-out",
|
||||
entities = {
|
||||
alert_entities.mac
|
||||
},
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
-- @brief Prepare an alert table used to generate the alert
|
||||
-- @param device The a string with the name or ip address of the device that connected/disconnected
|
||||
-- @return A table with the alert built
|
||||
function alert_device_disconnection:init(device)
|
||||
-- Call the parent constructor
|
||||
self.super:init()
|
||||
|
||||
self.alert_type_params = {
|
||||
device = device,
|
||||
}
|
||||
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_device_disconnection.format(ifid, alert, alert_type_params)
|
||||
local device = info.device
|
||||
|
||||
if not device or device == "" then
|
||||
device = alert.entity_val
|
||||
end
|
||||
|
||||
return(i18n("alert_messages.device_has_disconnected", {
|
||||
device = device,
|
||||
url = getMacUrl(alert.entity_val),
|
||||
}))
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return alert_device_disconnection
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
--
|
||||
-- (C) 2019-22 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local dirs = ntop.getDirs()
|
||||
local other_alert_keys = require "other_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_entities = require "alert_entities"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_unexpected_new_device = classes.class(alert)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
alert_unexpected_new_device.meta = {
|
||||
alert_key = other_alert_keys.alert_unexpected_new_device,
|
||||
i18n_title = "checks.unexpected_new_device_title",
|
||||
icon = "fas fa-fw fa-exclamation",
|
||||
entities = {
|
||||
alert_entities.mac
|
||||
},
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function alert_unexpected_new_device:init(device, mac)
|
||||
-- Call the parent 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
|
||||
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)
|
||||
-- The host has an snmp location
|
||||
if has_snmp_location then
|
||||
local access_port = snmp_location.get_host_access_port(alert_type_params.mac)
|
||||
|
||||
if access_port then
|
||||
return(i18n("checks.status_unexpected_new_device_description_pro", {
|
||||
mac_address = alert_type_params.device,
|
||||
host_url = getMacUrl(alert_type_params.mac),
|
||||
port = access_port.id,
|
||||
port_url = snmpIfaceUrl(access_port.snmp_device_ip, access_port.id),
|
||||
interface_name = access_port.name,
|
||||
ip = access_port.snmp_device_ip,
|
||||
ip_url = snmpDeviceUrl(access_port.snmp_device_ip),
|
||||
}))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Non enterprise software or the host hasn't an snmp location
|
||||
return(i18n("checks.status_unexpected_new_device_description", {
|
||||
mac_address = alert_type_params.device,
|
||||
host_url = getMacUrl(alert_type_params.mac),
|
||||
}))
|
||||
end
|
||||
|
||||
-- #######################################################
|
||||
|
||||
return alert_unexpected_new_device
|
||||
Loading…
Add table
Add a link
Reference in a new issue