Skip to content

Commit

Permalink
feat: several requested changes, added modules to agent's main
Browse files Browse the repository at this point in the history
  • Loading branch information
ncvicchi committed Aug 27, 2024
1 parent 2393f46 commit cfa7740
Show file tree
Hide file tree
Showing 23 changed files with 37 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ venv
# Auto generated build files
src/**/build/*

src/external/libdb/build_unix/
src/external/libdb/build_unix/*
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ add_subdirectory(common)
add_subdirectory(modules)

add_executable(wazuh-agent agent/src/main.cpp)
target_link_libraries(wazuh-agent Agent)
target_link_libraries(wazuh-agent Agent modules)

if(BUILD_TESTS)
enable_testing()
Expand Down
3 changes: 3 additions & 0 deletions src/agent/src/agent.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <agent.hpp>
#include "../../../modules/modules.hpp"

#include <message.hpp>
#include <message_queue_utils.hpp>
Expand Down Expand Up @@ -38,5 +39,7 @@ void Agent::Run()
[this]([[maybe_unused]] const std::string& response)
{ popMessagesFromQueue(m_messageQueue, MessageType::STATELESS); }));

m_taskManager.EnqueueTask([this]() { modulesExec(); });

m_signalHandler.WaitForSignal();
}
2 changes: 1 addition & 1 deletion src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22)

project(sysinfo)

Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/include/sysInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define EXPORTED
#endif

#include "sysInfoInterface.h"
#include "sysInfoInterface.hpp"

constexpr auto KByte
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/testtool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22)

project(sysinfo_test_tool)

Expand Down
4 changes: 2 additions & 2 deletions src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22)

project(Modules)

Expand All @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)

add_subdirectory(inventory)

add_executable(modules main.cpp pool.cpp)
add_library(modules STATIC modules.cpp pool.cpp)

target_include_directories(modules PRIVATE modules)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/modules/inventory/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.24)
cmake_minimum_required(VERSION 3.22)

project(Inventory)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef INVENTORY_H
#define INVENTORY_H
#pragma once

#include <chrono>
#include <thread>
Expand All @@ -8,12 +7,12 @@
#include <memory>
#include <string>
#include <memory>
#include "sysInfoInterface.h"
#include "configuration.h"
#include "sysInfoInterface.hpp"
#include "configuration.hpp"
#include "logging_helper.h"
#include "commonDefs.h"
#include "dbsync.hpp"
#include "inventoryNormalizer.h"
#include "inventoryNormalizer.hpp"

class Inventory {
public:
Expand Down Expand Up @@ -114,6 +113,3 @@ class Inventory {
long sync_max_eps; // Maximum events per second for synchronization messages.

};

#endif // INVENTORY_H

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/
#ifndef _INVENTORY_NORMALIZER_H
#define _INVENTORY_NORMALIZER_H
#pragma once
#include <nlohmann/json.hpp>
#include <string>
#include <map>
Expand All @@ -31,6 +30,3 @@ class InvNormalizer
const std::map<std::string, nlohmann::json> m_typeExclusions;
const std::map<std::string, nlohmann::json> m_typeDictionary;
};


#endif //_INVENTORY_NORMALIZER_H
2 changes: 1 addition & 1 deletion src/modules/inventory/src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "string_op.h"
#include "pthreads_op.h"

#include "inventory.h"
#include "inventory.hpp"
#include "sysInfo.hpp"

using namespace std;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/inventory/src/inventoryImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/
#include "inventory.h"
#include "inventory.hpp"
#include <nlohmann/json.hpp>
#include <iostream>
#include "stringHelper.h"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/inventory/src/inventoryNormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <iostream>
#include <fstream>
#include <regex>
#include <inventoryNormalizer.h>
#include <inventoryNormalizer.hpp>

InvNormalizer::InvNormalizer(const std::string& configFile,
const std::string& target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/
#ifndef _INV_NORMALIZER_TEST_H
#define _INV_NORMALIZER_TEST_H
#pragma once
#include "gtest/gtest.h"
#include "gmock/gmock.h"

Expand All @@ -23,5 +22,3 @@ class InvNormalizerTest : public ::testing::Test
void SetUp() override;
void TearDown() override;
};

#endif //_INV_NORMALIZER_TEST_H
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Foundation.
*/
#include <cstdio>
#include "inventoryImp_test.h"
#include "inventoryImp_test.hpp"
#include "inventory.hpp"

constexpr auto INVENTORY_DB_PATH {"TEMP.dbINVENTORY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* License (version 2) as published by the FSF - Free Software
* Foundation.
*/
#ifndef _INVENTORY_IMP_TEST_H
#define _INVENTORY_IMP_TEST_H
#pragma once
#include "gtest/gtest.h"
#include "gmock/gmock.h"

Expand All @@ -23,5 +22,3 @@ class InventoryImpTest : public ::testing::Test
void SetUp() override;
void TearDown() override;
};

#endif //_INVENTORY_IMP_TEST_H
7 changes: 2 additions & 5 deletions src/modules/moduleWrapper.h → src/modules/moduleWrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#ifndef MODULE_WRAPPER_H
#define MODULE_WRAPPER_H
#pragma once

#include <functional>
#include <string>
#include "configuration.h"
#include "configuration.hpp"

using namespace std;

Expand All @@ -14,5 +13,3 @@ struct ModuleWrapper {
function<string(const string&)> command;
function<string()> name;
};

#endif // MODULE_WRAPPER_H
10 changes: 5 additions & 5 deletions src/modules/main.cpp → src/modules/modules.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include <iostream>
#include <csignal>
#include "pool.h"
#include "configuration.h"
#include "pool.hpp"
#include "configuration.hpp"

using namespace std;

Pool* global_pool = nullptr;
static Pool* global_pool = nullptr;

void signalHandler(int signal) {
static void signalHandler(int signal) {

switch (signal) {
case SIGHUP:
Expand All @@ -23,7 +23,7 @@ void signalHandler(int signal) {
}
}

int main() {
int modulesExec(){
Pool pool;
global_pool = &pool;
Configuration config;
Expand Down
3 changes: 3 additions & 0 deletions src/modules/modules.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

int modulesExec();
4 changes: 2 additions & 2 deletions src/modules/pool.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <iostream>
#include "inventory.h"
#include "pool.h"
#include "inventory.hpp"
#include "pool.hpp"

Pool::Pool() {
// addModule(make_shared<LogCollector>());
Expand Down
9 changes: 3 additions & 6 deletions src/modules/pool.h → src/modules/pool.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#ifndef POOL_H
#define POOL_H
#pragma once

#include <map>
#include <memory>
#include <string>
#include <thread>
#include "configuration.h"
#include "moduleWrapper.h"
#include "configuration.hpp"
#include "moduleWrapper.hpp"

using namespace std;

Expand Down Expand Up @@ -35,5 +34,3 @@ class Pool {
map<string, shared_ptr<ModuleWrapper>> modules;
vector<thread> threads;
};

#endif // POOL_H

0 comments on commit cfa7740

Please sign in to comment.