moved update notification and too many flow notification

This commit is contained in:
gabryon99 2020-07-16 10:50:52 +02:00
parent 8b573d29b0
commit da7278065d
12 changed files with 157 additions and 120 deletions

View file

@ -3,6 +3,7 @@
--
local dirs = ntop.getDirs()
local info = ntop.getInfo()
local prefs = ntop.getPrefs()
local defined_alert_notifications = {}
local telemetry_utils = require("telemetry_utils")
@ -13,7 +14,7 @@ local function create_geo_ip_alert_notification()
local title = i18n("geo_map.geo_ip")
local description = i18n("geolocation_unavailable", {url = "https://github.com/ntop/ntopng/blob/dev/doc/README.geolocation.md", target = "_blank", icon = "fas fa-external-link-alt"})
return alert_notification:create("geoip_alert", title, description, "warning", nil)
return alert_notification:create("geoip_alert", title, description, "warning")
end
local function create_contribute_alert_notification()
@ -25,8 +26,7 @@ local function create_contribute_alert_notification()
title = i18n("configure")
}
return alert_notification:create("contribute_alert", title, description, "info", action, 0, "/lua/admin/prefs.lua")
return alert_notification:create("contribute_alert", title, description, "info", action, "/lua/admin/prefs.lua")
end
local function create_tempdir_alert_notification()
@ -37,10 +37,25 @@ local function create_tempdir_alert_notification()
url = "https://www.ntop.org/support/faq/migrate-the-data-directory-in-ntopng/"
}
return alert_notification:create("tempdir_alert", title, description, "warning", action, 0)
return alert_notification:create("tempdir_alert", title, description, "warning", action)
end
local function create_update_ntopng_notification(body)
local title = i18n("update")
return alert_notification:create("update_alert", title, body, "info")
end
local function create_too_many_flows_notification(level)
local title = i18n("too_many_flows")
local desc = i18n("about.you_have_too_many_flows", {product=info["product"]})
return alert_notification:create("toomanyflows_alert", title, desc, level)
end
-- ##################################################################
--- Create an instance for the geoip alert notification
--- if the user doesn't have geoIP installed
--- @param container table The table where the notification will be inserted
@ -73,4 +88,37 @@ function defined_alert_notifications.contribute(container)
end
function defined_alert_notifications.update_ntopng(container)
-- check if ntopng is oem and the user is an Administrator
local is_not_oem_and_administrator = isAdministrator() and not info.oem
local message = check_latest_major_release()
if is_not_oem_and_administrator and not isEmptyString(message) then
table.insert(container, create_update_ntopng_notification(message))
end
end
function defined_alert_notifications.too_many_flows(container)
local level = nil
local flows = interface.getNumFlows()
local flows_pctg = math.floor(1 + ((flows * 100) / prefs.max_num_flows))
local ALARM_THRESHOLD_LOW = 60
local ALARM_THRESHOLD_HIGH = 90;
if (flows_pctg >= ALARM_THRESHOLD_LOW and flows_pctg <= ALARM_THRESHOLD_HIGH) then
level = "warning"
elseif (flows_pctg > ALARM_THRESHOLD_HIGH) then
level = "danger"
end
if (level ~= nil) then
table.insert(container, create_too_many_flows_notification(level))
end
end
return defined_alert_notifications