2016-06-11 03:13:33 -05:00
|
|
|
package alerting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/bus"
|
2019-05-14 01:15:05 -05:00
|
|
|
"github.com/grafana/grafana/pkg/models"
|
2016-06-11 03:13:33 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
bus.AddHandler("alerting", updateDashboardAlerts)
|
2016-11-24 02:50:35 -06:00
|
|
|
bus.AddHandler("alerting", validateDashboardAlerts)
|
|
|
|
}
|
|
|
|
|
2019-05-14 01:15:05 -05:00
|
|
|
func validateDashboardAlerts(cmd *models.ValidateDashboardAlertsCommand) error {
|
2018-11-05 07:25:19 -06:00
|
|
|
extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId, cmd.User)
|
2016-11-24 02:50:35 -06:00
|
|
|
|
2018-03-28 04:31:33 -05:00
|
|
|
return extractor.ValidateAlerts()
|
2016-06-11 03:13:33 -05:00
|
|
|
}
|
|
|
|
|
2019-05-14 01:15:05 -05:00
|
|
|
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,
|
2016-06-11 03:13:33 -05:00
|
|
|
}
|
|
|
|
|
2018-11-05 07:25:19 -06:00
|
|
|
extractor := NewDashAlertExtractor(cmd.Dashboard, cmd.OrgId, cmd.User)
|
2016-06-11 03:13:33 -05:00
|
|
|
|
2018-03-28 04:31:33 -05:00
|
|
|
alerts, err := extractor.GetAlerts()
|
|
|
|
if err != nil {
|
2016-06-11 03:13:33 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-03-28 04:31:33 -05:00
|
|
|
saveAlerts.Alerts = alerts
|
2016-06-11 03:13:33 -05:00
|
|
|
|
2018-03-28 04:31:33 -05:00
|
|
|
return bus.Dispatch(&saveAlerts)
|
2016-06-11 03:13:33 -05:00
|
|
|
}
|