feat(alerting): began work on testing alert rule from UI without having to save it
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/alerting"
|
||||
)
|
||||
|
||||
func ValidateOrgAlert(c *middleware.Context) {
|
||||
@@ -71,6 +72,21 @@ func GetAlerts(c *middleware.Context) Response {
|
||||
return Json(200, alertDTOs)
|
||||
}
|
||||
|
||||
// POST /api/alerts/test
|
||||
func TestAlertRule(c *middleware.Context, dto dtos.TestAlertRuleCommand) Response {
|
||||
backendCmd := alerting.TestAlertRuleCommand{
|
||||
OrgId: c.OrgId,
|
||||
Dashboard: dto.Dashboard,
|
||||
PanelId: dto.PanelId,
|
||||
}
|
||||
|
||||
if err := bus.Dispatch(&backendCmd); err != nil {
|
||||
return ApiError(500, "Failed to test rule", err)
|
||||
}
|
||||
|
||||
return Json(200, backendCmd.Result)
|
||||
}
|
||||
|
||||
// GET /api/alerts/:id
|
||||
func GetAlert(c *middleware.Context) Response {
|
||||
id := c.ParamsInt64(":alertId")
|
||||
|
||||
@@ -246,6 +246,7 @@ func Register(r *macaron.Macaron) {
|
||||
r.Get("/metrics", wrap(GetInternalMetrics))
|
||||
|
||||
r.Group("/alerts", func() {
|
||||
r.Post("/test", bind(dtos.TestAlertRuleCommand{}), wrap(TestAlertRule))
|
||||
r.Get("/:alertId/states", wrap(GetAlertStates))
|
||||
//r.Put("/:alertId/state", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
|
||||
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package dtos
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
)
|
||||
|
||||
type AlertRuleDTO struct {
|
||||
Id int64 `json:"id"`
|
||||
@@ -29,3 +33,8 @@ type AlertNotificationDTO struct {
|
||||
Created time.Time `json:"created"`
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type TestAlertRuleCommand struct {
|
||||
Dashboard *simplejson.Json `json:"dashboard"`
|
||||
PanelId int64 `json:"panelId"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user