2017-10-23 02:02:55 -05:00
|
|
|
package provisioning
|
|
|
|
|
|
|
|
import (
|
2017-11-23 04:29:06 -06:00
|
|
|
"context"
|
2017-12-07 08:14:57 -06:00
|
|
|
"path"
|
2017-11-23 04:29:06 -06:00
|
|
|
"path/filepath"
|
|
|
|
|
2017-11-30 10:43:28 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
|
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/datasources"
|
2017-11-23 04:29:06 -06:00
|
|
|
ini "gopkg.in/ini.v1"
|
2017-10-23 02:02:55 -05:00
|
|
|
)
|
|
|
|
|
2017-11-28 07:01:10 -06:00
|
|
|
func Init(ctx context.Context, homePath string, cfg *ini.File) error {
|
2017-12-07 08:14:57 -06:00
|
|
|
provisioningPath := makeAbsolute(cfg.Section("paths").Key("provisioning").String(), homePath)
|
|
|
|
|
|
|
|
datasourcePath := path.Join(provisioningPath, "datasources")
|
2017-11-30 10:43:28 -06:00
|
|
|
if err := datasources.Provision(datasourcePath); err != nil {
|
2017-11-23 04:29:06 -06:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-12-07 08:14:57 -06:00
|
|
|
dashboardPath := path.Join(provisioningPath, "dashboards")
|
2017-11-30 10:43:28 -06:00
|
|
|
_, err := dashboards.Provision(ctx, dashboardPath)
|
2018-04-16 12:54:23 -05:00
|
|
|
return err
|
2017-11-23 04:29:06 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func makeAbsolute(path string, root string) string {
|
|
|
|
if filepath.IsAbs(path) {
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
return filepath.Join(root, path)
|
2017-10-23 02:02:55 -05:00
|
|
|
}
|