mirror of
https://github.com/ntop/ntopng.git
synced 2026-05-03 01:10:10 +00:00
Reworks experimental object-oriented alerts code
This commit is contained in:
parent
49749f7e3b
commit
2cc45f5229
6 changed files with 209 additions and 93 deletions
|
|
@ -2,11 +2,25 @@
|
|||
-- (C) 2019-20 - ntop.org
|
||||
--
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local alert_keys = require "alert_keys"
|
||||
-- Import the classes library.
|
||||
local classes = require "classes"
|
||||
-- Make sure to import the Superclass!
|
||||
local alert = require "alert"
|
||||
|
||||
-- ##############################################
|
||||
|
||||
local NewHostAlert = { }
|
||||
local NewHostAlert = classes.class(alert)
|
||||
|
||||
-- ##############################################
|
||||
|
||||
NewHostAlert.meta = {
|
||||
alert_key = alert_keys.user.alert_user_04,
|
||||
i18n_title = "New Host API Demo",
|
||||
icon = "fas fa-exclamation",
|
||||
}
|
||||
|
||||
-- ##############################################
|
||||
|
||||
|
|
@ -14,8 +28,10 @@ local NewHostAlert = { }
|
|||
-- @param one_param The first alert param
|
||||
-- @param another_param The second alert param
|
||||
-- @return A table with the alert built
|
||||
function NewHostAlert:set_params(one_param, another_param)
|
||||
-- tprint("new create: "..self.def_script.alert_key)
|
||||
function NewHostAlert:init(one_param, another_param)
|
||||
-- Optional, call to the `alert` constructor
|
||||
self.super:init()
|
||||
|
||||
self.alert_type_params = {
|
||||
one_param = one_param,
|
||||
another_param = another_param
|
||||
|
|
@ -30,9 +46,4 @@ end
|
|||
|
||||
-- #######################################################
|
||||
|
||||
return {
|
||||
alert_key = alert_keys.user.alert_user_04,
|
||||
i18n_title = "New Host API Demo",
|
||||
icon = "fas fa-exclamation",
|
||||
Alert = NewHostAlert
|
||||
}
|
||||
return NewHostAlert
|
||||
|
|
|
|||
|
|
@ -26,28 +26,26 @@ local script = {
|
|||
|
||||
function script.hooks.min(params)
|
||||
if false then -- TODO: set to true to execute
|
||||
local Alert = alert_consts.alert_types.alert_host_new_api_demo.new()
|
||||
|
||||
Alert:set_severity(alert_consts.alert_severities.error)
|
||||
Alert:set_granularity(params.granularity)
|
||||
|
||||
Alert:set_params(
|
||||
local alert = alert_consts.alert_types.alert_host_new_api_demo.new(
|
||||
"one_param",
|
||||
"another_param"
|
||||
)
|
||||
|
||||
alert:set_severity(alert_consts.alert_severities.error)
|
||||
alert:set_granularity(params.granularity)
|
||||
|
||||
if cond then
|
||||
Alert:set_attacker()
|
||||
alert:set_attacker()
|
||||
end
|
||||
|
||||
if another_cond then
|
||||
Alert:set_victim()
|
||||
alert:set_victim()
|
||||
end
|
||||
|
||||
if true then
|
||||
Alert:trigger(params.alert_entity, nil, params.cur_alerts)
|
||||
alert:trigger(params.alert_entity, nil, params.cur_alerts)
|
||||
else
|
||||
Alert:release(params.alert_entity, nil, params.cur_alerts)
|
||||
alert:release(params.alert_entity, nil, params.cur_alerts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue