Commit c6cf7647 by bergquist

feat(alerting): pausing alerts requires alert id

parent 8b0c29b1
......@@ -252,16 +252,11 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
return ApiSuccess("Test notification sent")
}
//POST /api/pause-alert
//POST /api/:alertId/pause
func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
alertId, err := getAlertIdForRequest(c.OrgId, dto.AlertId, dto.PanelId, dto.DashboardId)
if err != nil {
return ApiError(400, "Bad request", err)
}
cmd := models.PauseAlertCommand{
OrgId: c.OrgId,
AlertId: alertId,
AlertId: c.ParamsInt64("alertId"),
Paused: dto.Paused,
}
......@@ -284,30 +279,3 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
return Json(200, result)
}
func getAlertIdForRequest(orgId, alertId, panelId, dashboardId int64) (int64, error) {
if alertId == 0 && dashboardId == 0 && panelId == 0 {
return 0, fmt.Errorf("Missing alertId or dashboardId and panelId")
}
if alertId == 0 {
//fetch alertId
query := models.GetAlertsQuery{
OrgId: orgId,
DashboardId: dashboardId,
PanelId: panelId,
}
if err := bus.Dispatch(&query); err != nil {
return 0, err
}
if len(query.Result) != 1 {
return 0, fmt.Errorf("PanelId is not unique on dashboard")
}
alertId = query.Result[0].Id
}
return alertId, nil
}
......@@ -252,14 +252,12 @@ func Register(r *macaron.Macaron) {
r.Group("/alerts", func() {
r.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
r.Post("/:alertId/pause", ValidateOrgAlert, bind(dtos.PauseAlertCommand{}), wrap(PauseAlert))
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
r.Get("/", wrap(GetAlerts))
r.Get("/states-for-dashboard", wrap(GetAlertStatesForDashboard))
})
r.Post("/pause-alert", bind(dtos.PauseAlertCommand{}), wrap(PauseAlert))
r.Get("/alert-notifications", wrap(GetAlertNotifications))
r.Group("/alert-notifications", func() {
......
......@@ -60,8 +60,6 @@ type NotificationTestCommand struct {
}
type PauseAlertCommand struct {
AlertId int64 `json:"alertId"`
DashboardId int64 `json:"dashboardId"`
PanelId int64 `json:"panelId"`
Paused bool `json:"paused"`
AlertId int64 `json:"alertId"`
Paused bool `json:"paused"`
}
......@@ -47,11 +47,10 @@ export class AlertListCtrl {
var alert = _.find(this.alerts, {id: alertId});
var payload = {
paused: alert.state !== "paused",
alertId: alert.id
paused: alert.state !== "paused"
};
this.backendSrv.post(`/api/pause-alert`, payload).then(result => {
this.backendSrv.post(`/api/alerts/${alert.id}/pause`, payload).then(result => {
alert.state = result.state;
alert.stateModel = alertDef.getStateDisplayModel(result.state);
});
......
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