Avoid loops in shell script notifications

This commit is contained in:
Alfredo Cardigliano 2023-05-17 14:22:16 +02:00
parent d65bb0c143
commit 65f3b4c344

View file

@ -7,6 +7,7 @@ local sys_utils = require "sys_utils"
local json = require "dkjson"
local alerts_api = require "alerts_api"
local alert_consts = require "alert_consts"
local other_alert_keys = require "other_alert_keys"
local endpoint_key = "shell"
@ -96,17 +97,22 @@ function shell.runScript(alerts, settings)
-- Running script with the alert (json) as input (stdin)
sys_utils.execShellCmd(cmd, json.encode(alert))
-- Storing an alert-notice in regard of the shell script execution
-- for security reasons
local entity_info = alerts_api.systemEntity(ntop.getInfo().product)
local type_info = alert_consts.alert_types.alert_shell_script_executed.new(
exec_script,
alert_consts.alertTypeLabel(alert["alert_id"], true)
)
type_info:set_score_notice()
if (alert.alert_id ~= other_alert_keys.alert_shell_script_executed) then
-- Trigger alert (exclude those for the shell script execution itself to avoid loops)
type_info:store(entity_info)
-- Storing an alert-notice in regard of the shell script execution
-- for security reasons
local entity_info = alerts_api.systemEntity(ntop.getInfo().product)
local type_info = alert_consts.alert_types.alert_shell_script_executed.new(
exec_script,
alert_consts.alertTypeLabel(alert["alert_id"], true)
)
type_info:set_score_notice()
type_info:store(entity_info)
end
end -- for
return true