mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-28 15:47:25 +00:00
Set up outputs listed in configuration object
This commit is contained in:
parent
179e5519ce
commit
b2698f9d20
@ -5,12 +5,12 @@ rules_file: /etc/digwatch.conf
|
||||
priority_level: warning
|
||||
|
||||
syslog_output:
|
||||
enabled: true
|
||||
enabled: false
|
||||
|
||||
file_output:
|
||||
enabled: true
|
||||
enabled: false
|
||||
filename: "bla.bla"
|
||||
|
||||
stdout_output:
|
||||
enabled: false
|
||||
enabled: true
|
||||
|
||||
|
@ -156,24 +156,38 @@ void add_lua_path(lua_State *ls, string path)
|
||||
lua_pop(ls, 1);
|
||||
}
|
||||
|
||||
void add_output(lua_State *ls, string output_name)
|
||||
void add_output(lua_State *ls, output_config oc)
|
||||
{
|
||||
|
||||
uint8_t nargs = 1;
|
||||
lua_getglobal(ls, lua_add_output.c_str());
|
||||
|
||||
if(lua_isfunction(ls, -1))
|
||||
if(!lua_isfunction(ls, -1))
|
||||
{
|
||||
lua_pushstring(ls, output_name.c_str());
|
||||
if(lua_pcall(ls, 1, 0, 0) != 0)
|
||||
throw sinsp_exception("No function " + lua_add_output + " found. ");
|
||||
}
|
||||
lua_pushstring(ls, oc.name.c_str());
|
||||
|
||||
// If we have options, build up a lua table containing them
|
||||
if (oc.options.size())
|
||||
{
|
||||
nargs = 2;
|
||||
lua_createtable(ls, 0, oc.options.size());
|
||||
|
||||
for (auto it = oc.options.cbegin(); it != oc.options.cend(); ++it)
|
||||
{
|
||||
lua_pushstring(ls, (*it).second.c_str());
|
||||
lua_setfield(ls, -2, (*it).first.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if(lua_pcall(ls, nargs, 0, 0) != 0)
|
||||
{
|
||||
const char* lerr = lua_tostring(ls, -1);
|
||||
string err = "Error invoking add_output: " + string(lerr);
|
||||
throw sinsp_exception(err);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw sinsp_exception("No function " + lua_add_output + " found. ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -363,7 +377,10 @@ int digwatch_init(int argc, char **argv)
|
||||
|
||||
inspector->set_hostname_and_port_resolution_mode(false);
|
||||
|
||||
add_output(ls, output_name);
|
||||
for(std::vector<output_config>::iterator it = config.m_outputs.begin(); it != config.m_outputs.end(); ++it)
|
||||
{
|
||||
add_output(ls, *it);
|
||||
}
|
||||
|
||||
if (infile.size())
|
||||
{
|
||||
|
@ -165,7 +165,7 @@ outputs = {}
|
||||
|
||||
function add_output(output_name, config)
|
||||
if not (type(output_functions[output_name]) == 'function') then
|
||||
error("rule_loader.add_output(): invalid output_name: ", output_name)
|
||||
error("rule_loader.add_output(): invalid output_name: "..output_name)
|
||||
end
|
||||
|
||||
table.insert(outputs, {output = output_functions[output_name], config=config})
|
||||
|
Loading…
Reference in New Issue
Block a user