1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
--
-- (C) 2019-22 - ntop.org
--
-- ##############################################
local flow_alert_keys = require "flow_alert_keys"
-- Import the classes library.
local classes = require "classes"
-- Make sure to import the Superclass!
local alert = require "alert"
local json = require "dkjson"
-- ##############################################
local alert_periodicity_changed = classes.class(alert)
-- ##############################################
alert_periodicity_changed.meta = {
alert_key = flow_alert_keys.flow_alert_periodicity_changed,
i18n_title = "alerts_dashboard.alert_periodicity_update",
icon = "fas fa-fw fa-arrows-alt-h",
}
-- ##############################################
-- @brief Prepare an alert table used to generate the alert
-- @return A table with the alert built
function alert_periodicity_changed:init()
-- Call the parent constructor
self.super:init()
self.alert_type_params = {
}
end
-- #######################################################
-- @brief Format an alert into a human-readable string
-- @param ifid The integer interface id of the generated alert
-- @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_periodicity_changed.format(ifid, alert, alert_type_params)
-- Extracting info field
local info = ""
local href = ""
local flow_infos = {
host = alert["cli_ip"],
l7proto = ternary(tonumber(alert["l7_proto"]) ~= 0, alert["l7_proto"], alert["l7_master_proto"]),
vlan_id = alert["vlan_id"]
}
if alert.json then
info = json.decode(alert["json"])
if not isEmptyString(info["info"]) then
info = "[" .. info["info"] .. "]"
else
info = ""
end
end
if ntop.isEnterprise() and ntop.isAdministrator() then
local dirs = ntop.getDirs()
package.path = dirs.installdir .. "/pro/scripts/lua/enterprise/modules/?.lua;" .. package.path
local graph_map_utils = require("graph_map_utils")
href = '<a href="' .. graph_map_utils.getMapUrl(flow_infos, interface.getId(), 'periodicity_map', 'graph') .. '"><i class="fas fa-lg fa-clock"></i></a>'
end
if alert_type_params.is_periodic then
return(i18n("alerts_dashboard.periodicity_is_periodic_descr", { info = info, href = href }))
elseif alert_type_params.is_aperiodic then
return(i18n("alerts_dashboard.periodicity_is_aperiodic_descr", { info = info, href = href }))
else
return(i18n("alerts_dashboard.periodicity_changed_descr", { info = info, href = href }))
end
end
-- #######################################################
return alert_periodicity_changed
|