The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/pkg/api/alerting.go

61 lines
1.3 KiB

package api
import (
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models"
)
func ValidateOrgAlert(c *middleware.Context) {
id := c.ParamsInt64(":id")
query := models.GetAlertById{Id: id}
if err := bus.Dispatch(&query); err != nil {
c.JsonApiErr(404, "Alert not found", nil)
return
}
if c.OrgId != query.Result.OrgId {
c.JsonApiErr(403, "You are not allowed to edit/view alert", nil)
return
}
}
// GET /api/alert_rule
func GetAlertChanges(c *middleware.Context) Response {
query := models.GetAlertChangesQuery{
OrgId: c.OrgId,
}
if err := bus.Dispatch(&query); err != nil {
return ApiError(500, "List alerts failed", err)
}
return Json(200, query.Result)
}
// GET /api/alert_rule
func GetAlerts(c *middleware.Context) Response {
query := models.GetAlertsQuery{
OrgId: c.OrgId,
}
if err := bus.Dispatch(&query); err != nil {
return ApiError(500, "List alerts failed", err)
}
return Json(200, query.Result)
}
// GET /api/alert_rule/:id
func GetAlert(c *middleware.Context) Response {
id := c.ParamsInt64(":id")
query := models.GetAlertById{Id: id}
if err := bus.Dispatch(&query); err != nil {
return ApiError(500, "List alerts failed", err)
}
return Json(200, &query.Result)
}