代码拉取完成,页面将自动刷新
package dashboards
import (
"bytes"
"fmt"
"io/ioutil"
"net/url"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/setup/kibana"
)
var importAPI = "/api/kibana/dashboards/import"
type KibanaLoader struct {
client *kibana.Client
config *Config
version string
msgOutputter MessageOutputter
}
func NewKibanaLoader(cfg *common.Config, dashboardsConfig *Config, msgOutputter MessageOutputter) (*KibanaLoader, error) {
client, err := kibana.NewKibanaClient(cfg)
if err != nil {
return nil, fmt.Errorf("Error creating Kibana client: %v", err)
}
loader := KibanaLoader{
client: client,
config: dashboardsConfig,
version: client.GetVersion(),
msgOutputter: msgOutputter,
}
loader.statusMsg("Initialize the Kibana %s loader", client.GetVersion())
return &loader, nil
}
func (loader KibanaLoader) ImportIndex(file string) error {
params := url.Values{}
params.Set("force", "true") //overwrite the existing dashboards
// read json file
content, err := ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("fail to read index-pattern: %v", err)
}
return loader.client.ImportJSON(importAPI, params, bytes.NewBuffer(content))
}
func (loader KibanaLoader) ImportDashboard(file string) error {
params := url.Values{}
params.Set("force", "true") //overwrite the existing dashboards
params.Add("exclude", "index-pattern") //don't import the index pattern from the dashboards
// read json file
content, err := ioutil.ReadFile(file)
if err != nil {
return fmt.Errorf("fail to read index-pattern: %v", err)
}
return loader.client.ImportJSON(importAPI, params, bytes.NewBuffer(content))
}
func (loader KibanaLoader) Close() error {
return loader.client.Close()
}
func (loader KibanaLoader) statusMsg(msg string, a ...interface{}) {
if loader.msgOutputter != nil {
loader.msgOutputter(msg, a...)
} else {
logp.Debug("dashboards", msg, a...)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。