Skip to content

Commit

Permalink
out_es: check if host contains port number
Browse files Browse the repository at this point in the history
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

This patch is to check if a port number is contained or not.

Signed-off-by: Takahiro Yamashita <[email protected]>
  • Loading branch information
nokute78 authored and edsiper committed Sep 23, 2023
1 parent 8f408d9 commit de6010e
Showing 1 changed file with 19 additions and 0 deletions.
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

0 comments on commit de6010e

Please sign in to comment.