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