grafana/pkg/services/alerting/commands.go

37 lines
845 B
Go
Raw Normal View History

package alerting
import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
)
func init() {
bus.AddHandler("alerting", updateDashboardAlerts)
bus.AddHandler("alerting", validateDashboardAlerts)
}
func validateDashboardAlerts(cmd *models.ValidateDashboardAlertsCommand) error {
2018-11-05 07:25:19 -06:00
extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId, cmd.User)
return extractor.ValidateAlerts()
}
func updateDashboardAlerts(cmd *models.UpdateDashboardAlertsCommand) error {
saveAlerts := models.SaveAlertsCommand{
2016-06-11 07:08:55 -05:00
OrgId: cmd.OrgId,
2018-11-05 07:25:19 -06:00
UserId: cmd.User.UserId,
2016-06-11 07:08:55 -05:00
DashboardId: cmd.Dashboard.Id,
}
2018-11-05 07:25:19 -06:00
extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId, cmd.User)
alerts, err := extractor.GetAlerts()
if err != nil {
return err
}
saveAlerts.Alerts = alerts
return bus.Dispatch(&saveAlerts)
}