mirror of
https://github.com/falcosecurity/falco.git
synced 2025-07-16 15:51:55 +00:00
cleanup(metrics): use map for config and rules filenames sha256 tracking
Co-authored-by: Federico Di Pierro <nierro92@gmail.com> Signed-off-by: Melissa Kilby <melissa.kilby.oss@gmail.com>
This commit is contained in:
parent
91b58c43f1
commit
60e6798f9b
@ -85,7 +85,7 @@ falco::app::run_result falco::app::actions::load_rules_files(falco::app::state&
|
||||
falco_logger::log(falco_logger::level::WARNING,res->as_string(true, rc) + "\n");
|
||||
}
|
||||
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
|
||||
s.config->m_loaded_rules_filenames_sha256sum.push_back(falco::utils::calculate_file_sha256sum(filename));
|
||||
s.config->m_loaded_rules_filenames_sha256sum.insert({filename, falco::utils::calculate_file_sha256sum(filename)});
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ void falco_configuration::merge_configs_files(const std::string& config_name, st
|
||||
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
|
||||
for(auto &filename : m_loaded_configs_filenames)
|
||||
{
|
||||
m_loaded_configs_filenames_sha256sum.push_back(falco::utils::calculate_file_sha256sum(filename));
|
||||
m_loaded_configs_filenames_sha256sum.insert({filename, falco::utils::calculate_file_sha256sum(filename)});
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ public:
|
||||
|
||||
// Config list as passed by the user. Filenames.
|
||||
std::list<std::string> m_loaded_configs_filenames;
|
||||
// sha256 of the loaded configs files
|
||||
std::list<std::string> m_loaded_configs_filenames_sha256sum;
|
||||
// Map with filenames and their sha256 of the loaded configs files
|
||||
std::unordered_map<std::string, std::string> m_loaded_configs_filenames_sha256sum;
|
||||
// Config list as passed by the user. Folders.
|
||||
std::list<std::string> m_loaded_configs_folders;
|
||||
|
||||
@ -114,8 +114,8 @@ public:
|
||||
std::list<std::string> m_rules_filenames;
|
||||
// Actually loaded rules, with folders inspected
|
||||
std::list<std::string> m_loaded_rules_filenames;
|
||||
// sha256 of the loaded rules files
|
||||
std::list<std::string> m_loaded_rules_filenames_sha256sum;
|
||||
// Map with filenames and their sha256 of the loaded rules files
|
||||
std::unordered_map<std::string, std::string> m_loaded_rules_filenames_sha256sum;
|
||||
// List of loaded rule folders
|
||||
std::list<std::string> m_loaded_rules_folders;
|
||||
bool m_json_output;
|
||||
|
@ -85,28 +85,20 @@ std::string falco_metrics::to_text(const falco::app::state& state)
|
||||
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus("hostname", "falcosecurity", "evt", {{"hostname", machine_info->hostname}});
|
||||
|
||||
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
|
||||
auto it_filename = state.config.get()->m_loaded_rules_filenames.begin();
|
||||
auto it_sha256 = state.config.get()->m_loaded_rules_filenames_sha256sum.begin();
|
||||
while (it_filename != state.config.get()->m_loaded_rules_filenames.end() && it_sha256 != state.config.get()->m_loaded_rules_filenames_sha256sum.end())
|
||||
for (const auto& item : state.config.get()->m_loaded_rules_filenames_sha256sum)
|
||||
{
|
||||
fs::path fs_path = *it_filename;
|
||||
fs::path fs_path = item.first;
|
||||
std::string metric_name_file_sha256 = fs_path.filename().stem();
|
||||
metric_name_file_sha256 = "sha256_rule_file_" + metric_name_file_sha256;
|
||||
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus(metric_name_file_sha256, "falcosecurity", "falco", {{metric_name_file_sha256, *it_sha256}});
|
||||
++it_filename;
|
||||
++it_sha256;
|
||||
metric_name_file_sha256 = "falco.sha256_rule_file." + metric_name_file_sha256;
|
||||
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus(metric_name_file_sha256, "falcosecurity", "falco", {{metric_name_file_sha256, item.second}});
|
||||
}
|
||||
|
||||
it_filename = state.config.get()->m_loaded_configs_filenames.begin();
|
||||
it_sha256 = state.config.get()->m_loaded_configs_filenames_sha256sum.begin();
|
||||
while (it_filename != state.config.get()->m_loaded_configs_filenames.end() && it_sha256 != state.config.get()->m_loaded_configs_filenames_sha256sum.end())
|
||||
for (const auto& item : state.config.get()->m_loaded_configs_filenames_sha256sum)
|
||||
{
|
||||
fs::path fs_path = *it_filename;
|
||||
fs::path fs_path = item.first;
|
||||
std::string metric_name_file_sha256 = fs_path.filename().stem();
|
||||
metric_name_file_sha256 = "sha256_config_file_" + metric_name_file_sha256;
|
||||
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus(metric_name_file_sha256, "falcosecurity", "falco", {{metric_name_file_sha256, *it_sha256}});
|
||||
++it_filename;
|
||||
++it_sha256;
|
||||
metric_name_file_sha256 = "falco.sha256_config_file." + metric_name_file_sha256;
|
||||
prometheus_text += prometheus_metrics_converter.convert_metric_to_text_prometheus(metric_name_file_sha256, "falcosecurity", "falco", {{metric_name_file_sha256, item.second}});
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -331,28 +331,20 @@ void stats_writer::collector::get_metrics_output_fields_wrapper(
|
||||
output_fields["falco.outputs_queue_num_drops"] = m_writer->m_outputs->get_outputs_queue_num_drops();
|
||||
|
||||
#if defined(__linux__) and !defined(MINIMAL_BUILD) and !defined(__EMSCRIPTEN__)
|
||||
auto it_filename = m_writer->m_config->m_loaded_rules_filenames.begin();
|
||||
auto it_sha256 = m_writer->m_config->m_loaded_rules_filenames_sha256sum.begin();
|
||||
while (it_filename != m_writer->m_config->m_loaded_rules_filenames.end() && it_sha256 != m_writer->m_config->m_loaded_rules_filenames_sha256sum.end())
|
||||
for (const auto& item : m_writer->m_config->m_loaded_rules_filenames_sha256sum)
|
||||
{
|
||||
fs::path fs_path = *it_filename;
|
||||
fs::path fs_path = item.first;
|
||||
std::string metric_name_file_sha256 = fs_path.filename().stem();
|
||||
metric_name_file_sha256 = "falco.sha256_rule_file." + metric_name_file_sha256;
|
||||
output_fields[metric_name_file_sha256] = *it_sha256;
|
||||
++it_filename;
|
||||
++it_sha256;
|
||||
output_fields[metric_name_file_sha256] = item.second;
|
||||
}
|
||||
|
||||
it_filename = m_writer->m_config->m_loaded_configs_filenames.begin();
|
||||
it_sha256 = m_writer->m_config->m_loaded_configs_filenames_sha256sum.begin();
|
||||
while (it_filename != m_writer->m_config->m_loaded_configs_filenames.end() && it_sha256 != m_writer->m_config->m_loaded_configs_filenames_sha256sum.end())
|
||||
for (const auto& item : m_writer->m_config->m_loaded_configs_filenames_sha256sum)
|
||||
{
|
||||
fs::path fs_path = *it_filename;
|
||||
fs::path fs_path = item.first;
|
||||
std::string metric_name_file_sha256 = fs_path.filename().stem();
|
||||
metric_name_file_sha256 = "falco.sha256_config_file." + metric_name_file_sha256;
|
||||
output_fields[metric_name_file_sha256] = *it_sha256;
|
||||
++it_filename;
|
||||
++it_sha256;
|
||||
output_fields[metric_name_file_sha256] = item.second;
|
||||
}
|
||||
#endif
|
||||
output_fields["evt.source"] = src;
|
||||
|
Loading…
Reference in New Issue
Block a user