From 3b7beb31160253a0edc3ef3da699928688d2eaa5 Mon Sep 17 00:00:00 2001 From: AndrewChubatiuk Date: Tue, 11 Jun 2024 10:11:03 +0300 Subject: [PATCH] out_es: custom added ability ot set custom HTTP headers Signed-off-by: AndrewChubatiuk --- plugins/out_es/es.c | 22 ++++++++++++++++++++++ plugins/out_es/es.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/plugins/out_es/es.c b/plugins/out_es/es.c index 5d6a428992a..bacd18207ce 100644 --- a/plugins/out_es/es.c +++ b/plugins/out_es/es.c @@ -810,6 +810,10 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk, struct flb_http_client *c; flb_sds_t signature = NULL; 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 */ u_conn = flb_upstream_conn_get(ctx->u); @@ -867,6 +871,16 @@ static void cb_es_flush(struct flb_event_chunk *event_chunk, flb_http_add_header(c, "Content-Type", 12, "application/x-ndjson", 20); + /* Arbitrary additional headers */ + 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(c, + key->str, flb_sds_len(key->str), + val->str, flb_sds_len(val->str)); + } + if (ctx->http_user && ctx->http_passwd) { flb_http_basic_auth(c, ctx->http_user, ctx->http_passwd); } @@ -1016,6 +1030,14 @@ static struct flb_config_map config_map[] = { "Password for user defined in HTTP_User" }, + /* Arbitrary HTTP headers */ + { + FLB_CONFIG_MAP_SLIST_1, "header", NULL, + FLB_CONFIG_MAP_MULT, FLB_TRUE, offsetof(struct flb_elasticsearch, headers), + "Add a HTTP header key/value pair. Multiple headers can be set" + }, + + /* HTTP Compression */ { FLB_CONFIG_MAP_STR, "compress", NULL, diff --git a/plugins/out_es/es.h b/plugins/out_es/es.h index 67efc9e0442..c8ae5983edd 100644 --- a/plugins/out_es/es.h +++ b/plugins/out_es/es.h @@ -42,6 +42,9 @@ struct flb_elasticsearch { char *type; char suppress_type_name; + /* Arbitrary HTTP headers */ + struct mk_list *headers; + /* HTTP Auth */ char *http_user; char *http_passwd;