mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 11:20:27 -06:00
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package provisioning
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"path"
|
|
|
|
"github.com/grafana/grafana/pkg/registry"
|
|
"github.com/grafana/grafana/pkg/services/provisioning/dashboards"
|
|
"github.com/grafana/grafana/pkg/services/provisioning/datasources"
|
|
"github.com/grafana/grafana/pkg/services/provisioning/notifiers"
|
|
"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)
|
|
}
|
|
|
|
alertNotificationsPath := path.Join(ps.Cfg.ProvisioningPath, "notifiers")
|
|
if err := notifiers.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()
|
|
}
|