From de6010e3f1cec4bf0e6b96bc81efac57d675967e Mon Sep 17 00:00:00 2001 From: Takahiro Yamashita Date: Sat, 17 Sep 2022 08:57:39 +0900 Subject: [PATCH] out_es: check if host contains port number Some cloud id format is "$:$" . 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 --- plugins/out_es/es_conf.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/out_es/es_conf.c b/plugins/out_es/es_conf.c index 450a3482bdc..48c8c3e2516 100644 --- a/plugins/out_es/es_conf.c +++ b/plugins/out_es/es_conf.c @@ -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] = "$"; @@ -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 "$:$" . + * 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); }