mirror of
https://github.com/falcosecurity/falco.git
synced 2025-06-29 08:07:24 +00:00
Add a verbose flag.
Add a verbose flag -v which implies printing additional info. This is passed down to lua during load_rules and sets the per-module verbose value for the compiler and parser modules. Later commits will use this to print additional info when loading rules.
This commit is contained in:
parent
e66b3a817e
commit
5955c00f9c
@ -55,6 +55,7 @@ static void usage()
|
||||
" -r <rules_file> Rules file (defaults to value set in configuration file, or /etc/falco_rules.yaml).\n"
|
||||
" -L Show the name and description of all rules and exit.\n"
|
||||
" -l <rule> Show the name and description of the rule with name <rule> and exit.\n"
|
||||
" -v Verbose output.\n"
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
@ -253,6 +254,7 @@ int falco_init(int argc, char **argv)
|
||||
string pidfilename = "/var/run/falco.pid";
|
||||
bool describe_all_rules = false;
|
||||
string describe_rule = "";
|
||||
bool verbose = false;
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
@ -272,7 +274,7 @@ int falco_init(int argc, char **argv)
|
||||
// Parse the args
|
||||
//
|
||||
while((op = getopt_long(argc, argv,
|
||||
"c:ho:e:r:dp:Ll:",
|
||||
"c:ho:e:r:dp:Ll:v",
|
||||
long_options, &long_index)) != -1)
|
||||
{
|
||||
switch(op)
|
||||
@ -301,6 +303,9 @@ int falco_init(int argc, char **argv)
|
||||
case 'L':
|
||||
describe_all_rules = true;
|
||||
break;
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
case 'l':
|
||||
describe_rule = optarg;
|
||||
break;
|
||||
@ -397,7 +402,7 @@ int falco_init(int argc, char **argv)
|
||||
|
||||
|
||||
inspector->set_drop_event_flags(EF_DROP_FALCO);
|
||||
rules->load_rules(config.m_rules_filename);
|
||||
rules->load_rules(config.m_rules_filename, verbose);
|
||||
inspector->set_filter(rules->get_filter());
|
||||
falco_logger::log(LOG_INFO, "Parsed rules from file " + config.m_rules_filename + "\n");
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
local parser = require("parser")
|
||||
local compiler = {}
|
||||
|
||||
compiler.verbose = false
|
||||
|
||||
function compiler.set_verbose(verbose)
|
||||
compiler.verbose = verbose
|
||||
parser.set_verbose(verbose)
|
||||
end
|
||||
|
||||
function map(f, arr)
|
||||
local res = {}
|
||||
for i,v in ipairs(arr) do
|
||||
|
@ -11,6 +11,12 @@
|
||||
|
||||
local parser = {}
|
||||
|
||||
parser.verbose = false
|
||||
|
||||
function parser.set_verbose(verbose)
|
||||
parser.verbose = verbose
|
||||
end
|
||||
|
||||
local lpeg = require "lpeg"
|
||||
|
||||
lpeg.locale(lpeg)
|
||||
|
@ -117,7 +117,9 @@ end
|
||||
-- to a rule.
|
||||
local state = {macros={}, lists={}, filter_ast=nil, rules_by_name={}, n_rules=0, rules_by_idx={}}
|
||||
|
||||
function load_rules(filename)
|
||||
function load_rules(filename, verbose)
|
||||
|
||||
compiler.set_verbose(verbose)
|
||||
|
||||
local f = assert(io.open(filename, "r"))
|
||||
local s = f:read("*all")
|
||||
|
@ -40,7 +40,7 @@ void falco_rules::load_compiler(string lua_main_filename)
|
||||
}
|
||||
}
|
||||
|
||||
void falco_rules::load_rules(string rules_filename)
|
||||
void falco_rules::load_rules(string rules_filename, bool verbose)
|
||||
{
|
||||
lua_getglobal(m_ls, m_lua_load_rules.c_str());
|
||||
if(lua_isfunction(m_ls, -1))
|
||||
@ -82,7 +82,8 @@ void falco_rules::load_rules(string rules_filename)
|
||||
lua_setglobal(m_ls, m_lua_ignored_syscalls.c_str());
|
||||
|
||||
lua_pushstring(m_ls, rules_filename.c_str());
|
||||
if(lua_pcall(m_ls, 1, 0, 0) != 0)
|
||||
lua_pushboolean(m_ls, (verbose ? 1 : 0));
|
||||
if(lua_pcall(m_ls, 2, 0, 0) != 0)
|
||||
{
|
||||
const char* lerr = lua_tostring(m_ls, -1);
|
||||
string err = "Error loading rules:" + string(lerr);
|
||||
|
@ -8,7 +8,7 @@ class falco_rules
|
||||
public:
|
||||
falco_rules(sinsp* inspector, lua_State *ls, string lua_main_filename);
|
||||
~falco_rules();
|
||||
void load_rules(string rules_filename);
|
||||
void load_rules(string rules_filename, bool verbose);
|
||||
void describe_rule(string *rule);
|
||||
sinsp_filter* get_filter();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user