annotations.go 953 B

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