Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stateless Messages to Inventory Module Indicating Detected Deltas #454

Merged
merged 10 commits into from
Jan 17, 2025
3 changes: 2 additions & 1 deletion src/agent/src/message_queue_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ GetMessagesFromQueue(std::shared_ptr<IMultiTypeQueue> multiTypeQueue,
const auto messages = co_await multiTypeQueue->getNextBytesAwaitable(messageType, messagesSize, "", "");
for (const auto& message : messages)
{
output += "\n" + message.metaData + (message.data.dump() == "{}" ? "" : "\n" + message.data.dump());
output += (message.metaData.empty() ? "" : "\n" + message.metaData) +
(message.data.dump() == "{}" ? "" : "\n" + message.data.dump());
}

co_return std::tuple<int, std::string> {static_cast<int>(messages.size()), output};
Expand Down
4 changes: 2 additions & 2 deletions src/common/data_provider/src/network/networkBSDWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class NetworkBSDInterface final : public INetworkInterfaceWrapper

void adapter(nlohmann::json& network) const override
{
network["adapter"] = UNKNOWN_VALUE;
network["adapter"] = EMPTY_VALUE;
}

int family() const override
Expand Down Expand Up @@ -201,7 +201,7 @@ class NetworkBSDInterface final : public INetworkInterfaceWrapper

void type(nlohmann::json& network) const override
{
network["type"] = UNKNOWN_VALUE;
network["type"] = EMPTY_VALUE;

if (m_interfaceAddress->ifa_addr)
{
Expand Down
4 changes: 2 additions & 2 deletions src/common/data_provider/src/network/networkLinuxWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class NetworkLinuxInterface final : public INetworkInterfaceWrapper

void adapter(nlohmann::json& network) const override
{
network["adapter"] = UNKNOWN_VALUE;
network["adapter"] = EMPTY_VALUE;
}

int family() const override
Expand Down Expand Up @@ -507,7 +507,7 @@ class NetworkLinuxInterface final : public INetworkInterfaceWrapper

void type(nlohmann::json& network) const override
{
network["type"] = UNKNOWN_VALUE;
network["type"] = EMPTY_VALUE;
const auto networkTypeCode { Utils::getFileContent(std::string(WM_SYS_IFDATA_DIR) + this->name() + "/type") };

if (!networkTypeCode.empty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ class NetworkWindowsInterface final : public INetworkInterfaceWrapper

void type(nlohmann::json& network) const override
{
network["type"] = UNKNOWN_VALUE;
network["type"] = EMPTY_VALUE;
const auto interfaceType { NETWORK_INTERFACE_TYPES.find(m_interfaceAddress->IfType) };

if (NETWORK_INTERFACE_TYPES.end() != interfaceType)
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/packages/brewWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class BrewWrapper final : public IPackageWrapper

void architecture(nlohmann::json& package) const override
{
package["architecture"] = UNKNOWN_VALUE;
package["architecture"] = EMPTY_VALUE;
}

void format(nlohmann::json& package) const override
Expand Down
26 changes: 13 additions & 13 deletions src/common/data_provider/src/packages/packageLinuxParserHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ namespace PackageLinuxHelper
{
ret["name"] = info.at("Package");

nlohmann::json priority {UNKNOWN_VALUE};
nlohmann::json groups {UNKNOWN_VALUE};
nlohmann::json priority = UNKNOWN_VALUE;
nlohmann::json groups = UNKNOWN_VALUE;
// The multiarch field won't have a default value
nlohmann::json multiarch;
nlohmann::json architecture {UNKNOWN_VALUE};
nlohmann::json source {UNKNOWN_VALUE};
nlohmann::json version {UNKNOWN_VALUE};
nlohmann::json vendor {UNKNOWN_VALUE};
nlohmann::json description {UNKNOWN_VALUE};
nlohmann::json multiarch = UNKNOWN_VALUE;
nlohmann::json architecture = EMPTY_VALUE;
nlohmann::json source = UNKNOWN_VALUE;
nlohmann::json version = EMPTY_VALUE;
nlohmann::json vendor = UNKNOWN_VALUE;
nlohmann::json description = UNKNOWN_VALUE;
int size { 0 };

auto it{info.find("Priority")};
Expand Down Expand Up @@ -151,7 +151,7 @@ namespace PackageLinuxHelper
ret["source"] = source;
ret["version"] = version;
ret["format"] = "deb";
ret["location"] = UNKNOWN_VALUE;
ret["location"] = EMPTY_VALUE;
ret["vendor"] = vendor;
ret["install_time"] = UNKNOWN_VALUE;
ret["description"] = description;
Expand All @@ -166,9 +166,9 @@ namespace PackageLinuxHelper

std::string name;
std::string version;
nlohmann::json vendor { UNKNOWN_VALUE };
nlohmann::json install_time { UNKNOWN_VALUE };
nlohmann::json description { UNKNOWN_VALUE };
nlohmann::json vendor = UNKNOWN_VALUE;
nlohmann::json install_time = UNKNOWN_VALUE;
nlohmann::json description = UNKNOWN_VALUE;
int size { 0 };
bool hasName { false };
bool hasVersion { false };
Expand Down Expand Up @@ -262,7 +262,7 @@ namespace PackageLinuxHelper

ret["priority"] = UNKNOWN_VALUE;
ret["multiarch"] = UNKNOWN_VALUE;
ret["architecture"] = UNKNOWN_VALUE;
ret["architecture"] = EMPTY_VALUE;
ret["groups"] = UNKNOWN_VALUE;

return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace PackageLinuxHelper
ret["name"] = package.name;
ret["size"] = package.size;
ret["install_time"] = package.installTime;
ret["location"] = UNKNOWN_VALUE;
ret["location"] = EMPTY_VALUE;
ret["groups"] = package.group;
ret["version"] = version;
ret["priority"] = UNKNOWN_VALUE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ namespace PackageLinuxHelper
ret["name"] = name;
ret["size"] = size.empty() || size.compare(DEFAULT_VALUE) == 0 ? 0 : stoi(size);
ret["install_time"] = install_time.empty() || install_time.compare(DEFAULT_VALUE) == 0 ? UNKNOWN_VALUE : nlohmann::json(install_time);
ret["location"] = UNKNOWN_VALUE;
ret["location"] = EMPTY_VALUE;
ret["groups"] = groups.empty() || groups.compare(DEFAULT_VALUE) == 0 ? UNKNOWN_VALUE : nlohmann::json(groups);
ret["version"] = version.empty() || version.compare(DEFAULT_VALUE) == 0 ? UNKNOWN_VALUE : nlohmann::json(version);
ret["version"] = version.empty() || version.compare(DEFAULT_VALUE) == 0 ? EMPTY_VALUE : nlohmann::json(version);
ret["priority"] = UNKNOWN_VALUE;
ret["architecture"] = architecture.empty() || architecture.compare(DEFAULT_VALUE) == 0 ? UNKNOWN_VALUE : nlohmann::json(architecture);
ret["architecture"] = architecture.empty() || architecture.compare(DEFAULT_VALUE) == 0 ? EMPTY_VALUE : nlohmann::json(architecture);
ret["source"] = UNKNOWN_VALUE;
ret["format"] = "rpm";
ret["vendor"] = vendor.empty() || vendor.compare(DEFAULT_VALUE) == 0 ? UNKNOWN_VALUE : nlohmann::json(vendor);
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/packages/packagesNPM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NPM final

packageInfo["groups"] = UNKNOWN_VALUE;
packageInfo["description"] = UNKNOWN_VALUE;
packageInfo["architecture"] = UNKNOWN_VALUE;
packageInfo["architecture"] = EMPTY_VALUE;
packageInfo["format"] = "npm";
packageInfo["source"] = UNKNOWN_VALUE;
packageInfo["location"] = path.string();
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/packages/packagesPYPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class PYPI final : public TFileSystem, public TFileIO

packageInfo["groups"] = UNKNOWN_VALUE;
packageInfo["description"] = UNKNOWN_VALUE;
packageInfo["architecture"] = UNKNOWN_VALUE;
packageInfo["architecture"] = EMPTY_VALUE;
packageInfo["format"] = "pypi";
packageInfo["source"] = UNKNOWN_VALUE;
packageInfo["location"] = path.string();
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/packages/pkgWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class PKGWrapper final : public IPackageWrapper
}
void architecture(nlohmann::json& package) const override
{
package["architecture"] = UNKNOWN_VALUE;
package["architecture"] = EMPTY_VALUE;
}
void format(nlohmann::json& package) const override
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/ports/portBSDWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class BSDPortWrapper final : public IPortWrapper

void protocol(nlohmann::json& port) const override
{
port["protocol"] = UNKNOWN_VALUE;
port["protocol"] = EMPTY_VALUE;
const auto it { PORTS_TYPE.find(m_spSocketInfo->psi.soi_kind) };

if (it != PORTS_TYPE.end())
Expand Down
6 changes: 3 additions & 3 deletions src/common/data_provider/src/ports/portLinuxWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ class LinuxPortWrapper final : public IPortWrapper
}
else
{
port["protocol"] = UNKNOWN_VALUE;
port["protocol"] = EMPTY_VALUE;
}
}

void localIp(nlohmann::json& port) const override
{
port["local_ip"] = UNKNOWN_VALUE;
port["local_ip"] = EMPTY_VALUE;

if (m_localAddresses.size() == AddressField::ADDRESS_FIELD_SIZE)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ class LinuxPortWrapper final : public IPortWrapper
}
else
{
port["local_port"] = UNKNOWN_VALUE;
port["local_port"] = EMPTY_VALUE;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/data_provider/src/sysInfoLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static nlohmann::json getProcessInfo(const SysInfoProcess& process)

static void getSerialNumber(nlohmann::json& info)
{
info["board_serial"] = UNKNOWN_VALUE;
info["board_serial"] = EMPTY_VALUE;
std::fstream file{WM_SYS_HW_DIR, std::ios_base::in};

if (file.is_open())
Expand Down
8 changes: 4 additions & 4 deletions src/common/data_provider/src/sysInfoWin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static void getPackagesFromReg(const HKEY key, const std::string& subKey, std::f
{
packageJson["name"] = value;

packageJson["version"] = UNKNOWN_VALUE;
packageJson["version"] = EMPTY_VALUE;
if (packageReg.string("DisplayVersion", value))
{
packageJson["version"] = value;
Expand Down Expand Up @@ -399,13 +399,13 @@ static void getPackagesFromReg(const HKEY key, const std::string& subKey, std::f
packageJson["install_time"] = Utils::timestampToISO8601(packageReg.keyModificationDate());
}

packageJson["location"] = UNKNOWN_VALUE;
packageJson["location"] = EMPTY_VALUE;
if (packageReg.string("InstallLocation", value))
{
packageJson["location"] = value;
}

packageJson["architecture"] = UNKNOWN_VALUE;
packageJson["architecture"] = EMPTY_VALUE;
if (access & KEY_WOW64_32KEY)
{
packageJson["architecture"] = "i686";
Expand Down Expand Up @@ -509,7 +509,7 @@ static std::string getSerialNumber()
}
else
{
ret = UNKNOWN_VALUE;
ret = EMPTY_VALUE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ TEST(SysInfoPackageLinuxParserRPM_test, rpmFromBerkleyDB)
CallbackMock wrapper;

auto expectedPackage1 =
R"({"architecture":"amd64","description":"The Open Source Security Platform","format":"rpm","groups":"test","install_time":"5","name":"Wazuh","size":321,"vendor":"The Wazuh Team","version":"123:4.4-1","location":null,"priority":null,"source":null})"_json;
R"({"architecture":"amd64","description":"The Open Source Security Platform","format":"rpm","groups":"test","install_time":"5","name":"Wazuh","size":321,"vendor":"The Wazuh Team","version":"123:4.4-1","location":"","priority":null,"source":null})"_json;

auto utils_mock { std::make_unique<UtilsMock>() };
auto libdb_mock { std::make_unique<LibDBMock>() };
Expand Down Expand Up @@ -345,7 +345,7 @@ TEST(SysInfoPackageLinuxParserRPM_test, rpmFromLibRPM)
CallbackMock wrapper;

auto expectedPackage1 =
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":"","priority":null,"source":null})"_json;

auto utils_mock { std::make_unique<UtilsMock>() };
auto rpm_mock { std::make_unique<RpmLibMock>() };
Expand Down Expand Up @@ -402,9 +402,9 @@ TEST(SysInfoPackageLinuxParserRPM_test, rpmFallbackFromLibRPM)
CallbackMock wrapper;

auto expectedPackage1 =
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":"","priority":null,"source":null})"_json;
auto expectedPackage2 =
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":"","priority":null,"source":null})"_json;

auto utils_mock { std::make_unique<UtilsMock>() };
auto rpm_mock { std::make_unique<RpmLibMock>() };
Expand All @@ -430,9 +430,9 @@ TEST(SysInfoPackageLinuxParserRPM_test, rpmFallbackFromBerkleyDBConfigError)
CallbackMock wrapper;

auto expectedPackage1 =
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":"","priority":null,"source":null})"_json;
auto expectedPackage2 =
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":"","priority":null,"source":null})"_json;

auto utils_mock { std::make_unique<UtilsMock>() };
auto libdb_mock { std::make_unique<LibDBMock>() };
Expand All @@ -459,9 +459,9 @@ TEST(SysInfoPackageLinuxParserRPM_test, rpmFallbackFromBerkleyDBOpenError)
CallbackMock wrapper;

auto expectedPackage1 =
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":"","priority":null,"source":null})"_json;
auto expectedPackage2 =
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":"","priority":null,"source":null})"_json;

auto utils_mock { std::make_unique<UtilsMock>() };
auto libdb_mock { std::make_unique<LibDBMock>() };
Expand Down Expand Up @@ -497,9 +497,9 @@ TEST(SysInfoPackageLinuxParserRPM_test, rpmFallbackFromBerkleyDBCursorError)
CallbackMock wrapper;

auto expectedPackage1 =
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"1","architecture":"2","description":"3","size":4,"version":"5:7-6","vendor":"8","install_time":"9","groups":"10","format":"rpm","location":"","priority":null,"source":null})"_json;
auto expectedPackage2 =
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":null,"priority":null,"source":null})"_json;
R"({"name":"11","architecture":"12","description":"13","size":14,"version":"15:17-16","vendor":"18","install_time":"19","groups":"20","format":"rpm","location":"","priority":null,"source":null})"_json;

auto utils_mock { std::make_unique<UtilsMock>() };
auto libdb_mock { std::make_unique<LibDBMock>() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ TEST_F(SysInfoPackagesLinuxHelperTest, parseRpmInformationUnknownInEmpty)
EXPECT_EQ(0, jsPackageInfo["size"]);
EXPECT_EQ(UNKNOWN_VALUE, jsPackageInfo["install_time"]);
EXPECT_EQ(UNKNOWN_VALUE, jsPackageInfo["groups"]);
EXPECT_EQ(UNKNOWN_VALUE, jsPackageInfo["version"]);
EXPECT_EQ(UNKNOWN_VALUE, jsPackageInfo["architecture"]);
EXPECT_EQ(EMPTY_VALUE, jsPackageInfo["version"]);
EXPECT_EQ(EMPTY_VALUE, jsPackageInfo["architecture"]);
EXPECT_EQ("rpm", jsPackageInfo["format"]);
EXPECT_EQ(UNKNOWN_VALUE, jsPackageInfo["vendor"]);
EXPECT_EQ(UNKNOWN_VALUE, jsPackageInfo["description"]);
Expand Down
Loading
Loading