From 4f3f4f8d5965f423f9ea2dfe0aad8f602595a023 Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Fri, 31 May 2024 10:47:07 +0800 Subject: [PATCH] initialize kibanaclient module --- elk/elasticagent/elasticagent.go | 2 -- elk/kibanaClient/client.go | 39 ++++++++++++++++++++++++++++++++ elk/main.go | 6 +++++ 3 files changed, 45 insertions(+), 2 deletions(-) delete mode 100644 elk/elasticagent/elasticagent.go create mode 100644 elk/kibanaClient/client.go diff --git a/elk/elasticagent/elasticagent.go b/elk/elasticagent/elasticagent.go deleted file mode 100644 index a7278b24..00000000 --- a/elk/elasticagent/elasticagent.go +++ /dev/null @@ -1,2 +0,0 @@ -package elasticagent - diff --git a/elk/kibanaClient/client.go b/elk/kibanaClient/client.go new file mode 100644 index 00000000..eb074105 --- /dev/null +++ b/elk/kibanaClient/client.go @@ -0,0 +1,39 @@ +package kibanaClient + +import ( + "context" + "errors" + + "gitee.com/openeuler/PilotGo-plugin-elk/conf" + "gitee.com/openeuler/PilotGo-plugin-elk/errormanager" + "gitee.com/openeuler/PilotGo-plugin-elk/pluginclient" + "github.com/elastic/elastic-agent-libs/kibana" +) + +var Global_kibana *KibanaClient + +type KibanaClient struct { + Client *kibana.Client + Ctx context.Context +} + +func InitKibanaClient() { + cfg := &kibana.ClientConfig{ + Protocol: "http", + Host: conf.Global_Config.Kibana.Addr, + Username: conf.Global_Config.Kibana.Username, + Password: conf.Global_Config.Kibana.Password, + } + + ki_client, err := kibana.NewClientWithConfig(cfg, "", "", "", "") + if err != nil { + err = errors.New("failed to init kibana client **errstackfatal**0") // err top + errormanager.ErrorTransmit(pluginclient.Global_Context, err, true) + return + } + + Global_kibana = &KibanaClient{ + Client: ki_client, + Ctx: context.Background(), + } +} diff --git a/elk/main.go b/elk/main.go index e6cdba02..341a0cd2 100644 --- a/elk/main.go +++ b/elk/main.go @@ -5,6 +5,7 @@ import ( "gitee.com/openeuler/PilotGo-plugin-elk/db" "gitee.com/openeuler/PilotGo-plugin-elk/errormanager" "gitee.com/openeuler/PilotGo-plugin-elk/handler" + "gitee.com/openeuler/PilotGo-plugin-elk/kibanaClient" "gitee.com/openeuler/PilotGo-plugin-elk/logger" "gitee.com/openeuler/PilotGo-plugin-elk/pluginclient" "gitee.com/openeuler/PilotGo-plugin-elk/signal" @@ -42,6 +43,11 @@ func main() { */ db.InitDB() + /* + init kibana client + */ + kibanaClient.InitKibanaClient() + /* 终止进程信号监听 */ -- Gitee