Skip to content

Commit f261173

Browse files
out_datadog: custom added ability ot set custom HTTP headers
1 parent 41b90b7 commit f261173

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

plugins/out_datadog/datadog.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk,
368368
size_t b_sent;
369369
int ret = FLB_ERROR;
370370
int compressed = FLB_FALSE;
371+
struct mk_list *head;
372+
struct flb_config_map_val *mv;
373+
struct flb_slist_entry *key = NULL;
374+
struct flb_slist_entry *val = NULL;
371375

372376
/* Get upstream connection */
373377
upstream_conn = flb_upstream_conn_get(ctx->upstream);
@@ -427,7 +431,15 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk,
427431
if (compressed == FLB_TRUE) {
428432
flb_http_set_content_encoding_gzip(client);
429433
}
430-
/* TODO: Append other headers if needed*/
434+
435+
flb_config_map_foreach(head, mv, ctx->headers) {
436+
key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head);
437+
val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head);
438+
439+
flb_http_add_header(client,
440+
key->str, flb_sds_len(key->str),
441+
val->str, flb_sds_len(val->str));
442+
}
431443

432444
/* finaly send the query */
433445
ret = flb_http_do(client, &b_sent);
@@ -493,6 +505,11 @@ static struct flb_config_map config_map[] = {
493505
"compresses the payload in GZIP format, "
494506
"Datadog supports and recommends setting this to 'gzip'."
495507
},
508+
{
509+
FLB_CONFIG_MAP_SLIST_1, "header", NULL,
510+
FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_out_datadog, headers),
511+
"Add a HTTP header key/value pair. Multiple headers can be set"
512+
},
496513
{
497514
FLB_CONFIG_MAP_STR, "apikey", NULL,
498515
0, FLB_TRUE, offsetof(struct flb_out_datadog, api_key),

plugins/out_datadog/datadog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct flb_out_datadog {
5959
flb_sds_t api_key;
6060
int include_tag_key;
6161
flb_sds_t tag_key;
62+
struct mk_list *headers;
6263
bool remap;
6364

6465
/* final result */

0 commit comments

Comments
 (0)