2016-09-08 04:25:45 -05:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/grafana/grafana/pkg/api/dtos"
|
|
|
|
"github.com/grafana/grafana/pkg/middleware"
|
|
|
|
"github.com/grafana/grafana/pkg/services/annotations"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetAnnotations(c *middleware.Context) Response {
|
|
|
|
|
|
|
|
query := &annotations.ItemQuery{
|
2016-09-09 04:30:55 -05:00
|
|
|
From: c.QueryInt64("from") / 1000,
|
|
|
|
To: c.QueryInt64("to") / 1000,
|
|
|
|
Type: annotations.ItemType(c.Query("type")),
|
|
|
|
OrgId: c.OrgId,
|
|
|
|
AlertId: c.QueryInt64("alertId"),
|
|
|
|
DashboardId: c.QueryInt64("dashboardId"),
|
|
|
|
PanelId: c.QueryInt64("panelId"),
|
|
|
|
Limit: c.QueryInt64("limit"),
|
2016-09-14 01:36:44 -05:00
|
|
|
NewState: c.QueryStrings("newState"),
|
2016-09-08 04:25:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
repo := annotations.GetRepository()
|
|
|
|
|
|
|
|
items, err := repo.Find(query)
|
|
|
|
if err != nil {
|
|
|
|
return ApiError(500, "Failed to get annotations", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
result := make([]dtos.Annotation, 0)
|
|
|
|
|
|
|
|
for _, item := range items {
|
|
|
|
result = append(result, dtos.Annotation{
|
|
|
|
AlertId: item.AlertId,
|
|
|
|
Time: item.Epoch * 1000,
|
|
|
|
Data: item.Data,
|
|
|
|
NewState: item.NewState,
|
|
|
|
PrevState: item.PrevState,
|
|
|
|
Text: item.Text,
|
|
|
|
Metric: item.Metric,
|
|
|
|
Title: item.Title,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return Json(200, result)
|
|
|
|
}
|
2016-10-14 02:33:16 -05:00
|
|
|
|
|
|
|
func DeleteAnnotations(c *middleware.Context, cmd dtos.DeleteAnnotationsCmd) Response {
|
|
|
|
repo := annotations.GetRepository()
|
|
|
|
|
|
|
|
err := repo.Delete(&annotations.DeleteParams{
|
|
|
|
AlertId: cmd.PanelId,
|
|
|
|
DashboardId: cmd.DashboardId,
|
|
|
|
PanelId: cmd.PanelId,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ApiError(500, "Failed to delete annotations", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ApiSuccess("Annotations deleted")
|
|
|
|
}
|