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

@@ -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