forked from bosun-monitor/bosun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lookup.go
43 lines (39 loc) · 769 Bytes
/
lookup.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package conf
import (
"bosun.org/cmd/bosun/search"
"bosun.org/models"
"bosun.org/opentsdb"
)
// TODO: remove this and merge it with Lookup
type ExprLookup struct {
Tags []string
Entries []*ExprEntry
}
type ExprEntry struct {
AlertKey models.AlertKey
Values map[string]string
}
func (lookup *ExprLookup) Get(key string, tag opentsdb.TagSet) (value string, ok bool) {
for _, entry := range lookup.Entries {
value, ok = entry.Values[key]
if !ok {
continue
}
match := true
for ak, av := range entry.AlertKey.Group() {
matches, err := search.Match(av, []string{tag[ak]})
if err != nil {
return "", false
}
if len(matches) == 0 {
match = false
break
}
}
if !match {
continue
}
return
}
return "", false
}