Commit 80479724 by bergquist

feat(alerting): make it possible to pause from alert tab

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