Reworked SNMP interfaces average usage and replaced the interface load alert with the interface average usage alert (#8168)

This commit is contained in:
Nicolo Maio 2024-01-17 12:41:59 +01:00
parent c0dcf3f83e
commit b3c573498f
5 changed files with 46 additions and 40 deletions

View file

@ -13,13 +13,13 @@ local alert_entities = require "alert_entities"
-- ##############################################
local alert_port_load_threshold_exceeded = classes.class(alert)
local alert_port_avg_usages_threshold_crossed = classes.class(alert)
-- ##############################################
alert_port_load_threshold_exceeded.meta = {
alert_key = other_alert_keys.alert_port_load_threshold_exceeded,
i18n_title = "alerts_dashboard.snmp_port_load_threshold_exceeded",
alert_port_avg_usages_threshold_crossed.meta = {
alert_key = other_alert_keys.alert_port_avg_usages_threshold_crossed,
i18n_title = "alerts_dashboard.snmp_port_avg_perc_usage_threshold_crossed",
icon = "fas fa-fw fa-exclamation",
entities = {
alert_entities.snmp_device
@ -33,11 +33,11 @@ alert_port_load_threshold_exceeded.meta = {
-- @param device_name The device name
-- @param if_index The index of the port that changed
-- @param interface_name The string with the name of the port that changed
-- @param in_load The ingress load in percentage
-- @param out_load The egress load in percentage
-- @param load_threshold The threshold configured for the load
-- @param avg_in_perc The ingress avg usage in percentage
-- @param avg_out_perc The egress avg usage in percentage
-- @param usage_threshold The threshold configured for the usage
-- @return A table with the alert built
function alert_port_load_threshold_exceeded:init(device_ip, device_name, if_index, interface_name, in_load, out_load, load_threshold)
function alert_port_avg_usages_threshold_crossed:init(device_ip, device_name, if_index, interface_name, avg_in_perc, avg_out_perc, usage_threshold)
-- Call the parent constructor
self.super:init()
@ -46,9 +46,9 @@ function alert_port_load_threshold_exceeded:init(device_ip, device_name, if_inde
device_name = device_name,
interface = if_index,
interface_name = interface_name,
in_load = in_load,
out_load = out_load,
load_threshold = load_threshold,
avg_in_perc = avg_in_perc,
avg_out_perc = avg_out_perc,
usage_threshold = usage_threshold,
}
end
@ -59,20 +59,20 @@ end
-- @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_port_load_threshold_exceeded.format(ifid, alert, alert_type_params)
function alert_port_avg_usages_threshold_crossed.format(ifid, alert, alert_type_params)
local fmt = {
device = alert_type_params.device,
port = alert_type_params.interface_name or alert_type_params.interface,
url = snmpDeviceUrl(alert_type_params.device),
port_url = snmpIfaceUrl(alert_type_params.device, alert_type_params.interface),
in_load = alert_type_params.in_load,
out_load = alert_type_params.out_load,
threshold = alert_type_params.load_threshold,
avg_in_perc = alert_type_params.avg_in_perc,
avg_out_perc = alert_type_params.avg_out_perc,
threshold = alert_type_params.usage_threshold,
}
return(i18n("alerts_dashboard.snmp_port_load_threshold_exceeded_message", fmt))
return(i18n("alerts_dashboard.snmp_port_avg_perc_usage_threshold_crossed_message", fmt))
end
-- #######################################################
return alert_port_load_threshold_exceeded
return alert_port_avg_usages_threshold_crossed