mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Remove shell script options (alert is not provided as stdin)
This commit is contained in:
parent
129749211e
commit
aaf44b3edd
2 changed files with 8 additions and 59 deletions
|
|
@ -23,7 +23,7 @@ local shell = {
|
|||
template_name = "shell_endpoint.template"
|
||||
},
|
||||
recipient_params = {
|
||||
{ param_name = "shell_options" },
|
||||
{},
|
||||
},
|
||||
recipient_template = {
|
||||
plugin_key = endpoint_key,
|
||||
|
|
@ -48,7 +48,6 @@ end
|
|||
local function recipient2sendMessageSettings(recipient)
|
||||
local settings = {
|
||||
path = recipient.endpoint_conf.shell_script,
|
||||
options = recipient.recipient_params.shell_options,
|
||||
}
|
||||
|
||||
return settings
|
||||
|
|
@ -66,51 +65,6 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
function runScriptWithArgs(cmd, myalert)
|
||||
local use_args = false
|
||||
|
||||
alert = myalert -- Not sure why we need a non-local variable
|
||||
|
||||
if(do_debug) then
|
||||
-- tprint(myalert)
|
||||
tprint("[Before] "..cmd)
|
||||
end
|
||||
|
||||
-- Check if the user configured arguments to be mapped to alert fields
|
||||
-- Search all alert.* strings
|
||||
for word in string.gmatch(cmd, 'alert.[^,%s]+') do
|
||||
local arg_val = ""
|
||||
use_args = true
|
||||
|
||||
local field_name = string.gsub(word, 'alert%.', '')
|
||||
if field_name then
|
||||
local field_value = myalert[field_name]
|
||||
if field_value then
|
||||
arg_val = field_value
|
||||
end
|
||||
end
|
||||
|
||||
cmd = cmd:gsub(word, '"'..arg_val..'"')
|
||||
end
|
||||
|
||||
-- Mask output
|
||||
local full_cmd = cmd.." > /dev/null"
|
||||
|
||||
if use_args then
|
||||
-- Running script with expanded args
|
||||
os.execute(full_cmd)
|
||||
else
|
||||
-- Running script with the alert (json) as input (stdin)
|
||||
sys_utils.execShellCmd(full_cmd, json.encode(myalert))
|
||||
end
|
||||
|
||||
if(do_debug) then tprint("[After] "..cmd) end
|
||||
|
||||
return(cmd)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function shell.runScript(alerts, settings)
|
||||
local where = { "/usr/share/ntopng/scripts/shell/", dirs.installdir.."/scripts/shell/" }
|
||||
local fullpath = nil
|
||||
|
|
@ -134,9 +88,13 @@ function shell.runScript(alerts, settings)
|
|||
|
||||
for key, alert in ipairs(alerts) do
|
||||
-- Executing the script
|
||||
local exec_script = fullpath .. " " .. settings.options
|
||||
local exec_script = fullpath
|
||||
|
||||
exec_script = runScriptWithArgs(exec_script, alert)
|
||||
-- Mask output
|
||||
local cmd = exec_script .. " > /dev/null"
|
||||
|
||||
-- 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue