From ae966e63f1f8cdf1b53ef2e83bbd2b8dc6812534 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Thu, 13 Jun 2024 11:10:13 +0800 Subject: [PATCH] elk/handler: add index parameter to interface /plugin/elk/api/search --- elk/handler/search.go | 3 ++- elk/kibanaClient/7_17_16/client.go | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/elk/handler/search.go b/elk/handler/search.go index 8c80d80f..f7e5f153 100644 --- a/elk/handler/search.go +++ b/elk/handler/search.go @@ -15,6 +15,7 @@ import ( ) func SearchHandle(ctx *gin.Context) { + index := ctx.Query("index") defer ctx.Request.Body.Close() if elasticClient.Global_elastic.Client == nil { err := errors.Errorf("%+v **warn**0", "global_elastic is null") @@ -24,7 +25,7 @@ func SearchHandle(ctx *gin.Context) { } resp, err := elasticClient.Global_elastic.Client.Search( elasticClient.Global_elastic.Client.Search.WithContext(context.Background()), - elasticClient.Global_elastic.Client.Search.WithIndex(".ds-logs-system.syslog-default-2024.06.04-000001"), + elasticClient.Global_elastic.Client.Search.WithIndex(index), elasticClient.Global_elastic.Client.Search.WithBody(ctx.Request.Body), elasticClient.Global_elastic.Client.Search.WithTrackTotalHits(true), elasticClient.Global_elastic.Client.Search.WithPretty(), diff --git a/elk/kibanaClient/7_17_16/client.go b/elk/kibanaClient/7_17_16/client.go index 3e57673f..edc96180 100644 --- a/elk/kibanaClient/7_17_16/client.go +++ b/elk/kibanaClient/7_17_16/client.go @@ -25,8 +25,14 @@ type KibanaClient_v7 struct { } func InitKibanaClient() { + protocol := "" + if conf.Global_Config.Elk.Https_enabled { + protocol = "https" + } else { + protocol = "http" + } cfg := &kibana.ClientConfig{ - Protocol: "https", + Protocol: protocol, Host: conf.Global_Config.Kibana.Addr, Username: conf.Global_Config.Kibana.Username, Password: conf.Global_Config.Kibana.Password, -- Gitee