Open cborla opened 1 week ago
It has been identified the code in the wazuh/wazuh
repository.
Folder | File(s) | Keep | Notes |
---|---|---|---|
architecture | syscollector | ✅ | |
src/config | wmodules-syscollector.c | ❌ | Config will be migrated to TOML |
src/headers & src/shared | agent_messages_adapter.h/agent_messages_adapter.c | ✅ | |
logging_helper.h/logging_helper.c | ✅ | ||
sym_load.h/sym_load.c | 🟡 | Remove unused functions | |
src/shared_modules | utils/hashHelper.h | ✅ | |
utils/abstractLocking.hpp | ✅ | dbsync | |
utils/builder.hpp | ✅ | dbsync | |
utils/cjsonSmartDeleter.hpp | ✅ | dbsync | |
utils/customDeleter.hpp | ✅ | dbsync | |
utils/mapWrapperSafe.h | ✅ | dbsync | |
utils/pipelineNodesImp.h | ✅ | dbsync | |
utils/pipelinePattern.h | ✅ | dbsync | |
dbsync | ✅ | ||
src/wazuh_modules | syscollector | ✅ | The full directory is kept |
wm_syscollector.h/wm_syscollector.c | ✅ | ||
tests/integration | test_syscollector | ✅ |
Once this code has been migrated to the wazuh/wazuh-agent
repository, it must be refactored to fit the new repository structure, as follows:
wazuh-agent/
├── src/
│ ├── CMakeLists.txt
│ ├── vcpkg.json
│ ├── modules/
│ │ ├── inventory/
│ │ │ ├── CMakeLists.txt
│ │ │ ├── include/
│ │ │ │ ├── inventory.hpp
│ │ │ │ └── ...
│ │ │ ├── src/
│ │ │ │ ├── inventory.cpp
│ │ │ │ └── ...
│ │ │ └── tests/
│ │ │ ├── CMakeLists.txt
│ │ │ └── test_inventory.cpp
│ │ └── [additional modules...]
│ ├── common/
│ │ ├── dbsync/
│ │ └── [additional modules...]
│ └── build/
│ └── [build output...]
├── etc/
│ ├── config/
│ ├── selinux/
│ └── ruleset/
│ ├── sca/
│ └── rootcheck/
├── packages/
│ └── installers/
│ ├── unix/ (former init folder, including upgrade.sh and install.sh)
│ └── win32/
└── bump-version.sh
As a prerequisite for the Inventory or any other module implementation, the wmodule class needs to be implemented.
Analysis of different approaches is being performed.
A simple interface implementation as:
could be enough, leaving the implementation of every method specifically to each module.
Although this is a flexible approach, maintenance of every module will be required in such a scenario.
Another approach could be by implementing all module's behaviour in the parent class:
A mixed solution can also be implemented, where default behaviour is implemented in the parent class, but provides the means to extend every method behaviour in case a module needs it:
Although the extension is applied after the generic behaviour in this example, both pre & post extensions could be implemented, if necessary.
Although the 1st approach is much simpler at first, it delegates its implementation (and therefore its complexity) to every module that will be implemented. This gives a great deal of flexibility to a module implementation but effectively increases maintenance efforts.
The second approach improves maintenance effort requirements but at the expense of dramatically reducing flexibility. It removes all implementations from modules, not allowing the implementation of specific behaviours.
The third approach tries to accommodate both 1st and 2nd implementation limitations by allowing the extension of generic behaviours with specific behaviours:
Feature | Approach 1 | Approach 2 | Approach 3 |
---|---|---|---|
Simplicity | High | Medium | Medium |
Flexibility | High | Low | High |
Maintenance | Harder | Medium | Lower |
Manageable | Limited | Simple | Simple |
Based on this, I have created the base class Modules
and a first iteration of the Inventory
module, adapting the example to the structure of the new repository and using wrapper and concepts.
Output:
$ ./Modules
[Inventory] is running
[Inventory] query: Hello World!
[Inventory] stopped
Branch: https://github.com/wazuh/wazuh-agent/compare/master...17-migrate-syscollector-module-to-new-agent
Description
Migrate Syscollector and DBsync code from the
wazuh/wazuh
repository to thewazuh/wazuh-agent
repository.Tasks
wazuh/wazuh
repository.wazuh/wazuh-agent
repository.Implementation Constraints
Dependencies
Migration spike: https://github.com/wazuh/wazuh/issues/24037