Changed interface thpt alert

This commit is contained in:
MatteoBiscosi 2022-06-10 11:45:31 +02:00
parent bd65b3d7b5
commit a20d2dba58
2 changed files with 28 additions and 5 deletions

View file

@ -13,6 +13,9 @@ local script = {
default_enabled = false,
default_value = {
-- "> 5%"
operator = "gt",
threshold = 80,
},
-- See below
@ -21,8 +24,11 @@ local script = {
gui = {
i18n_title = "alerts_thresholds_config.throughput",
i18n_description = "alerts_thresholds_config.alert_throughput_description",
i18n_field_unit = checks.field_units.mbits,
i18n_field_unit = checks.field_units.percentage,
input_builder = "threshold_cross",
field_max = 99,
field_min = 1,
field_operator = "gt";
}
}
@ -30,16 +36,33 @@ local script = {
function script.hooks.min(params)
local interface_bytes = params.entity_info["stats"]["bytes"]
local interface_speed = params.entity_info["speed"]
local perc_threshold = tonumber(params.check_config.threshold)
local threshold = interface_speed * (perc_threshold / 100)
-- Delta
local value = alerts_api.interface_delta_val(script.key, params.granularity, interface_bytes)
-- Granularity
value = value / alert_consts.granularity2sec(params.granularity)
-- Bytes to Mbit
-- Bytes to Mbit, the Interface speed is in Mbit
value = (value * 8) / 1000000
-- Check if the configured threshold is crossed by the value and possibly trigger an alert
alerts_api.checkThresholdAlert(params, alert_consts.alert_types.alert_threshold_cross, value)
local alert = alert_consts.alert_types.alert_threshold_cross.new(
params.check.key,
value,
params.check_config.operator,
threshold
)
alert:set_score_error()
alert:set_subtype(params.entity_info["name"])
alert:set_granularity(params.granularity)
if(value > threshold) then
alert:trigger(params.alert_entity, nil, params.cur_alerts)
else
alert:release(params.alert_entity, nil, params.cur_alerts)
end
end
-- #################################################################