grafana/pkg/services/provisioning/provisioning.go

48 lines
1.3 KiB
Go
Raw Normal View History

package provisioning
import (
"context"
"fmt"
"path"
"github.com/grafana/grafana/pkg/registry"
2018-11-28 08:35:42 -06:00
"github.com/grafana/grafana/pkg/services/provisioning/alert_notifications"
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
"github.com/grafana/grafana/pkg/services/provisioning/datasources"
"github.com/grafana/grafana/pkg/setting"
)
func init() {
registry.RegisterService(&ProvisioningService{})
}
type ProvisioningService struct {
Cfg *setting.Cfg `inject:""`
}
func (ps *ProvisioningService) Init() error {
datasourcePath := path.Join(ps.Cfg.ProvisioningPath, "datasources")
if err := datasources.Provision(datasourcePath); err != nil {
return fmt.Errorf("Datasource provisioning error: %v", err)
}
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)
}
return nil
}
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
}
<-ctx.Done()
return ctx.Err()
}