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

refactor(userspace): change falco engine design to properly support multiple sources #2017

Merged
merged 10 commits into from
May 25, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor(userspace/engine): leverage falco_rule def in stats manager
Signed-off-by: Jason Dellaluce <[email protected]>
jasondellaluce committed May 24, 2022
commit 54745334d22aa4cad1253025cca578e22f77ad8b
27 changes: 8 additions & 19 deletions userspace/engine/stats_manager.cpp
Original file line number Diff line number Diff line change
@@ -38,10 +38,9 @@ void stats_manager::clear()

void stats_manager::format(
const indexed_vector<falco_rule>& rules,
string& out)
string& out) const
{
string fmt;
string name;
out = "Events detected: " + to_string(m_total) + "\n";
out += "Rule counts by severity:\n";
for (size_t i = 0; i < m_by_priority.size(); i++)
@@ -66,27 +65,17 @@ void stats_manager::format(
}
}

void stats_manager::on_event(
const indexed_vector<falco_rule>& rules,
uint32_t rule_id)
void stats_manager::on_event(const falco_rule& rule)
{
auto *rule = rules.at(rule_id);
if (!rule)
if (m_by_rule_id.size() <= rule.id)
{
throw falco_exception(
"on_event(): event with invalid rule_id: " + rule_id);
m_by_rule_id.resize(rule.id + 1, (uint64_t) 0);
}
if (m_by_rule_id.size() <= rule_id)
if (m_by_priority.size() <= (size_t) rule.priority)
{
m_by_rule_id.resize(rule_id + 1);
m_by_rule_id[rule_id] = 0;
}
if (m_by_priority.size() <= (size_t) rule->priority)
{
m_by_priority.resize((size_t) rule->priority + 1);
m_by_priority[(size_t) rule->priority] = 0;
m_by_priority.resize((size_t) rule.priority + 1, (uint64_t) 0);
}
m_total++;
m_by_rule_id[rule_id]++;
m_by_priority[(size_t) rule->priority]++;
m_by_rule_id[rule.id]++;
m_by_priority[(size_t) rule.priority]++;
}
8 changes: 3 additions & 5 deletions userspace/engine/stats_manager.h
Original file line number Diff line number Diff line change
@@ -36,18 +36,16 @@ class stats_manager
virtual void clear();

/*!
\brief Callback for when a rule with a given index matches an event
\brief Callback for when a given rule matches an event
*/
virtual void on_event(
const indexed_vector<falco_rule>& rules,
uint32_t index);
virtual void on_event(const falco_rule& rule);

/*!
\brief Formats the internal statistics into the out string
*/
virtual void format(
const indexed_vector<falco_rule>& rules,
std::string& out);
std::string& out) const;

private:
uint64_t m_total;