@@ -269,6 +269,7 @@ static int pack_map_meta(struct flb_splunk *ctx,
269
269
char * tag , int tag_len )
270
270
{
271
271
int index_key_set = FLB_FALSE ;
272
+ int source_key_set = FLB_FALSE ;
272
273
int sourcetype_key_set = FLB_FALSE ;
273
274
flb_sds_t str ;
274
275
struct mk_list * head ;
@@ -294,11 +295,13 @@ static int pack_map_meta(struct flb_splunk *ctx,
294
295
}
295
296
}
296
297
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 ,
300
302
map , NULL );
301
303
if (str ) {
304
+ /* source_key was found */
302
305
if (flb_sds_len (str ) > 0 ) {
303
306
flb_mp_map_header_append (mh );
304
307
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,
307
310
sizeof (FLB_SPLUNK_DEFAULT_EVENT_SOURCE ) - 1 );
308
311
msgpack_pack_str (mp_pck , flb_sds_len (str ));
309
312
msgpack_pack_str_body (mp_pck , str , flb_sds_len (str ));
313
+ source_key_set = FLB_TRUE ;
310
314
}
311
315
flb_sds_destroy (str );
312
316
}
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 ));
313
329
}
314
330
331
+
315
332
/* event sourcetype (key lookup) */
316
333
if (ctx -> event_sourcetype_key ) {
317
334
str = flb_ra_translate (ctx -> ra_event_sourcetype_key , tag , tag_len ,
@@ -1117,6 +1134,13 @@ static struct flb_config_map config_map[] = {
1117
1134
"Set the source value to assign to the event data."
1118
1135
},
1119
1136
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
+
1120
1144
{
1121
1145
FLB_CONFIG_MAP_STR , "event_sourcetype" , NULL ,
1122
1146
0 , FLB_TRUE , offsetof(struct flb_splunk , event_sourcetype ),
0 commit comments