Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out_es: custom http headers #9416

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions plugins/out_es/es.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,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);
Expand Down Expand Up @@ -874,6 +878,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);
}
Expand Down Expand Up @@ -1023,6 +1037,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,
Expand Down
3 changes: 3 additions & 0 deletions plugins/out_es/es.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ struct flb_elasticsearch {
char *type;
int suppress_type_name;

/* Arbitrary HTTP headers */
struct mk_list *headers;

/* HTTP Auth */
char *http_user;
char *http_passwd;
Expand Down