|
|
|
@ -215,8 +215,13 @@ func DeleteAlertNotification(c *middleware.Context) Response { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func GetAlertHistory(c *middleware.Context) Response { |
|
|
|
|
alertId, err := getAlertIdForRequest(c) |
|
|
|
|
if err != nil { |
|
|
|
|
return ApiError(400, "Invalid request", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
query := &annotations.ItemQuery{ |
|
|
|
|
AlertId: c.ParamsInt64("alertId"), |
|
|
|
|
AlertId: alertId, |
|
|
|
|
Type: annotations.AlertType, |
|
|
|
|
OrgId: c.OrgId, |
|
|
|
|
Limit: c.QueryInt64("limit"), |
|
|
|
@ -244,3 +249,34 @@ func GetAlertHistory(c *middleware.Context) Response { |
|
|
|
|
|
|
|
|
|
return Json(200, result) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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 len(query.Result) != 1 { |
|
|
|
|
return 0, fmt.Errorf("PanelId is not unique on dashboard") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
alertId = query.Result[0].Id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return alertId, nil |
|
|
|
|
} |
|
|
|
|