mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-02 08:50:12 +00:00
Plugins are a convenient way to group together related lua scripts. Their primary use case is to group user scripts and their alert/status definition. The builtin ntopng user scripts and definitions are now packed into plugins directories. In future, we will support loading of user created plugins. Plugins are loaded at startup into some runtime directories and then used. Other changes provided by this commit include: - Add sample flow logger plugin - Initial support for system user scripts - Rename edge to threshold - Migrate system probes to user scripts/plugins - Migrate scripts to more explicit alerts_api.checkThresholdAlert api
66 lines
1.9 KiB
Lua
66 lines
1.9 KiB
Lua
--
|
|
-- (C) 2019 - ntop.org
|
|
--
|
|
|
|
local alerts_api = require("alerts_api")
|
|
local alert_consts = require("alert_consts")
|
|
local user_scripts = require("user_scripts")
|
|
|
|
-- #################################################################
|
|
|
|
local function check_interface_idle(params)
|
|
local threshold = tonumber(params.alert_config.threshold)
|
|
local engage = false
|
|
local max_idle = 0
|
|
local max_idle_perc = 0
|
|
|
|
local hash_tables_stats = interface.getHashTablesStats()
|
|
for ht_name, ht_stats in pairsByKeys(hash_tables_stats, asc) do
|
|
local idle = ht_stats["hash_entry_states"]["hash_entry_state_idle"] or "0"
|
|
local active = ht_stats["hash_entry_states"]["hash_entry_state_active"] or "0"
|
|
local idle_perc = math.min(idle * 100.0 / (idle + active + 1), 100)
|
|
if (idle + active) > 1000 and idle_perc > threshold then
|
|
if idle_perc > max_idle_perc then
|
|
max_idle = idle
|
|
max_idle_perc = idle_perc
|
|
end
|
|
end
|
|
end
|
|
|
|
local idle_type = alerts_api.slowPurgeType(max_idle, max_idle_perc, threshold)
|
|
if max_idle_perc > threshold then
|
|
alerts_api.trigger(params.alert_entity, idle_type, nil, params.cur_alerts)
|
|
else
|
|
alerts_api.release(params.alert_entity, idle_type, nil, params.cur_alerts)
|
|
end
|
|
end
|
|
|
|
-- #################################################################
|
|
|
|
local script = {
|
|
default_enabled = true,
|
|
default_value = {
|
|
-- "> 50%"
|
|
operator = "gt",
|
|
threshold = 50,
|
|
},
|
|
|
|
hooks = {
|
|
min = check_interface_idle,
|
|
},
|
|
|
|
gui = {
|
|
i18n_title = "alerts_thresholds_config.alert_slow_purge_threshold",
|
|
i18n_description = "alerts_thresholds_config.alert_slow_purge_threshold_descr",
|
|
i18n_field_unit = user_scripts.field_units.percentage,
|
|
input_builder = user_scripts.threshold_cross_input_builder,
|
|
post_handler = user_scripts.threshold_cross_post_handler,
|
|
field_max = 99,
|
|
field_min = 1,
|
|
field_operator = "gt";
|
|
}
|
|
}
|
|
|
|
-- #################################################################
|
|
|
|
return script
|