|
|
|
@ -252,33 +252,30 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R |
|
|
|
|
return ApiSuccess("Test notification sent") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getAlertIdForRequest(c *middleware.Context) (int64, error) { |
|
|
|
|
alertId := c.QueryInt64("alertId") |
|
|
|
|
panelId := c.QueryInt64("panelId") |
|
|
|
|
dashboardId := c.QueryInt64("dashboardId") |
|
|
|
|
|
|
|
|
|
if alertId == 0 && dashboardId == 0 && panelId == 0 { |
|
|
|
|
return 0, fmt.Errorf("Missing alertId or dashboardId and panelId") |
|
|
|
|
//POST /api/:alertId/pause
|
|
|
|
|
func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response { |
|
|
|
|
cmd := models.PauseAlertCommand{ |
|
|
|
|
OrgId: c.OrgId, |
|
|
|
|
AlertId: c.ParamsInt64("alertId"), |
|
|
|
|
Paused: dto.Paused, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if alertId == 0 { |
|
|
|
|
//fetch alertId
|
|
|
|
|
query := models.GetAlertsQuery{ |
|
|
|
|
OrgId: c.OrgId, |
|
|
|
|
DashboardId: dashboardId, |
|
|
|
|
PanelId: panelId, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := bus.Dispatch(&query); err != nil { |
|
|
|
|
return 0, err |
|
|
|
|
} |
|
|
|
|
if err := bus.Dispatch(&cmd); err != nil { |
|
|
|
|
return ApiError(500, "", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if len(query.Result) != 1 { |
|
|
|
|
return 0, fmt.Errorf("PanelId is not unique on dashboard") |
|
|
|
|
} |
|
|
|
|
var response models.AlertStateType = models.AlertStateNoData |
|
|
|
|
pausedState := "un paused" |
|
|
|
|
if cmd.Paused { |
|
|
|
|
response = models.AlertStatePaused |
|
|
|
|
pausedState = "paused" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
alertId = query.Result[0].Id |
|
|
|
|
result := map[string]interface{}{ |
|
|
|
|
"alertId": cmd.AlertId, |
|
|
|
|
"state": response, |
|
|
|
|
"message": "alert " + pausedState, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return alertId, nil |
|
|
|
|
return Json(200, result) |
|
|
|
|
} |
|
|
|
|