mongoose.forward.webhook
- class mongoose.forward.webhook.WebhookFormatter[source]
Bases:
BaseFormatterFormats network data for webhook consumption.
This class handles the conversion of network models (DPI, Alert, Flow) into JSON-serializable dictionaries. 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.
- Security considerations:
The formatter performs a JSON round-trip to ensure data consistency and safety before it is sent over the network.
It uses a custom default for serialization to prevent failures on complex types, ensuring robust operation even with unexpected data.
- class mongoose.forward.webhook.WebhookForwarder(config)[source]
Bases:
BaseForwarderForwards network events to a remote webhook asynchronously.
Subscribes to specified topics and sends data to a configured URL using HTTP POST. It manages its own background worker thread for non-blocking operation and supports various authentication methods and retry logic.
Notes
Authentication: Supports Basic Auth, Bearer tokens, and custom headers. Credentials should be provided via WebhookConfiguration using SecretStr to prevent accidental leakage in logs.
SSL/TLS: SSL certificate verification is enabled by default (verify_ssl=True). It is highly recommended to keep this enabled in production.
Sensitive data: While Mongoose normalizes data, users should ensure the webhook endpoint is secured (HTTPS) as network event data may contain sensitive infrastructure information (IPs, ports, protocol details).
Isolation: Each forwarder uses a dedicated requests.Session for connection pooling and to keep authentication headers isolated.
- Forwarding modes:
immediate: Sends data as soon as it is received.
bulk: Accumulates data up to bulk_size or until a timeout occurs.
periodic: Sends data at a fixed periodic_interval at a maximum periodic_rate.
- __init__(config)[source]
Initialize the WebhookForwarder.
- Parameters:
config (WebhookForwarderConfiguration) – A WebhookConfiguration instance defining the destination and security settings.