annotations.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package api
  2. import (
  3. "github.com/grafana/grafana/pkg/api/dtos"
  4. "github.com/grafana/grafana/pkg/middleware"
  5. "github.com/grafana/grafana/pkg/services/annotations"
  6. )
  7. func GetAnnotations(c *middleware.Context) Response {
  8. query := &annotations.ItemQuery{
  9. From: c.QueryInt64("from") / 1000,
  10. To: c.QueryInt64("to") / 1000,
  11. Type: annotations.ItemType(c.Query("type")),
  12. OrgId: c.OrgId,
  13. AlertId: c.QueryInt64("alertId"),
  14. DashboardId: c.QueryInt64("dashboardId"),
  15. PanelId: c.QueryInt64("panelId"),
  16. Limit: c.QueryInt64("limit"),
  17. NewState: c.QueryStrings("newState"),
  18. }
  19. repo := annotations.GetRepository()
  20. items, err := repo.Find(query)
  21. if err != nil {
  22. return ApiError(500, "Failed to get annotations", err)
  23. }
  24. result := make([]dtos.Annotation, 0)
  25. for _, item := range items {
  26. result = append(result, dtos.Annotation{
  27. AlertId: item.AlertId,
  28. Time: item.Epoch * 1000,
  29. Data: item.Data,
  30. NewState: item.NewState,
  31. PrevState: item.PrevState,
  32. Text: item.Text,
  33. Metric: item.Metric,
  34. Title: item.Title,
  35. })
  36. }
  37. return Json(200, result)
  38. }