1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515#
16+ import json
17+
1618from .base_event_ingestor import EventIngestor
1719import requests
1820from time import time , mktime
@@ -52,7 +54,7 @@ def ingest(self, events, thread_count):
5254 """
5355 Ingests event and metric data into splunk using HEC token via event endpoint.
5456
55- For batch ingestion of events in a single request at event endpoint provide a list of event dict to be ingested.
57+ For batch ingestion of events in a single request at event endpoint provide stacked events one after the other to be ingested.
5658
5759 The format of dictionary for ingesting a single event::
5860
@@ -63,22 +65,20 @@ def ingest(self, events, thread_count):
6365 "event": "event_str"
6466 }
6567
66- The format of dictionary for ingesting a batch of events::
67-
68- [
69- {
70- "sourcetype": "sample_HEC",
71- "source": "sample_source",
72- "host": "sample_host",
73- "event": "event_str1"
74- },
75- {
76- "sourcetype": "sample_HEC",
77- "source": "sample_source",
78- "host": "sample_host",
79- "event": "event_str2"
80- },
81- ]
68+ The format for ingesting a batch of events::
69+
70+ {
71+ "sourcetype": "sample_HEC",
72+ "source": "sample_source",
73+ "host": "sample_host",
74+ "event": "event_str1"
75+ }
76+ {
77+ "sourcetype": "sample_HEC",
78+ "source": "sample_source",
79+ "host": "sample_host",
80+ "event": "event_str2"
81+ }
8282
8383 Args:
8484 events (list): List of events (SampleEvent) to be ingested
@@ -115,20 +115,21 @@ def ingest(self, events, thread_count):
115115
116116 def __ingest (self , data ):
117117 try :
118+ batch_data = "\n " .join (json .dumps (obj ) for obj in data )
118119 LOGGER .info (
119120 "Making a HEC event request with the following params:\n hec_uri:{}\n headers:{}" .format (
120121 str (self .hec_uri ), str (self .session_headers )
121122 )
122123 )
123124 LOGGER .debug (
124125 "Creating the following sample event to be ingested via HEC event endoipnt:{}" .format (
125- str (data )
126+ str (batch_data )
126127 )
127128 )
128129 response = requests .post ( # nosemgrep: splunk.disabled-cert-validation
129130 "{}/{}" .format (self .hec_uri , "event" ),
130131 auth = None ,
131- json = data ,
132+ data = batch_data ,
132133 headers = self .session_headers ,
133134 verify = False ,
134135 )
0 commit comments