mirror of
https://github.com/falcosecurity/falco.git
synced 2025-08-01 22:47:46 +00:00
Look up priorities using a table
This is faster than iteration + string case changes. Signed-off-by: Mark Stemm <mark.stemm@gmail.com>
This commit is contained in:
parent
0e4f2ec17c
commit
52a44c171c
@ -59,17 +59,13 @@ function map(f, arr)
|
|||||||
return res
|
return res
|
||||||
end
|
end
|
||||||
|
|
||||||
priorities = {"Emergency", "Alert", "Critical", "Error", "Warning", "Notice", "Informational", "Debug"}
|
|
||||||
|
|
||||||
local function priority_num_for(s)
|
-- Permissive for case and for common abbreviations.
|
||||||
s = string.lower(s)
|
priorities = {
|
||||||
for i,v in ipairs(priorities) do
|
Emergency=0, Alert=1, Critical=2, Error=3, Warning=4, Notice=5, Informational=5, Debug=7,
|
||||||
if (string.find(string.lower(v), "^"..s)) then
|
EMERGENCY=0, ALERT=1, CRITICAL=2, ERROR=3, WARNING=4, NOTICE=5, INFORMATIONAL=5, DEBUG=7,
|
||||||
return i - 1 -- (numbers start at 0, lua indices start at 1)
|
INFO=5
|
||||||
end
|
}
|
||||||
end
|
|
||||||
error("Invalid priority level: "..s)
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Take a filter AST and set it up in the libsinsp runtime, using the filter API.
|
Take a filter AST and set it up in the libsinsp runtime, using the filter API.
|
||||||
@ -336,7 +332,11 @@ function load_rules(sinsp_lua_parser,
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Convert the priority-as-string to a priority-as-number now
|
-- Convert the priority-as-string to a priority-as-number now
|
||||||
v['priority_num'] = priority_num_for(v['priority'])
|
v['priority_num'] = priorities[v['priority']]
|
||||||
|
|
||||||
|
if v['priority_num'] == nil then
|
||||||
|
error("Invalid priority level: "..v['priority'])
|
||||||
|
end
|
||||||
|
|
||||||
if v['priority_num'] <= min_priority then
|
if v['priority_num'] <= min_priority then
|
||||||
-- Note that we can overwrite rules, but the rules are still
|
-- Note that we can overwrite rules, but the rules are still
|
||||||
|
Loading…
Reference in New Issue
Block a user