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

Critical Error at Agent Startup Due to Missing retry_interval_secs Key in Default Configuration #285

Closed
Tracked by #241
vikman90 opened this issue Nov 11, 2024 · 2 comments · Fixed by #304
Closed
Tracked by #241
Assignees
Labels
level/task Task issue module/agent mvp Minimum Viable Product refinement type/bug Bug issue

Comments

@vikman90
Copy link
Member

vikman90 commented Nov 11, 2024

Parent Issue: #241

Description

When starting the Wazuh Agent with the default configuration file (etc/config/wazuh-agent.yml), the following critical error is encountered:

[2024-11-11 10:14:06.941] [wazuh-agent] [critical] [CRITICAL] [main.cpp:67] [main] An error occurred: Key not found: retry_interval_secs.

The agent should be able to operate with its default configuration out of the box. Furthermore, if certain options are not specified in the configuration file, the agent should be able to apply default values instead of failing with an error.

Expected Behavior

  • The agent should start successfully using the default configuration without requiring additional keys.
  • Missing keys in the configuration file, such as retry_interval_secs, should be handled by applying predefined default values.

Steps to Reproduce

Start the Wazuh Agent with the default etc/config/wazuh-agent.yml configuration:

./wazuh-agent --config-file ../etc/config/wazuh-agent.yml --run

Proposed Solution

  1. Implement a mechanism for handling missing configuration keys by applying default values.
  2. Ensure that the retry_interval_secs key (and any other essential keys) have sensible defaults within the agent's codebase to prevent startup errors.
@vikman90 vikman90 added level/task Task issue type/bug Bug issue mvp Minimum Viable Product refinement labels Nov 11, 2024
@wazuhci wazuhci moved this to Backlog in Release 5.0.0 Nov 11, 2024
@wazuhci wazuhci moved this from Backlog to In progress in Release 5.0.0 Nov 11, 2024
@aritosteles
Copy link
Contributor

aritosteles commented Nov 12, 2024

Update

  • 2024/11/11:
    Getting to know yaml-cpp library. Evaluating different approaches.

  • 2024/11/12 and 13:

    • Default value parameter was added to ConfigurationParser::GetConfig()
    • GetConfig() does not throw an exception if requested key is not found, default value returned instead
    • Modified config.cmake and config.h.in to allow configuration settings to be set on build
    • Updated all occurrences of GetConfig() in main code and in tests
  • 2024/11/14:

    • Modified interface to avoid passing the default values all the way down to the configuration_parser and back. Made ConfigurationParser::GetConfig() to return an optional value. Updated all corresponding occurrencies.
    • PR up for final review.

@aritosteles
Copy link
Contributor

Summary

  • New ConfigurationParser::GetConfig() signature:
template<typename T, typename... Keys>
        std::optional<T> GetConfig(Keys... keys) const
  • Usage example:
m_enabled = configurationParser.GetConfig<bool>( "inventory",
                                 enabled").value_or(config::inventory::DEFAULT_ENABLED);

@wazuhci wazuhci moved this from In progress to Done in Release 5.0.0 Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/task Task issue module/agent mvp Minimum Viable Product refinement type/bug Bug issue
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants