Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to write output to a program #105

Merged
merged 1 commit into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions falco.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ file_output:
stdout_output:
enabled: true

program_output:
enabled: false
program: mail -s "Falco Notification" [email protected]
14 changes: 14 additions & 0 deletions userspace/falco/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ void falco_configuration::init(string conf_filename, std::list<std::string> &cmd
m_outputs.push_back(syslog_output);
}

output_config program_output;
program_output.name = "program";
if (m_config->get_scalar<bool>("program_output", "enabled", false))
{
string program;
program = m_config->get_scalar<string>("program_output", "program", "");
if (program == string(""))
{
throw sinsp_exception("Error reading config file (" + m_config_file + "): program output enabled but no program in configuration block");
}
program_output.options["program"] = program;
m_outputs.push_back(program_output);
}

if (m_outputs.size() == 0)
{
throw sinsp_exception("Error reading config file (" + m_config_file + "): No outputs configured. Please configure at least one output file output enabled but no filename in configuration block");
Expand Down
18 changes: 17 additions & 1 deletion userspace/falco/lua/output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function mod.file_validate(options)
end

function mod.file(evt, rule, level, format, options)
format = "%evt.time: "..levels[level+1].." "..format
format = "*%evt.time: "..levels[level+1].." "..format
formatter = falco.formatter(format)
msg = falco.format_event(evt, rule, levels[level+1], formatter)

Expand All @@ -43,6 +43,22 @@ function mod.syslog(evt, rule, level, format)
falco.syslog(level, msg)
end

function mod.program(evt, rule, level, format, options)

format = "*%evt.time: "..levels[level+1].." "..format
formatter = falco.formatter(format)
msg = falco.format_event(evt, rule, levels[level+1], formatter)

-- XXX Ideally we'd check that the program ran
-- successfully. However, the luajit we're using returns true even
-- when the shell can't run the program.

file = io.popen(options.program, "w")

file:write(msg, "\n")
file:close()
end

function mod.event(event, rule, level, format)
for index,o in ipairs(outputs) do
o.output(event, rule, level, format, o.config)
Expand Down