mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): pausing alerts requires alert id
This commit is contained in:
parent
8b0c29b104
commit
c6cf7647ff
@ -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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user