mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): make it possible to pause from alert tab
This commit is contained in:
@@ -252,13 +252,17 @@ func NotificationTest(c *middleware.Context, dto dtos.NotificationTestCommand) R
|
||||
return ApiSuccess("Test notification sent")
|
||||
}
|
||||
|
||||
//POST /api/alerts/:alertId/pause
|
||||
func PauseAlert(c *middleware.Context, cmd models.PauseAlertCommand) Response {
|
||||
cmd.OrgId = c.OrgId
|
||||
cmd.AlertId = c.ParamsInt64(":alertId")
|
||||
//POST /api/pause-alert
|
||||
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)
|
||||
}
|
||||
|
||||
if cmd.AlertId == 0 {
|
||||
return ApiError(400, "Missing alert id", nil)
|
||||
cmd := models.PauseAlertCommand{
|
||||
OrgId: c.OrgId,
|
||||
AlertId: alertId,
|
||||
Paused: dto.Paused,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
@@ -278,11 +282,7 @@ func PauseAlert(c *middleware.Context, cmd models.PauseAlertCommand) Response {
|
||||
return Json(200, result)
|
||||
}
|
||||
|
||||
func getAlertIdForRequest(c *middleware.Context) (int64, error) {
|
||||
alertId := c.QueryInt64("alertId")
|
||||
panelId := c.QueryInt64("panelId")
|
||||
dashboardId := c.QueryInt64("dashboardId")
|
||||
|
||||
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")
|
||||
}
|
||||
@@ -290,7 +290,7 @@ func getAlertIdForRequest(c *middleware.Context) (int64, error) {
|
||||
if alertId == 0 {
|
||||
//fetch alertId
|
||||
query := models.GetAlertsQuery{
|
||||
OrgId: c.OrgId,
|
||||
OrgId: orgId,
|
||||
DashboardId: dashboardId,
|
||||
PanelId: panelId,
|
||||
}
|
||||
|
||||
@@ -252,12 +252,14 @@ func Register(r *macaron.Macaron) {
|
||||
|
||||
r.Group("/alerts", func() {
|
||||
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("/", 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() {
|
||||
|
||||
@@ -63,4 +63,5 @@ type PauseAlertCommand struct {
|
||||
AlertId int64 `json:"alertId"`
|
||||
DashboardId int64 `json:"dashboardId"`
|
||||
PanelId int64 `json:"panelId"`
|
||||
Paused bool `json:"paused"`
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ type SaveAlertsCommand struct {
|
||||
|
||||
type PauseAlertCommand struct {
|
||||
OrgId int64
|
||||
AlertId int64 `json:"alertId"`
|
||||
Paused bool `json:"paused"`
|
||||
AlertId int64
|
||||
Paused bool
|
||||
}
|
||||
|
||||
type SetAlertStateCommand struct {
|
||||
|
||||
@@ -47,10 +47,11 @@ export class AlertListCtrl {
|
||||
var alert = _.find(this.alerts, {id: alertId});
|
||||
|
||||
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.stateModel = alertDef.getStateDisplayModel(result.state);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user