Skip to content

Commit a8b2a64

Browse files
authored
Merge pull request #2499 from certtools/filter-docs
Filter expert: Docs fix, treat false as false for filter_regex and add logging
2 parents a9e8d4e + f3a3573 commit a8b2a64

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#### Experts
3535
- `intelmq.bots.experts.sieve.expert`:
3636
- For `:contains`, `=~` and `!~`, convert the value to string before matching avoiding an exception. If the value is a dict, convert the value to JSON (PR#2500 by Sebastian Wagner).
37+
- `intelmq.bots.experts.filter.expert`:
38+
- Treat value `false` for parameter `filter_regex` as false (PR#2499 by Sebastian Wagner).
3739

3840
#### Outputs
3941
- `intelmq.bots.outputs.misp.output_feed`: Handle failures if saved current event wasn't saved or is incorrect (PR by Kamil Mankowski).

docs/user/bots.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2730,25 +2730,23 @@ A simple filter for messages (drop or pass) based on a exact string comparison o
27302730

27312731
**`filter_key`**
27322732

2733-
() - key from data format
2733+
(required, string) - key from data format
27342734

27352735
**`filter_value`**
27362736

2737-
() - value for the key
2737+
(required, string) - value for the key
27382738

27392739
**`filter_action`**
27402740

2741-
() - action when a message match to the criteria
2741+
(required, string) - action when a message match to the criteria
27422742
(possible actions: keep/drop)
27432743

27442744
**`filter_regex`**
27452745

2746-
() - attribute determines if the `filter_value` shall be treated as regular expression or not.
2746+
(optional, boolean) - attribute determines if the `filter_value` shall be treated as regular expression or not.
27472747

2748-
If this attribute is not empty (can be `true`, `yes` or whatever), the bot uses python's `` `re.search ``
2749-
<<https://docs.python.org/3/library/re.html#re.search>>`_ function to evaluate the filter with regular expressions. If
2750-
this attribute is empty or evaluates to false, an exact string comparison is performed. A check on string *
2751-
inequality* can be achieved with the usage of *Paths* described below.
2748+
If this attribute is not empty (can be `true`, `yes` or whatever), the bot uses python's [`re.search`](https://docs.python.org/3/library/re.html#re.search) function to evaluate the filter with regular expressions. If
2749+
this attribute is empty or evaluates to false, an exact string comparison is performed. A check on string *inequality* can be achieved with the usage of *Paths* described below.
27522750

27532751
*Parameters for time based filtering*
27542752

intelmq/bots/experts/filter/expert.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def init(self):
6464
self.filter = False
6565

6666
self.regex = False
67-
if self.filter_regex is not None:
67+
if self.filter_regex:
6868
self.regex = re.compile(self.filter_value)
6969

7070
self.time_filter = self.not_after is not None or self.not_before is not None
@@ -148,10 +148,12 @@ def doFilter(self, event, key, condition):
148148
return self.equalsFilter(event, key, condition)
149149

150150
def equalsFilter(self, event, key, value):
151+
self.logger.debug('Equality check: %r (event value) == %r (filter value).', event.get(key), value)
151152
return (key in event and
152153
event.get(key) == value)
153154

154155
def regexSearchFilter(self, event, key):
156+
self.logger.debug('Regex filter: Matching %r against %r.', str(event.get(key)), self.filter_value)
155157
if key in event:
156158
return self.regex.search(str(event.get(key)))
157159
else:

0 commit comments

Comments
 (0)