docs/ref/modules/inventory-sync/architecture.md
The Inventory Sync module implements a session-based synchronization architecture designed to ensure reliable transfer of inventory data from Wazuh agents to the Wazuh Indexer. It leverages a combination of design patterns — Facade, Template Method, and Publisher–Subscriber — to modularize responsibilities, simplify extensibility, and provide scalable synchronization capabilities.
inventorySyncFacade.hppThe main orchestration component and entry point for inventory synchronization. Responsibilities:
agentSession.hppManages synchronization state and lifecycle for each agent. Responsibilities:
context.hppDefines metadata for each synchronization session. Responsibilities:
responseDispatcher.hppHandles outbound communication to agents. Responsibilities:
The Inventory Sync protocol operates in three phases:
Start Phase
START message containing mode and agent context.Data Phase
End Phase
END message.The module processes four distinct data message types during the Data Phase:
Purpose: Standard inventory data for indexing
Processing:
{session}_{seq}Indexer Integration:
bulkIndex() or bulkDelete()Purpose: Context metadata for Vulnerability Detector (future integration)
Processing:
{session}_{seq}_contextSpecial Handling:
key.ends_with("_context"))Purpose: Bulk deletion via deleteByQuery
Processing:
dataCleanIndices setdeleteByQuery for specified indices during End PhaseError Handling:
Purpose: Integrity verification for ModuleCheck mode
Processing:
The module handles two types of agent context updates:
Delta Operations (MetadataDelta, GroupDelta):
agent.* fields on all existing documents for that agentDisaster Recovery (MetadataCheck, GroupCheck):
To prevent race conditions between inventory updates and metadata/groups updates:
ownsAgentLock flagThis ensures that inventory documents receive correct agent context without conflicts.
flowchart TD
subgraph WazuhManager[" "]
subgraph WazuhModulesM[" "]
subgraph InventorySync[" "]
AgentSessions["Agent Sessions"]
LocalStorage["RocksDB Storage"]
WorkersQueue["Workers Queue"]
IndexerQueue["Indexer Queue"]
end
D@{ shape: braces, label: "Inventory Sync" } --> InventorySync
IndexerConnector["Indexer Connector"]
InventorySync -- "Bulk Operations" --> IndexerConnector
end
C@{ shape: braces, label: "Wazuh Modules" } --> WazuhModulesM
Router -- "FlatBuffer Messages" --> InventorySync
InventorySync -- "ACK / Status" --> Router
end
B@{ shape: braces, label: "Wazuh Manager" } --> WazuhManager
IndexerConnector -- "HTTP Bulk API" --> WazuhIndexer
subgraph WazuhAgent["Wazuh Agent"]
subgraph WazuhModulesA[" "]
Syscollector["Syscollector"]
FIM["FIM Module"]
end
A@{ shape: braces, label: "Wazuh Modules" } --> WazuhModulesA
Syscollector -- "Inventory States" --> Router
FIM -- "FIM States" --> Router
end
WazuhIndexer["Wazuh Indexer"]
WazuhDashboard["Wazuh Dashboard"]
WazuhDashboard -- "/wazuh-states-*/_search" --> WazuhIndexer
The module provides robust session lifecycle management: