Skip to content
Snippets Groups Projects
Commit 7ce9324f authored by Rajmund Hruška's avatar Rajmund Hruška
Browse files

Fix: Discard event if any filtering rule is matched. (Redmine issue: #6227)

parent a9126154
No related branches found
No related tags found
No related merge requests found
......@@ -488,7 +488,7 @@ class EventReporter(BaseReporter):
filter_list = self.settings_dict[group].setup_filters(self.filter_parser, self.filter_compiler)
match = self.filter_event(filter_list, event)
if match:
self.logger.debug("Event matched filtering rule '%s' of group %s", match, group)
self.logger.debug("Event matched filtering rule '%s' of group %s.", match, group)
fltlog[match] = fltlog.get(match, 0) + 1
else:
filtered_groups.append(group)
......@@ -527,9 +527,15 @@ class EventReporter(BaseReporter):
if main_group not in groups:
return [], [], fltlog
groups, fltlog = self._filter_groups(groups, event, fltlog)
filtered_groups, fltlog = self._filter_groups(groups, event, fltlog)
# If any filtering rule of at least one of the groups was matched then this event shall not be reported to anyone.
if filtered_groups != groups:
self.logger.debug("Discarding event with ID '%s' from reports.", event['ID'])
return [], [], fltlog
fallback_groups, fltlog = self._filter_groups(fallback_groups, event, fltlog)
return groups, fallback_groups, fltlog
return filtered_groups, fallback_groups, fltlog
def filter_events(self, main_group, events):
"""
......
......@@ -308,10 +308,13 @@ class TestMentatReportsEvent(unittest.TestCase):
for events in aggr.values():
self.assertEqual(len(events), 2)
self.reporter.logger.assert_has_calls([
call.debug("Event matched filtering rule '%s' of group %s", 'FLT1', 'abuse@cesnet.cz'),
call.debug("Event matched filtering rule '%s' of group %s.", 'FLT1', 'abuse@cesnet.cz'),
call.debug("Discarding event with ID '%s' from reports.", 'msg01'),
call.debug('Event matched filtering rules, all sources filtered'),
call.debug("Event matched filtering rule '%s' of group %s", 'FLT3', 'abuse@cesnet.cz'),
call.debug("Event matched filtering rule '%s' of group %s", 'FLT2', 'abuse@cesnet.cz')
call.debug("Event matched filtering rule '%s' of group %s.", 'FLT3', 'abuse@cesnet.cz'),
call.debug("Discarding event with ID '%s' from reports.", 'msg02'),
call.debug("Event matched filtering rule '%s' of group %s.", 'FLT2', 'abuse@cesnet.cz'),
call.debug("Discarding event with ID '%s' from reports.", 'msg02')
])
self.sqlstorage.session.commit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment