Skip to content

Commit 919cc25

Browse files
committed
fix: improve hec batch to be not a JSON array to conform specification: https://docs.splunk.com/Documentation/Splunk/latest/Data/FormateventsforHTTPEventCollector#Example_3:_Batched_data (ADDON-79329)
1 parent cd0c088 commit 919cc25

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

pytest_splunk_addon/event_ingestors/hec_event_ingestor.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import json
17+
1618
from .base_event_ingestor import EventIngestor
1719
import requests
1820
from time import time, mktime
@@ -115,20 +117,21 @@ def ingest(self, events, thread_count):
115117

116118
def __ingest(self, data):
117119
try:
120+
batch_data = "".join(json.dumps(obj) for obj in data)
118121
LOGGER.info(
119122
"Making a HEC event request with the following params:\nhec_uri:{}\nheaders:{}".format(
120123
str(self.hec_uri), str(self.session_headers)
121124
)
122125
)
123126
LOGGER.debug(
124127
"Creating the following sample event to be ingested via HEC event endoipnt:{}".format(
125-
str(data)
128+
str(batch_data)
126129
)
127130
)
128131
response = requests.post( # nosemgrep: splunk.disabled-cert-validation
129132
"{}/{}".format(self.hec_uri, "event"),
130133
auth=None,
131-
json=data,
134+
data=batch_data,
132135
headers=self.session_headers,
133136
verify=False,
134137
)

tests/unit/tests_standard_lib/test_event_ingestors/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,26 @@ def modinput_posts_sent():
6868
return [
6969
(
7070
f"POST {HEC_URI}/event",
71-
"[{"
71+
"{"
7272
'"sourcetype": "test:indextime:sourcetype:modinput_host_event_time_plugin", '
7373
'"source": "pytest-splunk-addon:modinput", '
7474
'"event": "test_modinput_1 host=modinput_host_event_time_plugin.samples_1", '
7575
'"index": "main", '
7676
'"host": "modinput_host_event_time_plugin.samples_1"'
77-
"}, {"
77+
"}{"
7878
'"sourcetype": "test:indextime:sourcetype:modinput_host_event_time_plugin", '
7979
'"source": "pytest-splunk-addon:modinput", '
8080
'"event": "test_modinput_2 host=modinput_host_event_time_plugin.samples_2", '
8181
'"index": "main", '
8282
'"host": "modinput_host_event_time_plugin.samples_2"'
83-
"}, {"
83+
"}{"
8484
'"sourcetype": "pytest_splunk_addon", '
8585
'"source": "pytest_splunk_addon:hec:event", '
8686
'"event": "fake event nothing happened", '
8787
'"index": "fake_index", '
8888
'"host": "fake host", '
8989
'"time": 1234.5678'
90-
"}]",
90+
"}",
9191
)
9292
]
9393

0 commit comments

Comments
 (0)