2017-10-23 02:02:55 -05:00
|
|
|
package provisioning
|
|
|
|
|
|
|
|
import (
|
2017-11-23 04:29:06 -06:00
|
|
|
"context"
|
2018-05-01 08:51:15 -05:00
|
|
|
"fmt"
|
2017-12-07 08:14:57 -06:00
|
|
|
"path"
|
2017-11-23 04:29:06 -06:00
|
|
|
|
2018-05-01 08:51:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/registry"
|
2018-11-28 08:35:42 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/alert_notifications"
|
2017-11-30 10:43:28 -06:00
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
|
|
|
|
"github.com/grafana/grafana/pkg/services/provisioning/datasources"
|
2018-05-01 08:51:15 -05:00
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
2017-10-23 02:02:55 -05:00
|
|
|
)
|
|
|
|
|
2018-05-01 08:51:15 -05:00
|
|
|
func init() {
|
|
|
|
registry.RegisterService(&ProvisioningService{})
|
|
|
|
}
|
|
|
|
|
|
|
|
type ProvisioningService struct {
|
|
|
|
Cfg *setting.Cfg `inject:""`
|
|
|
|
}
|
2017-12-07 08:14:57 -06:00
|
|
|
|
2018-05-01 08:51:15 -05:00
|
|
|
func (ps *ProvisioningService) Init() error {
|
|
|
|
datasourcePath := path.Join(ps.Cfg.ProvisioningPath, "datasources")
|
2017-11-30 10:43:28 -06:00
|
|
|
if err := datasources.Provision(datasourcePath); err != nil {
|
2018-05-01 08:51:15 -05:00
|
|
|
return fmt.Errorf("Datasource provisioning error: %v", err)
|
2017-11-23 04:29:06 -06:00
|
|
|
}
|
|
|
|
|
2018-11-28 08:35:42 -06:00
|
|
|
alertNotificationsPath := path.Join(ps.Cfg.ProvisioningPath, "alert_notifications")
|
|
|
|
if err := alert_notifications.Provision(alertNotificationsPath); err != nil {
|
|
|
|
return fmt.Errorf("Alert notification provisioning error: %v", err)
|
|
|
|
}
|
|
|
|
|
2018-05-01 08:51:15 -05:00
|
|
|
return nil
|
2017-11-23 04:29:06 -06:00
|
|
|
}
|
|
|
|
|
2018-05-01 08:51:15 -05:00
|
|
|
func (ps *ProvisioningService) Run(ctx context.Context) error {
|
|
|
|
dashboardPath := path.Join(ps.Cfg.ProvisioningPath, "dashboards")
|
|
|
|
dashProvisioner := dashboards.NewDashboardProvisioner(dashboardPath)
|
|
|
|
|
|
|
|
if err := dashProvisioner.Provision(ctx); err != nil {
|
|
|
|
return err
|
2017-11-23 04:29:06 -06:00
|
|
|
}
|
2018-05-01 08:51:15 -05:00
|
|
|
|
|
|
|
<-ctx.Done()
|
|
|
|
return ctx.Err()
|
2017-10-23 02:02:55 -05:00
|
|
|
}
|