diff --git a/src/agent/communicator/src/http_client.cpp b/src/agent/communicator/src/http_client.cpp index d97b801cef..57f8ddc175 100644 --- a/src/agent/communicator/src/http_client.cpp +++ b/src/agent/communicator/src/http_client.cpp @@ -61,6 +61,7 @@ namespace http_client if (!params.Body.empty()) { req.set(boost::beast::http::field::content_type, "application/json"); + req.set(boost::beast::http::field::transfer_encoding, "chunked"); req.body() = params.Body; req.prepare_payload(); } diff --git a/src/agent/multitype_queue/include/imultitype_queue.hpp b/src/agent/multitype_queue/include/imultitype_queue.hpp index 49e03e7313..ded5b2f7df 100644 --- a/src/agent/multitype_queue/include/imultitype_queue.hpp +++ b/src/agent/multitype_queue/include/imultitype_queue.hpp @@ -51,31 +51,39 @@ class IMultiTypeQueue * @brief Retrieves the next message from the queue. * * @param type The type of the queue to use as the source. - * @param module The name of the module requesting the message. + * @param moduleName The name of the module requesting the message. + * @param moduleType The type of the module requesting the messages. * @return Message The next message from the queue. */ - virtual Message getNext(MessageType type, const std::string module = "") = 0; + virtual Message getNext(MessageType type, const std::string moduleName = "", const std::string moduleType = "") = 0; /** * @brief Retrieves the next message from the queue asynchronously. * * @param type The type of the queue to use as the source. - * @param moduleName The name of the module requesting the message. * @param messageQuantity The quantity of messages to return. + * @param moduleName The name of the module requesting the message. + * @param moduleType The type of the module requesting the messages. * @return boost::asio::awaitable Awaitable object representing the next message. */ - virtual boost::asio::awaitable - getNextNAwaitable(MessageType type, int messageQuantity, const std::string moduleName = "") = 0; + virtual boost::asio::awaitable getNextNAwaitable(MessageType type, + int messageQuantity, + const std::string moduleName = "", + const std::string moduleType = "") = 0; /** * @brief Retrieves the next N messages from the queue. * * @param type The type of the queue to use as the source. - * @param moduleName The name of the module requesting the messages. * @param messageQuantity The quantity of messages to return. + * @param moduleName The name of the module requesting the messages. + * @param moduleType The type of the module requesting the messages. * @return std::vector A vector of messages fetched from the queue. */ - virtual std::vector getNextN(MessageType type, int messageQuantity, const std::string moduleName = "") = 0; + virtual std::vector getNextN(MessageType type, + int messageQuantity, + const std::string moduleName = "", + const std::string moduleType = "") = 0; /** * @brief Deletes a message from the queue. diff --git a/src/agent/multitype_queue/include/message.hpp b/src/agent/multitype_queue/include/message.hpp index d9443894b5..b6253fe0ee 100644 --- a/src/agent/multitype_queue/include/message.hpp +++ b/src/agent/multitype_queue/include/message.hpp @@ -16,7 +16,8 @@ enum class MessageType }; /** - * @brief Wrapper for Message, contains the message type, the json data and the module name. + * @brief Wrapper for Message, contains the message type, the json data, the + * module name, the module type and the metadata. * */ class Message @@ -25,17 +26,22 @@ class Message MessageType type; nlohmann::json data; std::string moduleName; + std::string moduleType; + std::string metaData; - Message(MessageType t, nlohmann::json d, std::string mN = "") + Message(MessageType t, nlohmann::json d, std::string mN = "", std::string mT = "", std::string mD = "") : type(t) , data(d) , moduleName(mN) + , moduleType(mT) + , metaData(mD) { } // Define equality operator bool operator==(const Message& other) const { - return type == other.type && data == other.data; + return type == other.type && data == other.data && moduleName == other.moduleName && + moduleType == other.moduleType && metaData == other.metaData; } }; diff --git a/src/agent/multitype_queue/include/multitype_queue.hpp b/src/agent/multitype_queue/include/multitype_queue.hpp index 6ea26ebb69..d350314aa1 100644 --- a/src/agent/multitype_queue/include/multitype_queue.hpp +++ b/src/agent/multitype_queue/include/multitype_queue.hpp @@ -92,18 +92,23 @@ class MultiTypeQueue : public IMultiTypeQueue /** * @copydoc IMultiTypeQueue::getNext(MessageType, const std::string) */ - Message getNext(MessageType type, const std::string module = "") override; + Message getNext(MessageType type, const std::string moduleName = "", const std::string moduleType = "") override; /** * @copydoc IMultiTypeQueue::getNextNAwaitable(MessageType, int, const std::string) */ - boost::asio::awaitable - getNextNAwaitable(MessageType type, int messageQuantity, const std::string moduleName = "") override; + boost::asio::awaitable getNextNAwaitable(MessageType type, + int messageQuantity, + const std::string moduleName = "", + const std::string moduleType = "") override; /** * @copydoc IMultiTypeQueue::getNextN(MessageType, int, const std::string) */ - std::vector getNextN(MessageType type, int messageQuantity, const std::string moduleName = "") override; + std::vector getNextN(MessageType type, + int messageQuantity, + const std::string moduleName = "", + const std::string moduleType = "") override; /** * @copydoc IMultiTypeQueue::pop(MessageType, const std::string) diff --git a/src/agent/multitype_queue/include/persistence.hpp b/src/agent/multitype_queue/include/persistence.hpp index e805e90ca8..a1af51e195 100644 --- a/src/agent/multitype_queue/include/persistence.hpp +++ b/src/agent/multitype_queue/include/persistence.hpp @@ -24,20 +24,28 @@ class Persistence * @param message The JSON message to be stored. * @param queueName The name of the queue. * @param moduleName The name of the module. + * @param moduleType The type of the module. + * @param metadata The metadata message to store. * @return int The number of messages stored. */ - virtual int - Store(const nlohmann::json& message, const std::string& queueName, const std::string& moduleName = "") = 0; - + virtual int Store(const nlohmann::json& message, + const std::string& tableName, + const std::string& moduleName = "", + const std::string& moduleType = "", + const std::string& metadata = "") = 0; /** * @brief Retrieve a JSON message from the specified queue. * * @param id rowid of the message to be retrieved. * @param queueName The name of the queue. * @param moduleName The name of the module. + * @param moduleType The type of the module. * @return nlohmann::json The retrieved JSON message. */ - virtual nlohmann::json Retrieve(int id, const std::string& queueName, const std::string& moduleName = "") = 0; + virtual nlohmann::json Retrieve(int id, + const std::string& queueName, + const std::string& moduleName = "", + const std::string& moduleType = "") = 0; /** * @brief Retrieve multiple JSON messages from the specified queue. @@ -45,10 +53,13 @@ class Persistence * @param n number of messages to be retrieved. * @param queueName The name of the queue. * @param moduleName The name of the module. + * @param moduleType The type of the module. * @return nlohmann::json The retrieved JSON messages. */ - virtual nlohmann::json - RetrieveMultiple(int n, const std::string& queueName, const std::string& moduleName = "") = 0; + virtual nlohmann::json RetrieveMultiple(int n, + const std::string& queueName, + const std::string& moduleName = "", + const std::string& moduleType = "") = 0; /** * @brief Remove a JSON message from the specified queue. diff --git a/src/agent/multitype_queue/src/multitype_queue.cpp b/src/agent/multitype_queue/src/multitype_queue.cpp index 61abd3ee81..f83e6adf6b 100644 --- a/src/agent/multitype_queue/src/multitype_queue.cpp +++ b/src/agent/multitype_queue/src/multitype_queue.cpp @@ -53,15 +53,19 @@ int MultiTypeQueue::push(Message message, bool shouldWait) { for (const auto& singleMessageData : messageData) { - result += m_persistenceDest->Store(singleMessageData, sMessageType, message.moduleName); + result += m_persistenceDest->Store( + singleMessageData, sMessageType, message.moduleName, message.moduleType, message.metaData); m_cv.notify_all(); } } } else { - result = - m_persistenceDest->Store(message.data, m_mapMessageTypeName.at(message.type), message.moduleName); + result = m_persistenceDest->Store(message.data, + m_mapMessageTypeName.at(message.type), + message.moduleName, + message.moduleType, + message.metaData); m_cv.notify_all(); } } @@ -99,15 +103,19 @@ boost::asio::awaitable MultiTypeQueue::pushAwaitable(Message message) { for (const auto& singleMessageData : messageData) { - result += m_persistenceDest->Store(singleMessageData, sMessageType, message.moduleName); + result += m_persistenceDest->Store( + singleMessageData, sMessageType, message.moduleName, message.moduleType, message.metaData); m_cv.notify_all(); } } } else { - result = - m_persistenceDest->Store(message.data, m_mapMessageTypeName.at(message.type), message.moduleName); + result = m_persistenceDest->Store(message.data, + m_mapMessageTypeName.at(message.type), + message.moduleName, + message.moduleType, + message.metaData); m_cv.notify_all(); } } @@ -129,19 +137,18 @@ int MultiTypeQueue::push(std::vector messages) return result; } -Message MultiTypeQueue::getNext(MessageType type, const std::string moduleName) +Message MultiTypeQueue::getNext(MessageType type, const std::string moduleName, const std::string moduleType) { - Message result(type, "{}"_json, moduleName); + Message result(type, "{}"_json, moduleName, moduleType, ""); if (m_mapMessageTypeName.contains(type)) { - auto resultData = m_persistenceDest->RetrieveMultiple(1, m_mapMessageTypeName.at(type), moduleName); + auto resultData = m_persistenceDest->RetrieveMultiple(1, m_mapMessageTypeName.at(type), moduleName, moduleType); if (!resultData.empty()) { - result.data = resultData; - if (moduleName.empty()) - { - result.moduleName = result.data.at(0).at("module"); - } + result.data = resultData[0]["data"]; + result.metaData = resultData[0]["metadata"]; + result.moduleName = resultData[0]["moduleName"]; + result.moduleType = resultData[0]["moduleType"]; } } else @@ -152,12 +159,14 @@ Message MultiTypeQueue::getNext(MessageType type, const std::string moduleName) return result; } -boost::asio::awaitable -MultiTypeQueue::getNextNAwaitable(MessageType type, int messageQuantity, const std::string moduleName) +boost::asio::awaitable MultiTypeQueue::getNextNAwaitable(MessageType type, + int messageQuantity, + const std::string moduleName, + const std::string moduleType) { boost::asio::steady_timer timer(co_await boost::asio::this_coro::executor); - Message result(type, "{}"_json, moduleName); + Message result(type, "{}"_json, moduleName, moduleType, ""); if (m_mapMessageTypeName.contains(type)) { while (isEmpty(type)) @@ -167,14 +176,14 @@ MultiTypeQueue::getNextNAwaitable(MessageType type, int messageQuantity, const s } auto resultData = - m_persistenceDest->RetrieveMultiple(messageQuantity, m_mapMessageTypeName.at(type), moduleName); + m_persistenceDest->RetrieveMultiple(messageQuantity, m_mapMessageTypeName.at(type), moduleName, moduleType); + if (!resultData.empty()) { - result.data = resultData; - if (moduleName.empty()) - { - result.moduleName = result.data.at(0).at("module"); - } + result.data = resultData[0]["data"]; + result.metaData = resultData[0]["metadata"]; + result.moduleName = resultData[0]["moduleName"]; + result.moduleType = resultData[0]["moduleType"]; } } else @@ -185,21 +194,20 @@ MultiTypeQueue::getNextNAwaitable(MessageType type, int messageQuantity, const s co_return result; } -std::vector MultiTypeQueue::getNextN(MessageType type, int messageQuantity, const std::string moduleName) +std::vector MultiTypeQueue::getNextN(MessageType type, + int messageQuantity, + const std::string moduleName, + const std::string moduleType) { std::vector result; if (m_mapMessageTypeName.contains(type)) { auto arrayData = - m_persistenceDest->RetrieveMultiple(messageQuantity, m_mapMessageTypeName.at(type), moduleName); + m_persistenceDest->RetrieveMultiple(messageQuantity, m_mapMessageTypeName.at(type), moduleName, moduleType); for (auto singleJson : arrayData) { - auto finalModuleName = moduleName; - if (moduleName.empty()) - { - finalModuleName = singleJson["module"]; - } - result.emplace_back(type, singleJson, finalModuleName); + result.emplace_back( + type, singleJson["data"], singleJson["moduleName"], singleJson["moduleType"], singleJson["metadata"]); } } else diff --git a/src/agent/multitype_queue/src/sqlitestorage.cpp b/src/agent/multitype_queue/src/sqlitestorage.cpp index 0f0f918c62..ea0ee67a6f 100644 --- a/src/agent/multitype_queue/src/sqlitestorage.cpp +++ b/src/agent/multitype_queue/src/sqlitestorage.cpp @@ -35,7 +35,7 @@ void SQLiteStorage::InitializeTable(const std::string& tableName) { // TODO: all queries should be in the same place. constexpr std::string_view CREATE_TABLE_QUERY { - "CREATE TABLE IF NOT EXISTS {} (module TEXT, message TEXT NOT NULL);"}; + "CREATE TABLE IF NOT EXISTS {} (module_name TEXT, module_type TEXT, metadata TEXT, message TEXT NOT NULL);"}; auto createTableQuery = fmt::format(CREATE_TABLE_QUERY, tableName); std::lock_guard lock(m_mutex); try @@ -63,10 +63,19 @@ void SQLiteStorage::ReleaseDatabaseAccess() m_cv.notify_one(); } -int SQLiteStorage::Store(const nlohmann::json& message, const std::string& tableName, const std::string& moduleName) +int SQLiteStorage::Store(const nlohmann::json& message, + const std::string& tableName, + const std::string& moduleName, + const std::string& moduleType, + const std::string& metadata) { - constexpr std::string_view INSERT_QUERY {"INSERT INTO {} (module, message) VALUES (\"{}\", ?);"}; - std::string insertQuery = fmt::format(INSERT_QUERY, tableName, moduleName); + + std::string insertQuery; + + constexpr std::string_view INSERT_QUERY { + R"(INSERT INTO {} (module_name, module_type, metadata, message) VALUES ("{}", "{}", '{}', ?);)"}; + insertQuery = fmt::format(INSERT_QUERY, tableName, moduleName, moduleType, metadata); + int result = 0; WaitForDatabaseAccess(); @@ -105,19 +114,22 @@ int SQLiteStorage::Store(const nlohmann::json& message, const std::string& table } // TODO: we shouldn't use rowid outside the table itself -nlohmann::json SQLiteStorage::Retrieve(int id, const std::string& tableName, const std::string& moduleName) +nlohmann::json SQLiteStorage::Retrieve(int id, + const std::string& tableName, + const std::string& moduleName, + [[maybe_unused]] const std::string& moduleType) { - std::string selectQuery; if (moduleName.empty()) { - constexpr std::string_view SELECT_QUERY {"SELECT module, message FROM {} WHERE rowid = ?;"}; + constexpr std::string_view SELECT_QUERY {"SELECT module_name, module_type, metadata, message FROM {} WHERE " + "rowid = ?;"}; selectQuery = fmt::format(SELECT_QUERY, tableName); } else { constexpr std::string_view SELECT_QUERY { - "SELECT module, message FROM {} WHERE module LIKE \"{}\" AND rowid = ?;"}; + "SELECT module_name, module_type, metadata, message FROM {} WHERE module_name LIKE \"{}\" AND rowid = ?;"}; selectQuery = fmt::format(SELECT_QUERY, tableName, moduleName); } @@ -125,32 +137,43 @@ nlohmann::json SQLiteStorage::Retrieve(int id, const std::string& tableName, con { SQLite::Statement query(*m_db, selectQuery); query.bind(1, id); - nlohmann::json outputJson = {{"module", ""}, {"data", {}}}; + nlohmann::json outputJson = {{"moduleName", ""}, {"moduleType", ""}, {"metadata", ""}, {"data", {}}}; if (query.executeStep()) { - std::string dataString; - std::string moduleString; - - if (query.getColumnCount() == 2 && query.getColumn(1).getType() == SQLite::TEXT && + if (query.getColumnCount() == 4 && query.getColumn(3).getType() == SQLite::TEXT && + query.getColumn(2).getType() == SQLite::TEXT && query.getColumn(1).getType() == SQLite::TEXT && query.getColumn(0).getType() == SQLite::TEXT) { - moduleString = query.getColumn(0).getString(); - dataString = query.getColumn(1).getString(); + std::string moduleNameString = query.getColumn(0).getString(); + std::string moduleTypeString = query.getColumn(1).getString(); + std::string metadataString = query.getColumn(2).getString(); + std::string dataString = query.getColumn(3).getString(); if (!dataString.empty()) { outputJson["data"] = nlohmann::json::parse(dataString); } - if (!moduleString.empty()) + if (!metadataString.empty()) + { + outputJson["metadata"] = metadataString; + } + + if (!moduleNameString.empty()) + { + outputJson["moduleName"] = moduleNameString; + } + + if (!moduleTypeString.empty()) { - outputJson["module"] = moduleString; + outputJson["moduleType"] = moduleTypeString; } } } return outputJson; } + catch (const std::exception& e) { LogError("Error during Retrieve operation: {}.", e.what()); @@ -158,18 +181,23 @@ nlohmann::json SQLiteStorage::Retrieve(int id, const std::string& tableName, con } } -nlohmann::json SQLiteStorage::RetrieveMultiple(int n, const std::string& tableName, const std::string& moduleName) +nlohmann::json SQLiteStorage::RetrieveMultiple(int n, + const std::string& tableName, + const std::string& moduleName, + [[maybe_unused]] const std::string& moduleType) { std::string selectQuery; if (moduleName.empty()) { - constexpr std::string_view SELECT_MULTIPLE_QUERY {"SELECT module, message FROM {} ORDER BY rowid ASC LIMIT ?;"}; + constexpr std::string_view SELECT_MULTIPLE_QUERY { + "SELECT module_name, module_type, metadata, message FROM {} ORDER BY rowid ASC LIMIT ?;"}; selectQuery = fmt::format(SELECT_MULTIPLE_QUERY, tableName); } else { constexpr std::string_view SELECT_MULTIPLE_QUERY { - "SELECT module, message FROM {} WHERE module LIKE \"{}\" ORDER BY rowid ASC LIMIT ?;"}; + "SELECT module_name, module_type, metadata, message FROM {} WHERE " + "module_name LIKE \"{}\" ORDER BY rowid ASC LIMIT ?;"}; selectQuery = fmt::format(SELECT_MULTIPLE_QUERY, tableName, moduleName); } @@ -180,26 +208,35 @@ nlohmann::json SQLiteStorage::RetrieveMultiple(int n, const std::string& tableNa nlohmann::json messages = nlohmann::json::array(); while (query.executeStep()) { - // getting data nlohmann::json - std::string dataString; - std::string moduleString; - - if (query.getColumnCount() == 2 && query.getColumn(1).getType() == SQLite::TEXT && + if (query.getColumnCount() == 4 && query.getColumn(3).getType() == SQLite::TEXT && + query.getColumn(2).getType() == SQLite::TEXT && query.getColumn(1).getType() == SQLite::TEXT && query.getColumn(0).getType() == SQLite::TEXT) { - moduleString = query.getColumn(0).getString(); - dataString = query.getColumn(1).getString(); + std::string moduleNameString = query.getColumn(0).getString(); + std::string moduleTypeString = query.getColumn(1).getString(); + std::string metadataString = query.getColumn(2).getString(); + std::string dataString = query.getColumn(3).getString(); - nlohmann::json outputJson = {{"module", ""}, {"data", {}}}; + nlohmann::json outputJson = {{"moduleName", ""}, {"moduleType", ""}, {"metadata", ""}, {"data", {}}}; if (!dataString.empty()) { outputJson["data"] = nlohmann::json::parse(dataString); } - if (!moduleString.empty()) + if (!metadataString.empty()) + { + outputJson["metadata"] = metadataString; + } + + if (!moduleNameString.empty()) { - outputJson["module"] = moduleString; + outputJson["moduleName"] = moduleNameString; + } + + if (!moduleTypeString.empty()) + { + outputJson["moduleType"] = moduleTypeString; } messages.push_back(outputJson); @@ -225,7 +262,7 @@ int SQLiteStorage::Remove(int id, const std::string& tableName, const std::strin } else { - constexpr std::string_view DELETE_QUERY {"DELETE FROM {} WHERE module LIKE \"{}\" AND rowid = ?;"}; + constexpr std::string_view DELETE_QUERY {"DELETE FROM {} WHERE module_name LIKE \"{}\" AND rowid = ?;"}; deleteQuery = fmt::format(DELETE_QUERY, tableName, moduleName); } @@ -257,9 +294,9 @@ int SQLiteStorage::RemoveMultiple(int n, const std::string& tableName, const std } else { - constexpr std::string_view DELETE_MULTIPLE_QUERY { - "DELETE FROM {} WHERE module LIKE \"{}\" AND rowid IN (SELECT rowid FROM {} WHERE module LIKE \"{}\" ORDER " - "BY rowid ASC LIMIT ?);"}; + constexpr std::string_view DELETE_MULTIPLE_QUERY {"DELETE FROM {} WHERE module_name LIKE \"{}\" AND rowid IN " + "(SELECT rowid FROM {} WHERE module_name LIKE \"{}\" ORDER " + "BY rowid ASC LIMIT ?);"}; deleteQuery = fmt::format(DELETE_MULTIPLE_QUERY, tableName, moduleName, tableName, moduleName); } @@ -291,7 +328,7 @@ int SQLiteStorage::GetElementCount(const std::string& tableName, const std::stri } else { - constexpr std::string_view COUNT_QUERY {"SELECT COUNT(*) FROM {} WHERE module LIKE \"{}\""}; + constexpr std::string_view COUNT_QUERY {"SELECT COUNT(*) FROM {} WHERE module_name LIKE \"{}\""}; countQuery = fmt::format(COUNT_QUERY, tableName, moduleName); } diff --git a/src/agent/multitype_queue/src/sqlitestorage.hpp b/src/agent/multitype_queue/src/sqlitestorage.hpp index 4ad938a421..25f2491058 100644 --- a/src/agent/multitype_queue/src/sqlitestorage.hpp +++ b/src/agent/multitype_queue/src/sqlitestorage.hpp @@ -54,9 +54,15 @@ class SQLiteStorage : public Persistence * @param message The JSON message to store. * @param tableName The name of the table to store the message in. * @param moduleName The name of the module that created the message. + * @param moduleType The type of the module that created the message. + * @param metadata The metadata message to store. * @return The number of stored elements. */ - int Store(const nlohmann::json& message, const std::string& tableName, const std::string& moduleName = "") override; + int Store(const nlohmann::json& message, + const std::string& tableName, + const std::string& moduleName = "", + const std::string& moduleType = "", + const std::string& metadata = "") override; /** * @brief Retrieve a JSON message by its ID. @@ -64,9 +70,13 @@ class SQLiteStorage : public Persistence * @param id The ID of the message to retrieve. * @param tableName The name of the table to retrieve the message from. * @param moduleName The name of the module that created the message. + * @param moduleType The module type that created the message. * @return The retrieved JSON message. */ - nlohmann::json Retrieve(int id, const std::string& tableName, const std::string& moduleName = "") override; + nlohmann::json Retrieve(int id, + const std::string& tableName, + const std::string& moduleName = "", + const std::string& moduleType = "") override; /** * @brief Retrieve multiple JSON messages. @@ -74,9 +84,13 @@ class SQLiteStorage : public Persistence * @param n The number of messages to retrieve. * @param tableName The name of the table to retrieve the message from. * @param moduleName The name of the module that created the message. + * @param moduleType The module type that created the message. * @return A vector of retrieved JSON messages. */ - nlohmann::json RetrieveMultiple(int n, const std::string& tableName, const std::string& moduleName = "") override; + nlohmann::json RetrieveMultiple(int n, + const std::string& tableName, + const std::string& moduleName = "", + const std::string& moduleType = "") override; /** * @brief Remove a JSON message by its ID. diff --git a/src/agent/multitype_queue/tests/multitype_queue_test.cpp b/src/agent/multitype_queue/tests/multitype_queue_test.cpp index 298799b32a..b5c0648a49 100644 --- a/src/agent/multitype_queue/tests/multitype_queue_test.cpp +++ b/src/agent/multitype_queue/tests/multitype_queue_test.cpp @@ -143,7 +143,7 @@ TEST_F(MultiTypeQueueTest, SinglePushGetNotEmpty) auto typeReceived = messageResponse.type; EXPECT_TRUE(typeSend == typeReceived); - auto dataResponse = messageResponse.data.at(0).at("data"); + auto dataResponse = messageResponse.data; EXPECT_EQ(dataResponse, BASE_DATA_CONTENT); EXPECT_FALSE(multiTypeQueue.isEmpty(MessageType::STATELESS)); @@ -158,7 +158,7 @@ TEST_F(MultiTypeQueueTest, SinglePushPopEmpty) EXPECT_EQ(multiTypeQueue.push(messageToSend), 1); auto messageResponse = multiTypeQueue.getNext(MessageType::STATELESS); - auto dataResponse = messageResponse.data.at(0).at("data"); + auto dataResponse = messageResponse.data; EXPECT_EQ(dataResponse, BASE_DATA_CONTENT); EXPECT_EQ(messageType, messageResponse.type); @@ -194,7 +194,7 @@ TEST_F(MultiTypeQueueTest, SinglePushGetWithModule) auto messageResponseCorrectModule = multiTypeQueue.getNext(MessageType::STATELESS, moduleName); - auto dataResponse = messageResponseCorrectModule.data.at(0).at("data"); + auto dataResponse = messageResponseCorrectModule.data; EXPECT_EQ(dataResponse, BASE_DATA_CONTENT); EXPECT_EQ(moduleName, messageResponseCorrectModule.moduleName); @@ -364,7 +364,7 @@ TEST_F(MultiTypeQueueTest, PushMultipleSeveralSingleGets) for (size_t i : {0u, 1u, 2u}) { auto messageResponse = multiTypeQueue.getNext(MessageType::STATELESS); - auto responseData = messageResponse.data.at(0).at("data"); + auto responseData = messageResponse.data; auto sentData = messageToSend.data[i].template get(); EXPECT_EQ(responseData, sentData); multiTypeQueue.pop(MessageType::STATELESS); @@ -440,9 +440,9 @@ TEST_F(MultiTypeQueueTest, PushMultipleGetMultipleWithModule) auto messagesReceived = multiTypeQueue.getNextN(MessageType::STATELESS, 10); // NOLINT(cppcoreguidelines-avoid-magic-numbers) int i = 0; - for (auto singleMessage : messagesReceived) + for (const auto& singleMessage : messagesReceived) { - EXPECT_EQ("content " + std::to_string(++i), singleMessage.data.at("data").get()); + EXPECT_EQ("content " + std::to_string(++i), singleMessage.data.get()); } EXPECT_EQ(0, multiTypeQueue.storedItems(MessageType::STATELESS, "fakemodule")); @@ -459,7 +459,7 @@ TEST_F(MultiTypeQueueTest, PushSinglesleGetMultipleWithModule) const MessageType messageType {MessageType::STATELESS}; const nlohmann::json multipleDataContent = {"content-" + i}; const std::string moduleName = "module-" + i; - const Message messageToSend {messageType, multipleDataContent, moduleName}; + const Message messageToSend {messageType, multipleDataContent, moduleName, "", ""}; EXPECT_EQ(1, multiTypeQueue.push(messageToSend)); } @@ -467,11 +467,11 @@ TEST_F(MultiTypeQueueTest, PushSinglesleGetMultipleWithModule) multiTypeQueue.getNextN(MessageType::STATELESS, 10); // NOLINT(cppcoreguidelines-avoid-magic-numbers) EXPECT_EQ(5, messagesReceived.size()); int i = 0; - for (auto singleMessage : messagesReceived) + for (const auto& singleMessage : messagesReceived) { auto val = ++i; - EXPECT_EQ("content-" + std::to_string(val), singleMessage.data.at("data").get()); - EXPECT_EQ("module-" + std::to_string(val), singleMessage.data.at("module").get()); + EXPECT_EQ("content-" + std::to_string(val), singleMessage.data.get()); + EXPECT_EQ("module-" + std::to_string(val), singleMessage.moduleName); } auto messageReceivedContent1 = multiTypeQueue.getNextN( @@ -563,7 +563,7 @@ TEST_F(MultiTypeQueueTest, FifoOrderCheck) const MessageType messageType {MessageType::STATEFUL}; for (int i : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { - const nlohmann::json dataContent = R"({"Data" : "for STATEFUL)" + std::to_string(i) + R"("})"; + const nlohmann::json dataContent = {{"Data", "for STATEFUL" + std::to_string(i)}}; EXPECT_EQ(multiTypeQueue.push({messageType, dataContent}), 1); } @@ -571,17 +571,17 @@ TEST_F(MultiTypeQueueTest, FifoOrderCheck) multiTypeQueue.getNextN(messageType, 10); // NOLINT(cppcoreguidelines-avoid-magic-numbers) EXPECT_EQ(messageReceivedVector.size(), 10); - std::for_each( - messageReceivedVector.begin(), - messageReceivedVector.end(), - [i = 0](const auto& singleMessage) mutable - { EXPECT_EQ(singleMessage.data.at("data"), R"({"Data" : "for STATEFUL)" + std::to_string(++i) + R"("})"); }); + std::for_each(messageReceivedVector.begin(), + messageReceivedVector.end(), + [i = 0](const auto& singleMessage) mutable { + EXPECT_EQ(singleMessage.data, (nlohmann::json {{"Data", "for STATEFUL" + std::to_string(++i)}})); + }); // Keep the order of the message: FIFO for (int i : {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) { auto messageReceived = multiTypeQueue.getNextN(messageType, 1); - EXPECT_EQ(messageReceived.at(0).data.at("data"), R"({"Data" : "for STATEFUL)" + std::to_string(i) + R"("})"); + EXPECT_EQ(messageReceived[0].data, (nlohmann::json {{"Data", "for STATEFUL" + std::to_string(i)}})); EXPECT_TRUE(multiTypeQueue.pop(messageType)); } } diff --git a/src/agent/src/message_queue_utils.cpp b/src/agent/src/message_queue_utils.cpp index c267e141e2..fb149f8b0f 100644 --- a/src/agent/src/message_queue_utils.cpp +++ b/src/agent/src/message_queue_utils.cpp @@ -13,18 +13,18 @@ boost::asio::awaitable GetMessagesFromQueue(std::shared_ptr getMetadataInfo) { - const auto message = co_await multiTypeQueue->getNextNAwaitable(messageType, NUM_EVENTS); + const auto message = co_await multiTypeQueue->getNextNAwaitable(messageType, NUM_EVENTS, "", ""); nlohmann::json jsonObj; + std::string output; if (getMetadataInfo != nullptr) { jsonObj = getMetadataInfo(); + output = jsonObj.dump() + "\n"; } - jsonObj["events"] = message.data; - - co_return jsonObj.dump(); + co_return output + message.metaData + "\n" + message.data.dump(); } void PopMessagesFromQueue(std::shared_ptr multiTypeQueue, MessageType messageType) diff --git a/src/agent/tests/message_queue_utils_test.cpp b/src/agent/tests/message_queue_utils_test.cpp index 654f3b3eb5..e4f5ad5ab9 100644 --- a/src/agent/tests/message_queue_utils_test.cpp +++ b/src/agent/tests/message_queue_utils_test.cpp @@ -16,13 +16,13 @@ class MockMultiTypeQueue : public MultiTypeQueue public: MOCK_METHOD(boost::asio::awaitable, getNextNAwaitable, - (MessageType, int, const std::string module), + (MessageType, int, const std::string, const std::string), (override)); - MOCK_METHOD(int, popN, (MessageType, int, const std::string module), (override)); + MOCK_METHOD(int, popN, (MessageType, int, const std::string), (override)); MOCK_METHOD(int, push, (Message, bool), (override)); MOCK_METHOD(int, push, (std::vector), (override)); - MOCK_METHOD(bool, isEmpty, (MessageType, const std::string moduleName), (override)); - MOCK_METHOD(Message, getNext, (MessageType, const std::string moduleName), (override)); + MOCK_METHOD(bool, isEmpty, (MessageType, const std::string), (override)); + MOCK_METHOD(Message, getNext, (MessageType, const std::string, const std::string), (override)); }; class MessageQueueUtilsTest : public ::testing::Test @@ -39,18 +39,17 @@ class MessageQueueUtilsTest : public ::testing::Test TEST_F(MessageQueueUtilsTest, GetMessagesFromQueueTest) { - std::vector data {"test_data"}; - Message testMessage {MessageType::STATEFUL, data}; + std::vector data {R"({"event":{"original":"Testing message!"}})"}; + std::string metadata {R"({"module":"logcollector","type":"file"})"}; + Message testMessage {MessageType::STATELESS, data, "", "", metadata}; // NOLINTBEGIN(cppcoreguidelines-avoid-capturing-lambda-coroutines) - EXPECT_CALL(*mockQueue, getNextNAwaitable(MessageType::STATEFUL, 1, "")) + EXPECT_CALL(*mockQueue, getNextNAwaitable(MessageType::STATELESS, 1, "", "")) .WillOnce([&testMessage]() -> boost::asio::awaitable { co_return testMessage; }); // NOLINTEND(cppcoreguidelines-avoid-capturing-lambda-coroutines) - io_context.restart(); - auto result = boost::asio::co_spawn( - io_context, GetMessagesFromQueue(mockQueue, MessageType::STATEFUL, nullptr), boost::asio::use_future); + io_context, GetMessagesFromQueue(mockQueue, MessageType::STATELESS, nullptr), boost::asio::use_future); const auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(1); io_context.run_until(timeout); @@ -59,23 +58,23 @@ TEST_F(MessageQueueUtilsTest, GetMessagesFromQueueTest) const auto jsonResult = result.get(); - nlohmann::json expectedJson; - expectedJson["events"] = nlohmann::json::array(); - expectedJson["events"].push_back("test_data"); + std::string expectedString = R"({"module":"logcollector","type":"file"})" + std::string("\n") + + R"(["{\"event\":{\"original\":\"Testing message!\"}}"])"; - ASSERT_EQ(jsonResult, expectedJson.dump()); + ASSERT_EQ(jsonResult, expectedString); } TEST_F(MessageQueueUtilsTest, GetMessagesFromQueueMetadataTest) { - std::vector data {"test_data"}; - Message testMessage {MessageType::STATEFUL, data}; + std::vector data {R"({"event":{"original":"Testing message!"}})"}; + std::string moduleMetadata {R"({"module":"logcollector","type":"file"})"}; + Message testMessage {MessageType::STATELESS, data, "", "", moduleMetadata}; nlohmann::json metadata; metadata["agent"] = "test"; // NOLINTBEGIN(cppcoreguidelines-avoid-capturing-lambda-coroutines) - EXPECT_CALL(*mockQueue, getNextNAwaitable(MessageType::STATEFUL, 1, "")) + EXPECT_CALL(*mockQueue, getNextNAwaitable(MessageType::STATELESS, 1, "", "")) .WillOnce([&testMessage]() -> boost::asio::awaitable { co_return testMessage; }); // NOLINTEND(cppcoreguidelines-avoid-capturing-lambda-coroutines) @@ -83,7 +82,7 @@ TEST_F(MessageQueueUtilsTest, GetMessagesFromQueueMetadataTest) auto result = boost::asio::co_spawn( io_context, - GetMessagesFromQueue(mockQueue, MessageType::STATEFUL, [&metadata]() { return metadata; }), + GetMessagesFromQueue(mockQueue, MessageType::STATELESS, [&metadata]() { return metadata; }), boost::asio::use_future); const auto timeout = std::chrono::steady_clock::now() + std::chrono::milliseconds(1); @@ -93,12 +92,11 @@ TEST_F(MessageQueueUtilsTest, GetMessagesFromQueueMetadataTest) const auto jsonResult = result.get(); - nlohmann::json expectedJson; - expectedJson["agent"] = "test"; - expectedJson["events"] = nlohmann::json::array(); - expectedJson["events"].push_back("test_data"); + std::string expectedString = R"({"agent":"test"})" + std::string("\n") + + R"({"module":"logcollector","type":"file"})" + std::string("\n") + + R"(["{\"event\":{\"original\":\"Testing message!\"}}"])"; - ASSERT_EQ(jsonResult, expectedJson.dump()); + ASSERT_EQ(jsonResult, expectedString); } TEST_F(MessageQueueUtilsTest, PopMessagesFromQueueTest) @@ -146,7 +144,7 @@ TEST_F(MessageQueueUtilsTest, GetCommandFromQueueTest) EXPECT_CALL(*mockQueue, isEmpty(MessageType::COMMAND, "")).WillOnce(testing::Return(false)); - EXPECT_CALL(*mockQueue, getNext(MessageType::COMMAND, "")).WillOnce(testing::Return(testMessage)); + EXPECT_CALL(*mockQueue, getNext(MessageType::COMMAND, "", "")).WillOnce(testing::Return(testMessage)); auto cmd = GetCommandFromQueue(mockQueue); diff --git a/src/modules/inventory/src/inventory.cpp b/src/modules/inventory/src/inventory.cpp index 899111319a..97cab329b7 100644 --- a/src/modules/inventory/src/inventory.cpp +++ b/src/modules/inventory/src/inventory.cpp @@ -69,23 +69,19 @@ void Inventory::SetPushMessageFunction(const std::function& pushMe void Inventory::SendDeltaEvent(const std::string& data) { const auto jsonData = nlohmann::json::parse(data); - const Message statelessMessage{ MessageType::STATELESS, jsonData, Name() }; - const Message statefulMessage{ MessageType::STATEFUL, jsonData, Name() }; - if(!m_pushMessage(statelessMessage)) { - LogWarn("Stateless event can't be pushed into the message queue: {}", data); + std::string dataType; + if (jsonData.contains("type") ) { + dataType = jsonData["type"].get(); } - else { - LogTrace("Stateless event queued: {}", data); - } + const Message statefulMessage{ MessageType::STATEFUL, jsonData, Name(), dataType }; if(!m_pushMessage(statefulMessage)) { LogWarn("Stateful event can't be pushed into the message queue: {}", data); } else { - LogTrace("Stateful event queued: {}", data); - + LogTrace("Stateful event queued: {}, dataType {}", data, dataType); } } diff --git a/src/modules/inventory/src/inventoryImp.cpp b/src/modules/inventory/src/inventoryImp.cpp index ed6b379f9f..5df4714194 100644 --- a/src/modules/inventory/src/inventoryImp.cpp +++ b/src/modules/inventory/src/inventoryImp.cpp @@ -26,7 +26,7 @@ static const std::map OPERATION_MAP constexpr auto OS_SQL_STATEMENT { - R"(CREATE TABLE dbsync_osinfo ( + R"(CREATE TABLE osinfo ( hostname TEXT, architecture TEXT, os_name TEXT, @@ -48,7 +48,7 @@ constexpr auto OS_SQL_STATEMENT constexpr auto HW_SQL_STATEMENT { - R"(CREATE TABLE dbsync_hwinfo ( + R"(CREATE TABLE hwinfo ( board_serial TEXT, cpu_name TEXT, cpu_cores INTEGER, @@ -62,7 +62,7 @@ constexpr auto HW_SQL_STATEMENT constexpr auto HOTFIXES_SQL_STATEMENT { - R"(CREATE TABLE dbsync_hotfixes( + R"(CREATE TABLE hotfixes( hotfix TEXT, checksum TEXT, PRIMARY KEY (hotfix)) WITHOUT ROWID;)" @@ -70,7 +70,7 @@ constexpr auto HOTFIXES_SQL_STATEMENT constexpr auto PACKAGES_SQL_STATEMENT { - R"(CREATE TABLE dbsync_packages( + R"(CREATE TABLE packages( name TEXT, version TEXT, vendor TEXT, @@ -92,7 +92,7 @@ static const std::vector PACKAGES_ITEM_ID_FIELDS{"name", "version", constexpr auto PROCESSES_SQL_STATEMENT { - R"(CREATE TABLE dbsync_processes ( + R"(CREATE TABLE processes ( pid TEXT, name TEXT, state TEXT, @@ -127,7 +127,7 @@ constexpr auto PROCESSES_SQL_STATEMENT constexpr auto PORTS_SQL_STATEMENT { - R"(CREATE TABLE dbsync_ports ( + R"(CREATE TABLE ports ( protocol TEXT, local_ip TEXT, local_port BIGINT, @@ -147,7 +147,7 @@ static const std::vector PORTS_ITEM_ID_FIELDS{"inode", "protocol", constexpr auto NETIFACE_SQL_STATEMENT { - R"(CREATE TABLE dbsync_network_iface ( + R"(CREATE TABLE network_iface ( name TEXT, adapter TEXT, type TEXT, @@ -170,7 +170,7 @@ static const std::vector NETIFACE_ITEM_ID_FIELDS{"name", "adapter", constexpr auto NETPROTO_SQL_STATEMENT { - R"(CREATE TABLE dbsync_network_protocol ( + R"(CREATE TABLE network_protocol ( iface TEXT, type TEXT, gateway TEXT, @@ -184,7 +184,7 @@ static const std::vector NETPROTO_ITEM_ID_FIELDS{"iface", "type"}; constexpr auto NETADDR_SQL_STATEMENT { - R"(CREATE TABLE dbsync_network_address ( + R"(CREATE TABLE network_address ( iface TEXT, proto INTEGER, address TEXT, @@ -196,15 +196,15 @@ constexpr auto NETADDR_SQL_STATEMENT }; static const std::vector NETADDRESS_ITEM_ID_FIELDS{"iface", "proto", "address"}; -constexpr auto NET_IFACE_TABLE { "dbsync_network_iface" }; -constexpr auto NET_PROTOCOL_TABLE { "dbsync_network_protocol" }; -constexpr auto NET_ADDRESS_TABLE { "dbsync_network_address" }; -constexpr auto PACKAGES_TABLE { "dbsync_packages" }; -constexpr auto HOTFIXES_TABLE { "dbsync_hotfixes" }; -constexpr auto PORTS_TABLE { "dbsync_ports" }; -constexpr auto PROCESSES_TABLE { "dbsync_processes" }; -constexpr auto OS_TABLE { "dbsync_osinfo" }; -constexpr auto HW_TABLE { "dbsync_hwinfo" }; +constexpr auto NET_IFACE_TABLE { "network_iface" }; +constexpr auto NET_PROTOCOL_TABLE { "network_protocol" }; +constexpr auto NET_ADDRESS_TABLE { "network_address" }; +constexpr auto PACKAGES_TABLE { "packages" }; +constexpr auto HOTFIXES_TABLE { "hotfixes" }; +constexpr auto PORTS_TABLE { "ports" }; +constexpr auto PROCESSES_TABLE { "processes" }; +constexpr auto OS_TABLE { "osinfo" }; +constexpr auto HW_TABLE { "hwinfo" }; static std::string GetItemId(const nlohmann::json& item, const std::vector& idFields) diff --git a/src/modules/inventory/tests/inventoryImp/inventoryImp_test.cpp b/src/modules/inventory/tests/inventoryImp/inventoryImp_test.cpp index 8a81020fd9..9223d047e4 100644 --- a/src/modules/inventory/tests/inventoryImp/inventoryImp_test.cpp +++ b/src/modules/inventory/tests/inventoryImp/inventoryImp_test.cpp @@ -88,7 +88,7 @@ TEST_F(InventoryImpTest, defaultCtor) { auto delta = nlohmann::json::parse(data); - if (delta.at("type").get_ref().compare("dbsync_osinfo") == 0) + if (delta.at("type").get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -100,49 +100,49 @@ TEST_F(InventoryImpTest, defaultCtor) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult11 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; @@ -318,7 +318,7 @@ TEST_F(InventoryImpTest, noHardware) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -330,43 +330,43 @@ TEST_F(InventoryImpTest, noHardware) const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult11 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult2)).Times(1); @@ -447,7 +447,7 @@ TEST_F(InventoryImpTest, noOs) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -459,43 +459,43 @@ TEST_F(InventoryImpTest, noOs) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult11 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -575,7 +575,7 @@ TEST_F(InventoryImpTest, noNetwork) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -587,27 +587,27 @@ TEST_F(InventoryImpTest, noNetwork) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -681,7 +681,7 @@ TEST_F(InventoryImpTest, noPackages) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -693,43 +693,43 @@ TEST_F(InventoryImpTest, noPackages) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult11 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -809,7 +809,7 @@ TEST_F(InventoryImpTest, noPorts) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -821,43 +821,43 @@ TEST_F(InventoryImpTest, noPorts) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult18 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult20 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -938,7 +938,7 @@ TEST_F(InventoryImpTest, noPortsAll) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -950,51 +950,51 @@ TEST_F(InventoryImpTest, noPortsAll) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult11 { - R"({"data":{"checksum":"09d591fb0ed092c387f77b24af5bada43b5d519d","inode":0,"item_id":"7046b3f9cda975eb6567259c2469748e634dde49","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"udp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"09d591fb0ed092c387f77b24af5bada43b5d519d","inode":0,"item_id":"7046b3f9cda975eb6567259c2469748e634dde49","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"udp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult12 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -1074,7 +1074,7 @@ TEST_F(InventoryImpTest, noProcesses) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -1086,43 +1086,43 @@ TEST_F(InventoryImpTest, noProcesses) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult10 { - R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"dbsync_hotfixes"})" + R"({"data":{"checksum":"56162cd7bb632b4728ec868e8e271b01222ff131","hotfix":"KB12345678"},"operation":"INSERTED","type":"hotfixes"})" }; const auto expectedResult11 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -1203,7 +1203,7 @@ TEST_F(InventoryImpTest, noHotfixes) { auto delta = nlohmann::json::parse(data); - if (delta["type"].get_ref().compare("dbsync_osinfo") == 0) + if (delta["type"].get_ref().compare("osinfo") == 0) { delta["data"].erase("checksum"); } @@ -1215,43 +1215,43 @@ TEST_F(InventoryImpTest, noHotfixes) const auto expectedResult1 { - R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"dbsync_hwinfo"})" + R"({"data":{"board_serial":"Intel Corporation","checksum":"af7b22eef8f5e06c04af4db49c9f8d1d28963918","cpu_MHz":2904,"cpu_cores":2,"cpu_name":"Intel(R) Core(TM) i5-9400 CPU @ 2.90GHz","ram_free":2257872,"ram_total":4972208,"ram_usage":54},"operation":"INSERTED","type":"hwinfo"})" }; const auto expectedResult2 { - R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"dbsync_osinfo"})" + R"({"data":{"architecture":"x86_64","hostname":"UBUNTU","os_build":"7601","os_major":"6","os_minor":"1","os_name":"Microsoft Windows 7","os_release":"sp1","os_version":"6.1.7601"},"operation":"INSERTED","type":"osinfo"})" }; const auto expectedResult3 { - R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"dbsync_network_iface"})" + R"({"data":{"adapter":" ","checksum":"165f7160ecd2838479ee4c43c1012b723736d90a","item_id":"25eef9a0a422a9b644fb6b73650453148bc6151c","mac":"d4:5d:64:51:07:5d","mtu":1500,"name":"enp4s0","rx_bytes":0,"rx_dropped":0,"rx_errors":0,"rx_packets":0,"state":"up","tx_bytes":0,"tx_dropped":0,"tx_errors":0,"tx_packets":0,"type":"ethernet"},"operation":"INSERTED","type":"network_iface"})" }; const auto expectedResult4 { - R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ff63981c231f110a0877ac6acd8862ac09877b5d","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"d633b040008ea38303d778431ee2fd0b4ee5a37a","metric":" ","type":"ipv4"},"operation":"INSERTED","type":"network_protocol"})" }; const auto expectedResult5 { - R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"192.168.153.1","broadcast":"192.168.153.255","checksum":"72dfd66759bd8062cdc17607d760a48c906189b3","iface":"enp4s0","item_id":"3d48ddc47fac84c62a19746af66fbfcf78547de9","netmask":"255.255.255.0","proto":0},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult6 { - R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"dbsync_network_address"})" + R"({"data":{"address":"fe80::250:56ff:fec0:8","checksum":"f606d1a1c551874d8fab33e4e5cfaa0370673ec8","iface":"enp4s0","item_id":"65973316a5dc8615a6d20b2d6c4ce52ecd074496","netmask":"ffff:ffff:ffff:ffff::","proto":1},"operation":"INSERTED","type":"network_address"})" }; const auto expectedResult7 { - R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"checksum":"f25348b1ce5310f36c1ed859d13138fbb4e6bacb","inode":0,"item_id":"cbf2ac25a6775175f912ebf2abc72f6f51ab48ba","local_ip":"127.0.0.1","local_port":631,"pid":0,"process_name":"System Idle Process","protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult8 { - R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"dbsync_processes"})" + R"({"data":{"checksum":"039934723aa69928b52e470c8d27365b0924b615","egroup":"root","euser":"root","fgroup":"root","name":"kworker/u256:2-","nice":0,"nlwp":1,"pgrp":0,"pid":"431625","ppid":2,"priority":20,"processor":1,"resident":0,"rgroup":"root","ruser":"root","session":0,"sgroup":"root","share":0,"size":0,"start_time":9302261,"state":"I","stime":3,"suser":"root","tgid":431625,"tty":0,"utime":0,"vm_size":0},"operation":"INSERTED","type":"processes"})" }; const auto expectedResult9 { - R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","checksum":"c084f78ed87ed19974b1fd90bbf727c2d1416f7d","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; const auto expectedResult18 { - R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"dbsync_network_protocol"})" + R"({"data":{"checksum":"ea17673e7422c0ab04c4f1f111a5828be8cd366a","dhcp":"unknown","gateway":"192.168.0.1|600","iface":"enp4s0","item_id":"9dff246584835755137820c975f034d089e90b6f","metric":" ","type":"ipv6"},"operation":"INSERTED","type":"network_protocol"})" }; EXPECT_CALL(wrapperDelta, callbackMock(expectedResult1)).Times(1); @@ -1444,22 +1444,22 @@ TEST_F(InventoryImpTest, portAllEnable) }; const auto expectedResult1 { - R"({"data":{"inode":43481,"item_id":"12903a43db24ab10d872547cdd1d786a5876a0da","local_ip":"0.0.0.0","local_port":47748,"pid":0,"process_name":null,"protocol":"udp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":43481,"item_id":"12903a43db24ab10d872547cdd1d786a5876a0da","local_ip":"0.0.0.0","local_port":47748,"pid":0,"process_name":null,"protocol":"udp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult2 { - R"({"data":{"inode":43482,"item_id":"ca7c9aff241cb251c6ad31e30b806366ecb2ad5f","local_ip":"::","local_port":51087,"pid":0,"process_name":null,"protocol":"udp6","remote_ip":"::","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":43482,"item_id":"ca7c9aff241cb251c6ad31e30b806366ecb2ad5f","local_ip":"::","local_port":51087,"pid":0,"process_name":null,"protocol":"udp6","remote_ip":"::","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult3 { - R"({"data":{"inode":50324,"item_id":"8c790ef53962dd27f4516adb1d7f3f6096bc6d29","local_ip":"127.0.0.1","local_port":33060,"pid":0,"process_name":null,"protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":50324,"item_id":"8c790ef53962dd27f4516adb1d7f3f6096bc6d29","local_ip":"127.0.0.1","local_port":33060,"pid":0,"process_name":null,"protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult4 { - R"({"data":{"inode":122575,"item_id":"d5511242275bd3f2d57175f248108d6c3b39c438","local_ip":"192.168.0.104","local_port":39106,"pid":0,"process_name":null,"protocol":"tcp","remote_ip":"44.238.116.130","remote_port":443,"rx_queue":0,"state":"established","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":122575,"item_id":"d5511242275bd3f2d57175f248108d6c3b39c438","local_ip":"192.168.0.104","local_port":39106,"pid":0,"process_name":null,"protocol":"tcp","remote_ip":"44.238.116.130","remote_port":443,"rx_queue":0,"state":"established","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; EXPECT_CALL(wrapper, callbackMock(expectedResult1)).Times(1); @@ -1589,17 +1589,17 @@ TEST_F(InventoryImpTest, portAllDisable) }; const auto expectedResult1 { - R"({"data":{"inode":43481,"item_id":"12903a43db24ab10d872547cdd1d786a5876a0da","local_ip":"0.0.0.0","local_port":47748,"pid":0,"process_name":null,"protocol":"udp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":43481,"item_id":"12903a43db24ab10d872547cdd1d786a5876a0da","local_ip":"0.0.0.0","local_port":47748,"pid":0,"process_name":null,"protocol":"udp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult2 { - R"({"data":{"inode":43482,"item_id":"ca7c9aff241cb251c6ad31e30b806366ecb2ad5f","local_ip":"::","local_port":51087,"pid":0,"process_name":null,"protocol":"udp6","remote_ip":"::","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":43482,"item_id":"ca7c9aff241cb251c6ad31e30b806366ecb2ad5f","local_ip":"::","local_port":51087,"pid":0,"process_name":null,"protocol":"udp6","remote_ip":"::","remote_port":0,"rx_queue":0,"state":null,"tx_queue":0},"operation":"INSERTED","type":"ports"})" }; const auto expectedResult3 { - R"({"data":{"inode":50324,"item_id":"8c790ef53962dd27f4516adb1d7f3f6096bc6d29","local_ip":"127.0.0.1","local_port":33060,"pid":0,"process_name":null,"protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"dbsync_ports"})" + R"({"data":{"inode":50324,"item_id":"8c790ef53962dd27f4516adb1d7f3f6096bc6d29","local_ip":"127.0.0.1","local_port":33060,"pid":0,"process_name":null,"protocol":"tcp","remote_ip":"0.0.0.0","remote_port":0,"rx_queue":0,"state":"listening","tx_queue":0},"operation":"INSERTED","type":"ports"})" }; EXPECT_CALL(wrapper, callbackMock(expectedResult1)).Times(1); @@ -1671,7 +1671,7 @@ TEST_F(InventoryImpTest, PackagesDuplicated) const auto expectedResult1 { - R"({"data":{"architecture":"amd64","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"dbsync_packages"})" + R"({"data":{"architecture":"amd64","format":"deb","group":"x11","item_id":"4846c220a185b0fc251a07843efbfbb0d90ac4a5","location":" ","name":"xserver-xorg","priority":"optional","size":411,"source":"xorg","version":"1:7.7+19ubuntu14"},"operation":"INSERTED","type":"packages"})" }; EXPECT_CALL(wrapper, callbackMock(expectedResult1)).Times(1); diff --git a/src/modules/logcollector/include/logcollector.hpp b/src/modules/logcollector/include/logcollector.hpp index 43ad0b3cc4..c05d994792 100644 --- a/src/modules/logcollector/include/logcollector.hpp +++ b/src/modules/logcollector/include/logcollector.hpp @@ -45,8 +45,9 @@ class Logcollector { /// @brief Sends a message to que queue /// @param location Location of the message /// @param log Message to send + /// @param collectorType type of logcollector /// @pre The message queue must be set with SetMessageQueue - virtual void SendMessage(const std::string& location, const std::string& log); + virtual void SendMessage(const std::string& location, const std::string& log, const std::string& collectorType); /// @brief Enqueues an ASIO task (coroutine) /// @param task Task to enqueue diff --git a/src/modules/logcollector/src/file_reader.cpp b/src/modules/logcollector/src/file_reader.cpp index aa61c49ec4..8749840a16 100644 --- a/src/modules/logcollector/src/file_reader.cpp +++ b/src/modules/logcollector/src/file_reader.cpp @@ -30,7 +30,7 @@ Awaitable FileReader::ReadLocalfile(Localfile* lf) { auto log = lf->NextLog(); while (!log.empty()) { - m_logcollector.SendMessage(lf->Filename(), log); + m_logcollector.SendMessage(lf->Filename(), log, m_collectorType); log = lf->NextLog(); } diff --git a/src/modules/logcollector/src/file_reader.hpp b/src/modules/logcollector/src/file_reader.hpp index 2654a0da0b..df8bb6d7d0 100644 --- a/src/modules/logcollector/src/file_reader.hpp +++ b/src/modules/logcollector/src/file_reader.hpp @@ -116,6 +116,9 @@ class FileReader : public IReader { /// @brief Reload (wildcard expand) interval in seconds long m_reloadIntervalSec; + + /// @brief File pattern + const std::string m_collectorType = "file"; }; /// @brief Open error class diff --git a/src/modules/logcollector/src/logcollector.cpp b/src/modules/logcollector/src/logcollector.cpp index c08fd26318..a6bd1d89c1 100644 --- a/src/modules/logcollector/src/logcollector.cpp +++ b/src/modules/logcollector/src/logcollector.cpp @@ -4,10 +4,15 @@ #include #include +#include +#include +#include + #include "file_reader.hpp" using namespace logcollector; + void Logcollector::Start() { if (!m_enabled) { LogInfo("Logcollector is disabled"); @@ -64,25 +69,55 @@ void Logcollector::Stop() { LogInfo("Logcollector stopped"); } -// NOLINTNEXTLINE(performance-unnecessary-value-param) -Co_CommandExecutionResult Logcollector::ExecuteCommand(const std::string command, [[maybe_unused]] const nlohmann::json parameters) { - LogInfo("Logcollector command: ", command); - co_return module_command::CommandExecutionResult{module_command::Status::SUCCESS, "OK"}; +// NOLINTBEGIN(performance-unnecessary-value-param) +Co_CommandExecutionResult Logcollector::ExecuteCommand(const std::string command, + [[maybe_unused]] const nlohmann::json parameters) { + LogInfo("Logcollector command: ", command); + co_return module_command::CommandExecutionResult{module_command::Status::SUCCESS, "OK"}; } +// NOLINTEND(performance-unnecessary-value-param) void Logcollector::SetPushMessageFunction(const std::function& pushMessage) { m_pushMessage = pushMessage; } -void Logcollector::SendMessage(const std::string& location, const std::string& log) { +void Logcollector::SendMessage(const std::string& location, const std::string& log, const std::string& collectorType) { + auto metadata = nlohmann::json::object(); auto data = nlohmann::json::object(); - auto event = nlohmann::json::object(); - data["location"] = location; - data["event"] = event; - event["original"] = log; - auto message = Message(MessageType::STATELESS, data, m_moduleName); + auto getCurrentTimestamp = []() { + constexpr int MILLISECS_IN_A_SEC = 1000; + auto now = std::chrono::system_clock::now(); + auto time_t_now = std::chrono::system_clock::to_time_t(now); + auto milliseconds = std::chrono::duration_cast(now.time_since_epoch()).count() % MILLISECS_IN_A_SEC; + + std::tm tm_now{}; +#ifdef _WIN32 + gmtime_s(&tm_now, &time_t_now); // MSVC (Windows) +#else + gmtime_r(&time_t_now, &tm_now); // Linux/macOS (POSIX) +#endif + + // Formatear el timestamp + std::ostringstream oss; + oss << std::put_time(&tm_now, "%Y-%m-%dT%H:%M:%S") << '.' + << std::setw(3) << std::setfill('0') << milliseconds << "Z"; // Usar 'milliseconds' como entero + + return oss.str(); + }; + + metadata["module"] = m_moduleName; + metadata["type"] = collectorType; + + data["log"]["file"]["path"] = location; + data["tags"] = nlohmann::json::array({"mvp"}); + data["event"]["original"] = log; + data["event"]["ingested"] = getCurrentTimestamp(); + data["event"]["module"] = m_moduleName; + data["event"]["provider"] = "syslog"; + + auto message = Message(MessageType::STATELESS, data, m_moduleName, collectorType, metadata.dump()); m_pushMessage(message); LogTrace("Message pushed: '{}':'{}'", location, log); diff --git a/src/modules/logcollector/tests/unit/logcollector_mock.hpp b/src/modules/logcollector/tests/unit/logcollector_mock.hpp index 1faeb35dd3..47979f675c 100644 --- a/src/modules/logcollector/tests/unit/logcollector_mock.hpp +++ b/src/modules/logcollector/tests/unit/logcollector_mock.hpp @@ -21,6 +21,7 @@ class LogcollectorMock : public Logcollector { } MOCK_METHOD(void, AddReader, (std::shared_ptr reader), (override)); - MOCK_METHOD(void, SendMessage, (const std::string& location, const std::string& log), (override)); + MOCK_METHOD(void, SendMessage, (const std::string& location, const std::string& log, + const std::string& collectorType), (override)); MOCK_METHOD(void, EnqueueTask, (Awaitable task), (override)); }; diff --git a/src/modules/logcollector/tests/unit/queue_mock.hpp b/src/modules/logcollector/tests/unit/queue_mock.hpp index 4544623f56..63975619d5 100644 --- a/src/modules/logcollector/tests/unit/queue_mock.hpp +++ b/src/modules/logcollector/tests/unit/queue_mock.hpp @@ -5,15 +5,32 @@ class QueueMock : public IMultiTypeQueue { public: - MOCK_METHOD(int, push, (Message message, bool shouldWait), (override)); - MOCK_METHOD(boost::asio::awaitable, pushAwaitable, (Message message), (override)); - MOCK_METHOD(int, push, (std::vector messages), (override)); - MOCK_METHOD(Message, getNext, (MessageType type, const std::string module), (override)); - MOCK_METHOD(boost::asio::awaitable, getNextNAwaitable, (MessageType type, int messageQuantity, const std::string moduleName), (override)); - MOCK_METHOD(std::vector, getNextN, (MessageType type, int messageQuantity, const std::string moduleName), (override)); - MOCK_METHOD(bool, pop, (MessageType type, const std::string moduleName), (override)); - MOCK_METHOD(int, popN, (MessageType type, int messageQuantity, const std::string moduleName), (override)); - MOCK_METHOD(bool, isEmpty, (MessageType type, const std::string moduleName), (override)); - MOCK_METHOD(bool, isFull, (MessageType type, const std::string moduleName), (override)); - MOCK_METHOD(int, storedItems, (MessageType type, const std::string moduleName), (override)); + MOCK_METHOD(int, push, (Message message, bool shouldWait), (override)); + MOCK_METHOD(boost::asio::awaitable, pushAwaitable, (Message message), + (override)); + MOCK_METHOD(int, push, (std::vector messages), (override)); + MOCK_METHOD(Message, getNext, + (MessageType type, const std::string module, + const std::string moduleType), + (override)); + MOCK_METHOD(boost::asio::awaitable, getNextNAwaitable, + (MessageType type, int messageQuantity, + const std::string moduleName, const std::string moduleType), + (override)); + MOCK_METHOD(std::vector, getNextN, + (MessageType type, int messageQuantity, + const std::string moduleName, const std::string moduleType), + (override)); + MOCK_METHOD(bool, pop, (MessageType type, const std::string moduleName), + (override)); + MOCK_METHOD(int, popN, + (MessageType type, int messageQuantity, + const std::string moduleName), + (override)); + MOCK_METHOD(bool, isEmpty, (MessageType type, const std::string moduleName), + (override)); + MOCK_METHOD(bool, isFull, (MessageType type, const std::string moduleName), + (override)); + MOCK_METHOD(int, storedItems, + (MessageType type, const std::string moduleName), (override)); };