@@ -269,6 +269,7 @@ static int pack_map_meta(struct flb_splunk *ctx,
269269 char * tag , int tag_len )
270270{
271271 int index_key_set = FLB_FALSE ;
272+ int source_key_set = FLB_FALSE ;
272273 int sourcetype_key_set = FLB_FALSE ;
273274 flb_sds_t str ;
274275 struct mk_list * head ;
@@ -294,11 +295,13 @@ static int pack_map_meta(struct flb_splunk *ctx,
294295 }
295296 }
296297
297- /* event source */
298- if (ctx -> event_source ) {
299- str = flb_ra_translate (ctx -> ra_event_source , tag , tag_len ,
298+
299+ /* event source (key lookup) */
300+ if (ctx -> event_source_key ) {
301+ str = flb_ra_translate (ctx -> ra_event_source_key , tag , tag_len ,
300302 map , NULL );
301303 if (str ) {
304+ /* source_key was found */
302305 if (flb_sds_len (str ) > 0 ) {
303306 flb_mp_map_header_append (mh );
304307 msgpack_pack_str (mp_pck , sizeof (FLB_SPLUNK_DEFAULT_EVENT_SOURCE ) - 1 );
@@ -307,11 +310,25 @@ static int pack_map_meta(struct flb_splunk *ctx,
307310 sizeof (FLB_SPLUNK_DEFAULT_EVENT_SOURCE ) - 1 );
308311 msgpack_pack_str (mp_pck , flb_sds_len (str ));
309312 msgpack_pack_str_body (mp_pck , str , flb_sds_len (str ));
313+ source_key_set = FLB_TRUE ;
310314 }
311315 flb_sds_destroy (str );
312316 }
317+ /* If not found, it will fallback to the value set in event_source */
318+ }
319+
320+ if (source_key_set == FLB_FALSE && ctx -> event_source ) {
321+ flb_mp_map_header_append (mh );
322+ msgpack_pack_str (mp_pck , sizeof (FLB_SPLUNK_DEFAULT_EVENT_SOURCE ) - 1 );
323+ msgpack_pack_str_body (mp_pck ,
324+ FLB_SPLUNK_DEFAULT_EVENT_SOURCE ,
325+ sizeof (FLB_SPLUNK_DEFAULT_EVENT_SOURCE ) - 1 );
326+ msgpack_pack_str (mp_pck , flb_sds_len (ctx -> event_source ));
327+ msgpack_pack_str_body (mp_pck ,
328+ ctx -> event_source , flb_sds_len (ctx -> event_source ));
313329 }
314330
331+
315332 /* event sourcetype (key lookup) */
316333 if (ctx -> event_sourcetype_key ) {
317334 str = flb_ra_translate (ctx -> ra_event_sourcetype_key , tag , tag_len ,
@@ -1117,6 +1134,13 @@ static struct flb_config_map config_map[] = {
11171134 "Set the source value to assign to the event data."
11181135 },
11191136
1137+ {
1138+ FLB_CONFIG_MAP_STR , "event_source_key" , NULL ,
1139+ 0 , FLB_TRUE , offsetof(struct flb_splunk , event_source_key ),
1140+ "Set a record key that will populate 'source'. If the key is found, it will "
1141+ "have precedence over the value set in 'event_source'."
1142+ },
1143+
11201144 {
11211145 FLB_CONFIG_MAP_STR , "event_sourcetype" , NULL ,
11221146 0 , FLB_TRUE , offsetof(struct flb_splunk , event_sourcetype ),
0 commit comments