mirror of
https://github.com/alice-lg/birdwatcher.git
synced 2025-03-09 00:00:05 +01:00
added parser configuration for (for now exclusively) filtering fields from route parses
This commit is contained in:
parent
3e8140a414
commit
8e2e8d2a97
5 changed files with 27 additions and 1 deletions
|
@ -15,6 +15,10 @@ type BirdConfig struct {
|
|||
BirdCmd string `toml:"birdc"`
|
||||
}
|
||||
|
||||
type ParserConfig struct {
|
||||
FilterFields []string `toml:"filter_fields"`
|
||||
}
|
||||
|
||||
type RateLimitConfig struct {
|
||||
Reqs int
|
||||
Max int `toml:"requests_per_minute"`
|
||||
|
|
|
@ -6,8 +6,19 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var ParserConf ParserConfig
|
||||
|
||||
type Parsed map[string]interface{}
|
||||
|
||||
func dirtyContains(l []string, e string) bool {
|
||||
for _, c := range l {
|
||||
if c == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func emptyLine(line string) bool {
|
||||
return len(strings.TrimSpace(line)) == 0
|
||||
}
|
||||
|
@ -117,6 +128,13 @@ func mainRouteDetail(groups []string, route Parsed) Parsed {
|
|||
route["learnt_from"] = groups[6]
|
||||
route["primary"] = groups[7] == "*"
|
||||
route["metric"] = parseInt(groups[8])
|
||||
|
||||
for k, _ := range route {
|
||||
if !dirtyContains(ParserConf.FilterFields, k) {
|
||||
route[k] = nil
|
||||
}
|
||||
}
|
||||
|
||||
return route
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,7 @@ func main() {
|
|||
bird.ClientConf = birdConf
|
||||
bird.StatusConf = conf.Status
|
||||
bird.RateLimitConf.Conf = conf.Ratelimit
|
||||
bird.ParserConf = conf.Parser
|
||||
endpoints.Conf = conf.Server
|
||||
|
||||
// Make server
|
||||
|
|
|
@ -19,6 +19,7 @@ type Config struct {
|
|||
Status bird.StatusConfig
|
||||
Bird bird.BirdConfig
|
||||
Bird6 bird.BirdConfig
|
||||
Parser bird.ParserConfig
|
||||
}
|
||||
|
||||
// Try to load configfiles as specified in the files
|
||||
|
|
|
@ -50,4 +50,6 @@ listen = "0.0.0.0:29189"
|
|||
config = "/etc/bird6.conf"
|
||||
birdc = "birdc6"
|
||||
|
||||
|
||||
[parser]
|
||||
# Remove fields e.g. interface
|
||||
filter_fields = []
|
||||
|
|
Loading…
Add table
Reference in a new issue