Add support for ignore regexes in filters
This commit is contained in:
parent
c076177d2b
commit
8afa6281f4
@ -62,6 +62,12 @@ func runCommands(commands [][]string, moment string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pattern) notAnIgnore(match *string) bool {
|
func (p *Pattern) notAnIgnore(match *string) bool {
|
||||||
|
for _, regex := range p.compiledIgnoreRegex {
|
||||||
|
if regex.MatchString(*match) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, ignore := range p.Ignore {
|
for _, ignore := range p.Ignore {
|
||||||
if ignore == *match {
|
if ignore == *match {
|
||||||
return false
|
return false
|
||||||
|
@ -23,6 +23,9 @@ patterns:
|
|||||||
ignore:
|
ignore:
|
||||||
- 127.0.0.1
|
- 127.0.0.1
|
||||||
- ::1
|
- ::1
|
||||||
|
# Patterns can be ignored based on regexes, it will try to match the whole string detected by the pattern
|
||||||
|
# ignoreregex:
|
||||||
|
# - '10\.0\.[0-9]{1,3}\.[0-9]{1,3}'
|
||||||
|
|
||||||
# Those commands will be executed in order at start, before everything else
|
# Those commands will be executed in order at start, before everything else
|
||||||
start:
|
start:
|
||||||
|
@ -39,6 +39,17 @@ func (c *Conf) setup() {
|
|||||||
logger.Fatalf("Bad configuration: pattern ignore '%v' doesn't match pattern %v! It should be fixed or removed.", ignore, pattern.nameWithBraces)
|
logger.Fatalf("Bad configuration: pattern ignore '%v' doesn't match pattern %v! It should be fixed or removed.", ignore, pattern.nameWithBraces)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compile ignore regexes
|
||||||
|
for _, regex := range pattern.IgnoreRegex {
|
||||||
|
// Enclose the regex to make sure that it matches the whole detected string
|
||||||
|
compiledRegex, err := regexp.Compile("^" + regex + "$")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("%vBad configuration: in ignoreregex of pattern %s: %v", logger.FATAL, pattern.name, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern.compiledIgnoreRegex = append(pattern.compiledIgnoreRegex, *compiledRegex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.Streams) == 0 {
|
if len(c.Streams) == 0 {
|
||||||
|
@ -19,6 +19,9 @@ type Pattern struct {
|
|||||||
Regex string `json:"regex"`
|
Regex string `json:"regex"`
|
||||||
Ignore []string `json:"ignore"`
|
Ignore []string `json:"ignore"`
|
||||||
|
|
||||||
|
IgnoreRegex []string `json:"ignoreregex"`
|
||||||
|
compiledIgnoreRegex []regexp.Regexp `json:"-"`
|
||||||
|
|
||||||
name string `json:"-"`
|
name string `json:"-"`
|
||||||
nameWithBraces string `json:"-"`
|
nameWithBraces string `json:"-"`
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,8 @@ local banFor(time) = {
|
|||||||
// simple version: regex: @'(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})|(?:[0-9a-fA-F:]{2,90})',
|
// simple version: regex: @'(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3})|(?:[0-9a-fA-F:]{2,90})',
|
||||||
regex: @'(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}|(?:(?:[0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,7}:|(?:[0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|(?:[0-9a-fA-F]{1,4}:){1,5}(?::[0-9a-fA-F]{1,4}){1,2}|(?:[0-9a-fA-F]{1,4}:){1,4}(?::[0-9a-fA-F]{1,4}){1,3}|(?:[0-9a-fA-F]{1,4}:){1,3}(?::[0-9a-fA-F]{1,4}){1,4}|(?:[0-9a-fA-F]{1,4}:){1,2}(?::[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:(?:(?::[0-9a-fA-F]{1,4}){1,6})|:(?:(?::[0-9a-fA-F]{1,4}){1,7}|:)|fe80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4]|1{0,1}[0-9]){0,1}[0-9]))',
|
||||||
ignore: ['127.0.0.1', '::1'],
|
ignore: ['127.0.0.1', '::1'],
|
||||||
|
// Patterns can be ignored based on regexes, it will try to match the whole string detected by the pattern
|
||||||
|
// ignoreregex: [@'10\.0\.[0-9]{1,3}\.[0-9]{1,3}'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user