-
Notifications
You must be signed in to change notification settings - Fork 137
Pycti: Inconsistent Metrics Increment in Bundle Sending Process #934
Description
Description
The bundle_send metric is not incremented when using the API queue protocol in the send_stix2_bundle method of the OpenCTIConnectorHelper class. This leads to inaccurate metrics reporting, as the bundle_send_total counter remains at 0 even when bundles are successfully sent through the API protocol.
Environment
- Cloud Instance
- OpenCTI version: 6.7.3
- Other environment details: - CONNECTOR_QUEUE_PROTOCOL=api # Use api to send bundle through HTTP query to the API, amqp (default) to send to rabbit
Reproducible Steps
Current Behavior
In the send_stix2_bundle method of opencti_connector_helper.py, there are two different code paths based on the queue protocol:
-
When using the AMQP protocol (
self.queue_protocol == "amqp"), bundles are sent via the_send_bundlemethod, which correctly increments thebundle_sendmetric:self.metric.inc("bundle_send")
-
When using the API protocol (
self.queue_protocol == "api"), bundles are sent via thesend_bundle_to_apimethod, but the metric is not incremented:elif self.queue_protocol == "api": self.api.send_bundle_to_api( connector_id=self.connector_id, bundle=bundle ) # Missing: self.metric.inc("bundle_send")
Expected behaviour
The bundle_send metric should be incremented regardless of the queue protocol used, ensuring consistent and accurate metrics reporting.
Proposed Fix
Add the metric increment after the API call in the API protocol branch:
elif self.queue_protocol == "api":
self.api.send_bundle_to_api(
connector_id=self.connector_id, bundle=bundle
)
self.metric.inc("bundle_send") # Add this lineAdditional information
Affected Files
pycti/connector/opencti_connector_helper.py