diff --git a/elk/elasticagent/elasticagent.go b/elk/elasticagent/elasticagent.go deleted file mode 100644 index a7278b2409c288fda7860ea99a93b91a019ea896..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..eb074105b1f4d03435912785fbf24b97261c5f6d --- /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 e6cdba022cbb60b8b73a11b8075201718bbb023b..341a0cd253f662a56632286090d9da49c034b1b7 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() + /* 终止进程信号监听 */