mongoose.forward.file

class mongoose.forward.file.FileFormatter[source]

Bases: BaseFormatter

Formats network data for file storage.

This class handles the conversion of network models (DPI, Alert, Flow) into JSON-serializable strings. It ensures that complex types like datetime objects are correctly converted to strings and that any Pydantic-specific fields are handled according to the Pydantic version in use.

static format(data)[source]

Format the given data into a JSON string.

Parameters:

data (Any) – The model instance or data object to format.

Returns:

A JSON string representation of the data followed by a newline. Returns an empty string if formatting fails.

Return type:

str

class mongoose.forward.file.FileForwarder(config)[source]

Bases: BaseForwarder

Forwards network events to files asynchronously.

Subscribes to specified topics and appends data to a file for each topic. Files are stored in the configured output directory. It manages its own background worker thread for non-blocking operation.

Security considerations:
  • Permissions: Ensure the output directory has appropriate permissions to prevent unauthorized access to the dumped network data.

  • Disk space: Monitor disk space as files will grow indefinitely since this forwarder appends data without rotation or cleanup.

  • Sensitive data: Network event data may contain sensitive infrastructure information (IPs, ports, protocol details). Ensure the storage medium is secured.

__init__(config)[source]

Initialize the FileForwarder.

Parameters:

config (FileForwarderConfiguration) – A FileForwarderConfiguration instance.

forward(data)[source]

Write formatted data to the appropriate topic file.

Parameters:

data (Any) – The data to write (Pydantic model instance).