alerting.go 1023 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package api
  2. import (
  3. "github.com/grafana/grafana/pkg/bus"
  4. "github.com/grafana/grafana/pkg/middleware"
  5. "github.com/grafana/grafana/pkg/models"
  6. )
  7. func ValidateOrgAlert(c *middleware.Context) {
  8. id := c.ParamsInt64(":id")
  9. query := models.GetAlertById{Id: id}
  10. if err := bus.Dispatch(&query); err != nil {
  11. c.JsonApiErr(404, "Alert not found", nil)
  12. return
  13. }
  14. if c.OrgId != query.Result.OrgId {
  15. c.JsonApiErr(403, "You are not allowed to edit/view alert", nil)
  16. return
  17. }
  18. }
  19. // GET /api/alert_rule
  20. func GetAlerts(c *middleware.Context) Response {
  21. query := models.GetAlertsQuery{
  22. OrgId: c.OrgId,
  23. }
  24. if err := bus.Dispatch(&query); err != nil {
  25. return ApiError(500, "List alerts failed", err)
  26. }
  27. return Json(200, query.Result)
  28. }
  29. // GET /api/alert_rule/:id
  30. func GetAlert(c *middleware.Context) Response {
  31. id := c.ParamsInt64(":id")
  32. query := models.GetAlertById{Id: id}
  33. if err := bus.Dispatch(&query); err != nil {
  34. return ApiError(500, "List alerts failed", err)
  35. }
  36. return Json(200, &query.Result)
  37. }