feat(alerting): progress on testing alerts
This commit is contained in:
+17
-3
@@ -1,6 +1,8 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
@@ -73,8 +75,8 @@ func GetAlerts(c *middleware.Context) Response {
|
||||
}
|
||||
|
||||
// POST /api/alerts/test
|
||||
func TestAlertRule(c *middleware.Context, dto dtos.TestAlertRuleCommand) Response {
|
||||
backendCmd := alerting.TestAlertRuleCommand{
|
||||
func AlertTest(c *middleware.Context, dto dtos.AlertTestCommand) Response {
|
||||
backendCmd := alerting.AlertTestCommand{
|
||||
OrgId: c.OrgId,
|
||||
Dashboard: dto.Dashboard,
|
||||
PanelId: dto.PanelId,
|
||||
@@ -84,7 +86,19 @@ func TestAlertRule(c *middleware.Context, dto dtos.TestAlertRuleCommand) Respons
|
||||
return ApiError(500, "Failed to test rule", err)
|
||||
}
|
||||
|
||||
return Json(200, backendCmd.Result)
|
||||
res := backendCmd.Result
|
||||
|
||||
dtoRes := &dtos.AlertTestResult{
|
||||
Triggered: res.Triggered,
|
||||
}
|
||||
|
||||
if res.Error != nil {
|
||||
dtoRes.Error = res.Error.Error()
|
||||
}
|
||||
|
||||
dtoRes.Timing = fmt.Sprintf("%1.3fs", res.GetDurationSeconds())
|
||||
|
||||
return Json(200, dtoRes)
|
||||
}
|
||||
|
||||
// GET /api/alerts/:id
|
||||
|
||||
+1
-1
@@ -246,7 +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.Post("/test", bind(dtos.AlertTestCommand{}), wrap(AlertTest))
|
||||
r.Get("/:alertId/states", wrap(GetAlertStates))
|
||||
//r.Put("/:alertId/state", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
|
||||
r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
|
||||
|
||||
@@ -34,7 +34,13 @@ type AlertNotificationDTO struct {
|
||||
Updated time.Time `json:"updated"`
|
||||
}
|
||||
|
||||
type TestAlertRuleCommand struct {
|
||||
Dashboard *simplejson.Json `json:"dashboard"`
|
||||
PanelId int64 `json:"panelId"`
|
||||
type AlertTestCommand struct {
|
||||
Dashboard *simplejson.Json `json:"dashboard" binding:"Required"`
|
||||
PanelId int64 `json:"panelId" binding:"Required"`
|
||||
}
|
||||
|
||||
type AlertTestResult struct {
|
||||
Triggered bool `json:"triggerd"`
|
||||
Timing string `json:"timing"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user