feat(alerting): working on alert state filters for alert list

This commit is contained in:
Torkel Ödegaard
2016-08-17 11:00:00 +02:00
parent da59d6547f
commit 63a283b4bc
7 changed files with 73 additions and 56 deletions

View File

@@ -13,12 +13,13 @@ const (
AlertStatePending AlertStateType = "pending"
AlertStateExeuctionError AlertStateType = "exeuction_error"
AlertStatePaused AlertStateType = "paused"
AlertStateFiring AlertStateType = "firing"
AlertStateCritical AlertStateType = "critical"
AlertStateWarning AlertStateType = "warning"
AlertStateOK AlertStateType = "ok"
)
func (s AlertStateType) IsValid() bool {
return s == AlertStatePending || s == AlertStateFiring || s == AlertStateOK
return s == AlertStateOK || s == AlertStatePending || s == AlertStateExeuctionError || s == AlertStatePaused || s == AlertStateCritical || s == AlertStateWarning
}
const (

View File

@@ -35,7 +35,7 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
ctx.Rule.State = m.AlertStateExeuctionError
exeuctionError = ctx.Error.Error()
} else if ctx.Firing {
ctx.Rule.State = m.AlertStateFiring
ctx.Rule.State = m.AlertStateType(ctx.Rule.Severity)
} else {
ctx.Rule.State = m.AlertStateOK
}

View File

@@ -3,7 +3,6 @@ package sqlstore
import (
"bytes"
"fmt"
"strings"
"time"
"github.com/go-xorm/xorm"
@@ -76,18 +75,19 @@ func HandleAlertsQuery(query *m.GetAlertsQuery) error {
params = append(params, query.PanelId)
}
if len(query.State) > 0 {
if len(query.State) > 0 && query.State[0] != "ALL" {
sql.WriteString(` AND (`)
for i, v := range query.State {
if i > 0 {
sql.WriteString(" OR ")
}
sql.WriteString("state = ? ")
params = append(params, strings.ToUpper(v))
params = append(params, v)
}
sql.WriteString(")")
}
sqlog.Error(sql.String(), "params", params)
alerts := make([]*m.Alert, 0)
if err := x.Sql(sql.String(), params...).Find(&alerts); err != nil {
return err