Commit df2b2e30 by Carl Bergquist Committed by Torkel Ödegaard

feat(alerting): validate alerts before saving dashboard (#6691)

ref #6576
parent 223f2320
......@@ -120,6 +120,16 @@ func PostDashboard(c *middleware.Context, cmd m.SaveDashboardCommand) Response {
cmd.UserId = c.UserId
}
validateAlertsCmd := alerting.ValidateDashboardAlertsCommand{
OrgId: c.OrgId,
UserId: c.UserId,
Dashboard: cmd.Result,
}
if err := bus.Dispatch(&validateAlertsCmd); err != nil {
return ApiError(500, "Invalid alert data. Cannot save dashboard", err)
}
dash := cmd.GetDashboardModel()
if dash.Id == 0 {
limitReached, err := middleware.QuotaReached(c, "dashboard")
......
......@@ -11,8 +11,25 @@ type UpdateDashboardAlertsCommand struct {
Dashboard *m.Dashboard
}
type ValidateDashboardAlertsCommand struct {
UserId int64
OrgId int64
Dashboard *m.Dashboard
}
func init() {
bus.AddHandler("alerting", updateDashboardAlerts)
bus.AddHandler("alerting", validateDashboardAlerts)
}
func validateDashboardAlerts(cmd *ValidateDashboardAlertsCommand) error {
extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId)
if _, err := extractor.GetAlerts(); err != nil {
return err
}
return nil
}
func updateDashboardAlerts(cmd *UpdateDashboardAlertsCommand) error {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment