feat(alerting): testing alert is starting to work

This commit is contained in:
Torkel Ödegaard
2016-07-21 13:09:12 +02:00
parent 9e91aacd34
commit f6a160b270
14 changed files with 104 additions and 70 deletions
+7
View File
@@ -83,6 +83,9 @@ func AlertTest(c *middleware.Context, dto dtos.AlertTestCommand) Response {
}
if err := bus.Dispatch(&backendCmd); err != nil {
if validationErr, ok := err.(alerting.AlertValidationError); ok {
return ApiError(422, validationErr.Error(), nil)
}
return ApiError(500, "Failed to test rule", err)
}
@@ -96,6 +99,10 @@ func AlertTest(c *middleware.Context, dto dtos.AlertTestCommand) Response {
dtoRes.Error = res.Error.Error()
}
for _, log := range res.Logs {
dtoRes.Logs = append(dtoRes.Logs, &dtos.AlertTestResultLog{Message: log.Message, Data: log.Data})
}
dtoRes.Timing = fmt.Sprintf("%1.3fs", res.GetDurationSeconds())
return Json(200, dtoRes)
+9 -3
View File
@@ -40,7 +40,13 @@ type AlertTestCommand struct {
}
type AlertTestResult struct {
Triggered bool `json:"triggerd"`
Timing string `json:"timing"`
Error string `json:"error"`
Triggered bool `json:"triggerd"`
Timing string `json:"timing"`
Error string `json:"error"`
Logs []*AlertTestResultLog `json:"logs"`
}
type AlertTestResultLog struct {
Message string `json:"message"`
Data interface{} `json:"data"`
}