diff options
| author | Shulhan <ms@kilabit.info> | 2019-01-04 11:19:00 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2019-01-04 15:15:35 +0700 |
| commit | d7739491bdadf7b936095dcc2ba09f57e2f3a322 (patch) | |
| tree | ccfdcc3e4042f4a976db57569a1037c4b59d4c76 /config.go | |
| parent | 49e7d14699b299dffa835b2a9240e2f03e8d0dd3 (diff) | |
| download | haminer-d7739491bdadf7b936095dcc2ba09f57e2f3a322.tar.xz | |
Add option to preprocess http_url
Diffstat (limited to 'config.go')
| -rw-r--r-- | config.go | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -49,6 +49,9 @@ type Config struct { // MaxBufferedLogs define a number of logs that will be keep in buffer // before being forwarded. MaxBufferedLogs int + + // retags contains list of pre-processing rules for tag. + retags []*tagPreprocessor } // @@ -90,6 +93,10 @@ func (cfg *Config) Load(path string) { if len(v) > 0 { cfg.InfluxAPIWrite = v } + + sec := in.GetSection("preprocess", "tag") + + cfg.parsePreprocessTag(sec) } // @@ -149,3 +156,35 @@ func (cfg *Config) ParseCaptureRequestHeader(v string) { cfg.RequestHeaders = append(cfg.RequestHeaders, headers[x]) } } + +func (cfg *Config) parsePreprocessTag(sec *ini.Section) { + if sec == nil { + return + } + + for _, v := range sec.Vars { + if len(v.KeyLower) == 0 { + continue + } + if v.KeyLower != "http_url" { + log.Printf("parsePreprocessTag: unknown tag %q\n", + v.KeyLower) + continue + } + + rep := strings.Split(v.Value, "=>") + if len(rep) != 2 { + log.Printf("parsePreprocessTag: invalid format %q\n", + v.Value) + continue + } + + retag, err := newTagPreprocessor(v.KeyLower, rep[0], rep[1]) + if err != nil { + log.Printf("parsePreprocessTag: %s\n", err) + continue + } + + cfg.retags = append(cfg.retags, retag) + } +} |
