feat(alerting): add support for deleting alert rules
This commit is contained in:
+19
-1
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func ValidateOrgAlert(c *middleware.Context) {
|
||||
id := c.ParamsInt64(":id")
|
||||
id := c.ParamsInt64(":alertId")
|
||||
query := models.GetAlertByIdQuery{Id: id}
|
||||
|
||||
if err := bus.Dispatch(&query); err != nil {
|
||||
@@ -98,6 +98,24 @@ func GetAlert(c *middleware.Context) Response {
|
||||
return Json(200, &query.Result)
|
||||
}
|
||||
|
||||
// DEL /api/alerts/:id
|
||||
func DelAlert(c *middleware.Context) Response {
|
||||
alertId := c.ParamsInt64(":alertId")
|
||||
|
||||
if alertId == 0 {
|
||||
return ApiError(401, "Failed to parse alertid", nil)
|
||||
}
|
||||
|
||||
cmd := models.DeleteAlertCommand{AlertId: alertId}
|
||||
|
||||
if err := bus.Dispatch(&cmd); err != nil {
|
||||
return ApiError(500, "Failed to delete alert", err)
|
||||
}
|
||||
|
||||
var resp = map[string]interface{}{"alertId": alertId}
|
||||
return Json(200, resp)
|
||||
}
|
||||
|
||||
// GET /api/alerts/state/:id
|
||||
func GetAlertState(c *middleware.Context) Response {
|
||||
alertId := c.ParamsInt64(":alertId")
|
||||
|
||||
+2
-1
@@ -243,7 +243,8 @@ func Register(r *macaron.Macaron) {
|
||||
r.Put("/events/:alertId", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
|
||||
r.Get("/changes", wrap(GetAlertChanges))
|
||||
r.Get("/", wrap(GetAlerts))
|
||||
r.Get("/:id", ValidateOrgAlert, wrap(GetAlert))
|
||||
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
||||
r.Delete("/:alertId", ValidateOrgAlert, wrap(DelAlert))
|
||||
})
|
||||
|
||||
r.Get("/alerts-dashboard/:dashboardId", wrap(GetAlertsForDashboard))
|
||||
|
||||
Reference in New Issue
Block a user