Skip to content

Commit

Permalink
Merge pull request #203 from wazuh/enhancement/193-improve-inventory
Browse files Browse the repository at this point in the history
Improve inventory implementation
  • Loading branch information
cborla authored Oct 7, 2024
2 parents d354a47 + f9cda38 commit 7531019
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ This project uses the following third-party software:
| [Boost Asio](https://www.boost.org/doc/libs/release/doc/html/boost_asio.html) | Cross-platform C++ library for network programming | Boost Software License 1.0 | 1.85.0 |
| [Boost Beast](https://www.boost.org/doc/libs/release/libs/beast/) | Library built on Boost Asio for HTTP and WebSocket communication | Boost Software License 1.0 | 1.85.0 |
| [Boost Uuid](https://www.boost.org/doc/libs/release/libs/uuid/) | Provides support for universally unique identifiers (UUIDs) | Boost Software License 1.0 | 1.85.0 |
| [cjson](https://github.com/DaveGamble/cJSON) | Ultralightweight JSON parser in ANSI Clone | MIT licensed | 1.7.17 |
| [curl](https://curl.se/) | A library for transferring data with URLs | curl AND ISC AND BSD-3-Clause | 8.5.0 |
| [fmt](https://fmt.dev/) | A formatting library for C++ | MIT License | 10.2.1 |
| [gtest](https://github.com/google/googletest) | Google's C++ testing framework | BSD-3-Clause | 1.15.2 |
| [jwt-cpp](https://github.com/Thalhammer/jwt-cpp) | C++ library for handling JSON Web Tokens (JWT) | MIT License | 0.7.0 |
| [libarchive](https://www.libarchive.org) | Library for reading and writing streaming archives | 3-Clause New BSD License | 3.7.5 |
| [libdb](https://github.com/yasuhirokimura/db18) | Database management library | AGPL-3.0 | 18.1.40 |
| [libplist](https://libimobiledevice.org/) | A library to handle Apple Property List format in binary or XML | LGPL-2.1-or-later | 2.2.0 |
| [libpopt](https://github.com/rpm-software-management/popt) | Library for parsing command line parameters | MIT licensed | 1.16 |
| [librpm](https://github.com/rpm-software-management/rpm) | RPM package manager | GPL-2.0 | 4.18.2 |
| [lua](https://www.lua.org) | A powerful, fast, lightweight, embeddable scripting language | MIT licensed | 5.4.1 |
| [nlohmann-json](https://github.com/nlohmann/json) | JSON parsing and serialization library for C++ | MIT License | 3.11.3 |
| [OpenSSL](https://www.openssl.org/) | Toolkit for SSL/TLS protocols | Apache 2.0 and OpenSSL License | 3.3.2 |
| [procps](https://github.com/warmchang/procps) | Utilities for monitoring system processes and resources | GPL-2.0 | 3.3.0 |
| [spdlog](https://github.com/gabime/spdlog) | Fast C++ logging library | MIT License | 1.14.1 |
| [sqlite3](https://sqlite.org/) | SQLite is a software library that implements a self-contained serverless, zero-configuration, transactional SQL database engine | Public Domain (no restrictions) | 3.45.0 |
| [SQLiteCpp](https://github.com/SRombauts/SQLiteCpp) | C++ wrapper around the SQLite database library | MIT License | 3.3.2 |
| [toml11](https://github.com/ToruNiina/toml11) | C++11 TOML parser library | MIT License | 4.0.0 |
| [zlib](https://www.zlib.net/) | A compression library | Zlib | 1.3.1 |
## License
Expand Down
6 changes: 5 additions & 1 deletion src/common/data_provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

find_package(cJSON CONFIG REQUIRED)
find_package(LibArchive REQUIRED)
Expand Down
6 changes: 2 additions & 4 deletions src/common/data_provider/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ else()
string(APPEND CMAKE_EXE_LINKER_FLAGS " -lgcov ")
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
add_subdirectory(sysInfo)
add_subdirectory(sysInfoPorts)
endif()
add_subdirectory(sysInfo)
add_subdirectory(sysInfoPorts)
15 changes: 11 additions & 4 deletions src/common/data_provider/tests/sysInfo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@ file(GLOB sysinfo_UNIT_TEST_SRC
"*.cpp")

file(GLOB SYSINFO_SRC
"${CMAKE_SOURCE_DIR}/src/sysInfo.cpp"
"${CMAKE_SOURCE_DIR}/src/osinfo/sysOsParsers.cpp")
"${CMAKE_CURRENT_SOURCE_DIR}/../../src/sysInfo.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/../../src/osinfo/sysOsParsers.cpp")

add_executable(sysinfo_unit_test
${sysinfo_UNIT_TEST_SRC}
${SYSINFO_SRC})
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
target_link_libraries(sysinfo_unit_test PRIVATE
sysinfo
GTest::gtest
GTest::gmock
GTest::gtest_main
GTest::gmock_main
pthread
unofficial::sqlite3::sqlite3
cjson
utils
-static-libgcc -static-libstdc++
)
else()
target_link_libraries(sysinfo_unit_test PRIVATE
sysinfo
GTest::gtest
GTest::gmock
GTest::gtest_main
GTest::gmock_main
pthread
unofficial::sqlite3::sqlite3
cjson
utils
dl
)
endif(CMAKE_SYSTEM_NAME STREQUAL "Windows")

Expand Down
6 changes: 5 additions & 1 deletion src/common/dbsync/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ endif()

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
else()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
Expand Down
26 changes: 16 additions & 10 deletions src/modules/inventory/src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
#include <inventory.hpp>
#include <sysInfo.hpp>


constexpr const char* INV_LOGTAG = "modules:inventory"; // Tag for log messages

void Inventory::Start() {

if (!m_enabled) {
Expand Down Expand Up @@ -61,7 +58,7 @@ void Inventory::Stop() {

// NOLINTNEXTLINE(performance-unnecessary-value-param)
Co_CommandExecutionResult Inventory::ExecuteCommand(const std::string query) {
LogInfo("Query: ",query);
LogInfo("Query: {}", query);
co_return module_command::CommandExecutionResult{module_command::Status::SUCCESS, "OK"};
}

Expand All @@ -72,13 +69,22 @@ void Inventory::SetMessageQueue(const std::shared_ptr<IMultiTypeQueue> queue) {
void Inventory::SendDeltaEvent(const std::string& data) {

const auto jsonData = nlohmann::json::parse(data);
const Message message{ MessageType::STATELESS, jsonData, Name() };
const Message statelessMessage{ MessageType::STATELESS, jsonData, Name() };
const Message statefulMessage{ MessageType::STATEFUL, jsonData, Name() };

if(!m_messageQueue->push(statelessMessage)) {
LogWarn("Stateless event can't be pushed into the message queue: {}", data);
}
else {
LogTrace("Stateless event queued: {}", data);

}

if(!m_messageQueue->push(message)) {
LogWarn("Delta event can't be pushed into the message queue: ", data);
if(!m_messageQueue->push(statefulMessage)) {
LogWarn("Stateful event can't be pushed into the message queue: {}", data);
}
else {
LogTrace("Delta sent: ", data);
LogTrace("Stateful event queued: {}", data);

}
}
Expand All @@ -89,7 +95,7 @@ void Inventory::ShowConfig()
if (configJson) {
char * configString = cJSON_PrintUnformatted(configJson);
if (configString) {
LogTrace("{}",configString);
LogTrace("{}", configString);
cJSON_free(configString);
}
cJSON_Delete(configJson);
Expand Down Expand Up @@ -123,5 +129,5 @@ cJSON * Inventory::Dump() {

void Inventory::LogErrorInventory(const std::string& log)
{
LogError("{}",log.c_str(), INV_LOGTAG);
LogError("{}", log.c_str());
}
4 changes: 0 additions & 4 deletions src/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@
"name": "openssl",
"version>=": "3.3.2"
},
{
"name": "pcre2",
"version>=": "10.42"
},
{
"name": "procps",
"version>=": "3.3.0",
Expand Down

0 comments on commit 7531019

Please sign in to comment.