forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
dashboards.go
42 lines (33 loc) · 1023 Bytes
/
dashboards.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package dashboards
import (
"fmt"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs/elasticsearch"
)
// DashboardLoader is a subset of the Elasticsearch client API capable of
// loading the dashboards.
type DashboardLoader interface {
LoadJSON(path string, json map[string]interface{}) ([]byte, error)
CreateIndex(index string, body interface{}) (int, *elasticsearch.QueryResult, error)
}
func ImportDashboards(beatName, beatVersion string, esClient DashboardLoader, cfg *common.Config) error {
if cfg == nil || !cfg.Enabled() {
return nil
}
dashConfig := defaultDashboardsConfig
dashConfig.Beat = beatName
dashConfig.URL = fmt.Sprintf(defaultURLPattern, beatVersion)
dashConfig.SnapshotURL = fmt.Sprintf(snapshotURLPattern, beatVersion)
err := cfg.Unpack(&dashConfig)
if err != nil {
return err
}
importer, err := NewImporter(&dashConfig, esClient, nil)
if err != nil {
return nil
}
if err := importer.Import(); err != nil {
return err
}
return nil
}