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: check if host contains port number #6064

Merged
merged 1 commit into from
Sep 23, 2023
Merged
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
19 changes: 19 additions & 0 deletions plugins/out_es/es_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static flb_sds_t extract_cloud_host(struct flb_elasticsearch *ctx,
char *colon;
char *region;
char *host;
char *port = NULL;
char buf[256] = {0};
char cloud_host_buf[256] = {0};
const char dollar[2] = "$";
Expand Down Expand Up @@ -71,9 +72,27 @@ static flb_sds_t extract_cloud_host(struct flb_elasticsearch *ctx,
if (host == NULL) {
return NULL;
}

/*
* Some cloud id format is "<deployment_region>$<elasticsearch_hostname>:<port>$<kibana_hostname>" .
* e.g. https://github.com/elastic/beats/blob/v8.4.1/libbeat/cloudid/cloudid_test.go#L60
*
* It means the variable "host" can contains ':' and port number.
*/
colon = strchr(host, ':');
if (colon != NULL) {
/* host contains host number */
*colon = '\0'; /* remove port number from host */
port = colon+1;
}

strcpy(cloud_host_buf, host);
strcat(cloud_host_buf, ".");
strcat(cloud_host_buf, region);
if (port != NULL) {
strcat(cloud_host_buf, ":");
strcat(cloud_host_buf, port);
}
return flb_sds_create(cloud_host_buf);
}

Expand Down