annotations.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. }
  18. repo := annotations.GetRepository()
  19. items, err := repo.Find(query)
  20. if err != nil {
  21. return ApiError(500, "Failed to get annotations", err)
  22. }
  23. result := make([]dtos.Annotation, 0)
  24. for _, item := range items {
  25. result = append(result, dtos.Annotation{
  26. AlertId: item.AlertId,
  27. Time: item.Epoch * 1000,
  28. Data: item.Data,
  29. NewState: item.NewState,
  30. PrevState: item.PrevState,
  31. Text: item.Text,
  32. Metric: item.Metric,
  33. Title: item.Title,
  34. })
  35. }
  36. return Json(200, result)
  37. }