From 59ff5bcc00f501840a4f81ed1c542ee5f7edb634 Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Sat, 28 Sep 2024 10:14:43 +0300 Subject: [PATCH] out_datadog: custom added ability ot set custom HTTP headers Signed-off-by: Andrii Chubatiuk --- plugins/out_datadog/datadog.c | 19 ++++++++++++++++++- plugins/out_datadog/datadog.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/out_datadog/datadog.c b/plugins/out_datadog/datadog.c index 86ff6b51a2a..e5c6621f880 100644 --- a/plugins/out_datadog/datadog.c +++ b/plugins/out_datadog/datadog.c @@ -368,6 +368,10 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk, size_t b_sent; int ret = FLB_ERROR; int compressed = FLB_FALSE; + struct mk_list *head; + struct flb_config_map_val *mv; + struct flb_slist_entry *key = NULL; + struct flb_slist_entry *val = NULL; /* Get upstream connection */ upstream_conn = flb_upstream_conn_get(ctx->upstream); @@ -427,7 +431,15 @@ static void cb_datadog_flush(struct flb_event_chunk *event_chunk, if (compressed == FLB_TRUE) { flb_http_set_content_encoding_gzip(client); } - /* TODO: Append other headers if needed*/ + + flb_config_map_foreach(head, mv, ctx->headers) { + key = mk_list_entry_first(mv->val.list, struct flb_slist_entry, _head); + val = mk_list_entry_last(mv->val.list, struct flb_slist_entry, _head); + + flb_http_add_header(client, + key->str, flb_sds_len(key->str), + val->str, flb_sds_len(val->str)); + } /* finaly send the query */ ret = flb_http_do(client, &b_sent); @@ -493,6 +505,11 @@ static struct flb_config_map config_map[] = { "compresses the payload in GZIP format, " "Datadog supports and recommends setting this to 'gzip'." }, + { + FLB_CONFIG_MAP_SLIST_1, "header", NULL, + FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_out_datadog, headers), + "Add a HTTP header key/value pair. Multiple headers can be set" + }, { FLB_CONFIG_MAP_STR, "apikey", NULL, 0, FLB_TRUE, offsetof(struct flb_out_datadog, api_key), diff --git a/plugins/out_datadog/datadog.h b/plugins/out_datadog/datadog.h index 0fa44997029..60e7a676c72 100644 --- a/plugins/out_datadog/datadog.h +++ b/plugins/out_datadog/datadog.h @@ -59,6 +59,7 @@ struct flb_out_datadog { flb_sds_t api_key; int include_tag_key; flb_sds_t tag_key; + struct mk_list *headers; bool remap; /* final result */