Fixes and cleanup for low goodput user script

This commit is contained in:
Simone Mainardi 2020-11-17 17:33:52 +01:00
parent 17266b71a6
commit 658b48994d
5 changed files with 13 additions and 75 deletions

View file

@ -10,7 +10,11 @@ local format_utils = require("format_utils")
-- #################################################################
local function formatFlowLowGoodput(info)
return i18n("flow_details.flow_low_goodput", { ratio = format_utils.round(info.goodput_ratio,2) })
if info and info.goodput_ratio then
return i18n("flow_details.flow_low_goodput", { ratio = format_utils.round(info.goodput_ratio, 2) })
end
return(i18n("alerts_dashboard.flow_low_goodput"))
end
-- #################################################################
@ -18,6 +22,6 @@ end
return {
status_key = status_keys.ntopng.status_low_goodput,
alert_type = alert_consts.alert_types.alert_flow_low_goodput,
i18n_title = "flow_details.flow_low_goodput",
i18n_title = "alerts_dashboard.flow_low_goodput",
i18n_description = formatFlowLowGoodput
}

View file

@ -13,6 +13,10 @@ local script = {
-- Script category
category = user_scripts.script_categories.network,
packet_interface_only = true,
nedge_exclude = true,
l4_proto = "tcp",
-- NOTE: hooks defined below
hooks = {},

View file

@ -1,55 +0,0 @@
--
-- (C) 2019-20 - ntop.org
--
local flow_consts = require("flow_consts")
local user_scripts = require ("user_scripts")
local alerts_api = require "alerts_api"
local alert_consts = require("alert_consts")
-- #################################################################
-- NOTE: this module is always enabled
local script = {
-- Script category
category = user_scripts.script_categories.network,
packet_interface_only = true,
nedge_exclude = true,
l4_proto = "tcp",
three_way_handshake_ok = true,
-- Default values (will be made configurable from the UI)
default_low_goodput_min_duration_secs = 600, -- 5 minutes
default_low_goodput_threshold_pct = 20, -- Triggers the low goodput status if <=20%
-- NOTE: hooks defined below
hooks = {},
gui = {
i18n_title = "flow_callbacks_config.tcp_issues_packets",
i18n_description = "flow_callbacks_config.tcp_issues_packets_description",
}
}
-- #################################################################
function script.hooks.periodicUpdate(now)
if flow.getDuration() >= script.default_low_goodput_min_duration_secs then
local cur_bytes = flow.getBytes()
if cur_bytes > 0 then
local cur_goodput = flow.getGoodputBytes() / flow.getBytes() * 100
if cur_goodput <= script.default_low_goodput_threshold_pct then
local low_goodput_type = flow_consts.status_types.status_low_goodput.create()
alerts_api.trigger_status(low_goodput_type, alert_consts.alert_severities.info, 10, 10, 10)
end
end
end
end
-- #################################################################
return script