@@ -8,6 +8,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
"github.com/grafana/grafana/pkg/services/annotations"
|
||||
)
|
||||
|
||||
func ValidateOrgAlert(c *middleware.Context) {
|
||||
@@ -212,3 +213,34 @@ func DeleteAlertNotification(c *middleware.Context) Response {
|
||||
|
||||
return ApiSuccess("Notification deleted")
|
||||
}
|
||||
|
||||
func GetAlertHistory(c *middleware.Context) Response {
|
||||
query := &annotations.ItemQuery{
|
||||
AlertId: c.ParamsInt64("alertId"),
|
||||
Type: annotations.AlertType,
|
||||
OrgId: c.OrgId,
|
||||
Limit: c.QueryInt64("limit"),
|
||||
}
|
||||
|
||||
repo := annotations.GetRepository()
|
||||
|
||||
items, err := repo.Find(query)
|
||||
if err != nil {
|
||||
return ApiError(500, "Failed to get history for alert", err)
|
||||
}
|
||||
|
||||
var result []dtos.AlertHistory
|
||||
for _, item := range items {
|
||||
result = append(result, dtos.AlertHistory{
|
||||
AlertId: item.AlertId,
|
||||
Timestamp: item.Timestamp,
|
||||
Data: item.Data,
|
||||
NewState: item.NewState,
|
||||
Text: item.Text,
|
||||
Metric: item.Metric,
|
||||
Title: item.Title,
|
||||
})
|
||||
}
|
||||
|
||||
return Json(200, result)
|
||||
}
|
||||
|
||||
+2
-1
@@ -250,11 +250,12 @@ func Register(r *macaron.Macaron) {
|
||||
|
||||
r.Group("/alerts", func() {
|
||||
r.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
|
||||
//r.Get("/:alertId/states", wrap(GetAlertStates))
|
||||
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
||||
r.Get("/", wrap(GetAlerts))
|
||||
})
|
||||
|
||||
r.Get("/alert-history/:alertId", ValidateOrgAlert, wrap(GetAlertHistory))
|
||||
|
||||
r.Get("/alert-notifications", wrap(GetAlertNotifications))
|
||||
|
||||
r.Group("/alert-notifications", func() {
|
||||
|
||||
@@ -52,3 +52,14 @@ type EvalMatch struct {
|
||||
Metric string `json:"metric"`
|
||||
Value float64 `json:"value"`
|
||||
}
|
||||
|
||||
type AlertHistory struct {
|
||||
AlertId int64 `json:"alertId"`
|
||||
NewState string `json:"netState"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Title string `json:"title"`
|
||||
Text string `json:"text"`
|
||||
Metric string `json:"metric"`
|
||||
|
||||
Data *simplejson.Json `json:"data"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user