Implements example of simplified flow alerts

This commit is contained in:
Simone Mainardi 2020-11-10 15:10:54 +01:00
parent 683a4a727b
commit 93920ccdce
9 changed files with 132 additions and 7 deletions

View file

@ -0,0 +1,31 @@
--
-- (C) 2019-20 - ntop.org
--
local alert_keys = require "alert_keys"
-- #######################################################
-- @brief Prepare an alert table used to generate the alert
-- @param one_param The first alert param
-- @param another_param The second alert param
-- @return A table with the alert built
local function createDemo(one_param, another_param)
local built = {
alert_type_params = {
one_param = one_param,
another_param = another_param
},
}
return built
end
-- #######################################################
return {
alert_key = alert_keys.user.alert_user_03,
i18n_title = "New API Demo",
icon = "fas fa-exclamation",
creator = createDemo,
}

View file

@ -0,0 +1,3 @@
return {
my_manifest_title = "My Manifest Title",
}

View file

@ -0,0 +1,10 @@
--
-- (C) 2019-20 - ntop.org
--
return {
title = "Demo to trigger flow alerts with the new API",
description = "Demo plugin to trigger flow alerts with the new API",
author = "ntop",
dependencies = {},
}

View file

@ -0,0 +1,25 @@
--
-- (C) 2019-20 - ntop.org
--
local status_keys = require "flow_keys"
local alert_consts = require "alert_consts"
-- #################################################################
local function formatDemo(flowstatus_info)
if flowstatus_info and flowstatus_info.one_param and flowstatus_info.another_param then
return string.format("New API demo: [%s][%s]", flowstatus_info.one_param, flowstatus_info.another_param)
end
return "New API Demo"
end
-- #################################################################
return {
status_key = status_keys.user.status_user_03,
alert_type = alert_consts.alert_types.alert_new_api_demo,
i18n_title = "New API Demo",
i18n_description = formatDemo
}

View file

@ -0,0 +1,42 @@
--
-- (C) 2019-20 - ntop.org
--
local user_scripts = require("user_scripts")
local alert_consts = require("alert_consts")
local flow_consts = require "flow_consts"
local alerts_api = require "alerts_api"
-- #################################################################
local script = {
-- Script category
category = user_scripts.script_categories.security,
-- NOTE: hooks defined below
hooks = {},
gui = {
i18n_title = "New API Demo",
i18n_description = "Demonstrate the use of the new API for flow alerts",
}
}
-- #################################################################
function script.hooks.protocolDetected(now)
if true then -- TODO: set to true to execute
local cli_score, srv_score, flow_score = 10, 10, 10
local status_type = flow_consts.status_types.status_new_api_demo.create(
"one_param",
"another_param"
)
alerts_api.trigger_status(status_type, alert_consts.alert_severities.error, cli_score, srv_score, flow_score)
end
end
-- #################################################################
return script