Skip to content

Commit 8a66a7d

Browse files
author
Sebastian Wagner
committed
Merge remote-tracking branch 'upstream/pr/1687' into develop
2 parents 6278f15 + 79e6587 commit 8a66a7d

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

docs/user/bots.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,10 +2453,12 @@ rules are specified in an external configuration file and with a syntax *similar
24532453
to the `Sieve language <http://sieve.info>`_ used for mail filtering.
24542454

24552455
Each rule defines a set of matching conditions on received events. Events can be
2456-
matched based on keys and values in the event. If the processed event matches a
2457-
rule's conditions, the corresponding actions are performed. Actions can specify
2458-
whether the event should be kept or dropped in the pipeline (filtering actions)
2459-
or if keys and values should be changed (modification actions).
2456+
matched based on keys and values in the event. Conditions can be combined using
2457+
parenthesis and the boolean operators ``&&`` and ``||``. If the processed event
2458+
matches a rule's conditions, the corresponding actions are performed. Actions
2459+
can specify whether the event should be kept or dropped in the pipeline
2460+
(filtering actions) or if keys and values should be changed (modification
2461+
actions).
24602462

24612463
**Requirements**
24622464

@@ -2524,7 +2526,8 @@ Each rule specifies on or more expressions to match an event based on its keys
25242526
and values. Event keys are specified as strings without quotes. String values
25252527
must be enclosed in single quotes. Numeric values can be specified as integers
25262528
or floats and are unquoted. IP addresses and network ranges (IPv4 and IPv6) are
2527-
specified with quotes. Parentheses in expression statements are not possible.
2529+
specified with quotes. Expression statements can be combined and chained using
2530+
parenthesis and the boolean operators ``&&`` and ``||``.
25282531
The following operators may be used to match events:
25292532

25302533
* `:exists` and `:notexists` match if a given key exists, for example:
@@ -2559,6 +2562,10 @@ The following operators may be used to match events:
25592562
Events with values like `8.8.8.8` or `8.8.4.4` will match, as they are always unequal to the other value.
25602563
The result is *not* that the field must be unequal to all given values.
25612564

2565+
* The combination of multiple expressions can be done using parenthesis and boolean operators:
2566+
2567+
``if (source.ip == '127.0.0.1') && (comment == 'add field' || classification.taxonomy == 'vulnerable') { ... }``
2568+
25622569

25632570
*Actions*
25642571

intelmq/tests/bots/experts/sieve/test_expert.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,32 @@ def test_numeric_key(self):
975975
self.run_bot()
976976
self.assertMessageEqual(0, numeric_match_true)
977977

978+
def test_parentheses(self):
979+
""" Test if parenthesis work"""
980+
self.sysconfig['file'] = os.path.join(os.path.dirname(__file__), 'test_sieve_files/test_parentheses.sieve')
981+
982+
# If doesn't match, nothing should have changed
983+
event1 = EXAMPLE_INPUT.copy()
984+
self.input_message = event1
985+
self.run_bot()
986+
self.assertMessageEqual(0, event1)
987+
988+
# If expression matches, destination.ip field is added
989+
event1['comment'] = 'add field'
990+
result = event1.copy()
991+
result['destination.ip'] = '150.50.50.10'
992+
self.input_message = event1
993+
self.run_bot()
994+
self.assertMessageEqual(0, result)
995+
996+
# If expression matches, destination.ip field is added
997+
event2 = EXAMPLE_INPUT.copy()
998+
event2['classification.taxonomy'] = 'vulnerable'
999+
result = event2.copy()
1000+
result['destination.ip'] = '150.50.50.10'
1001+
self.input_message = event2
1002+
self.run_bot()
1003+
self.assertMessageEqual(0, result)
9781004

9791005
if __name__ == '__main__': # pragma: no cover
9801006
unittest.main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (source.ip == '127.0.0.1') && (comment == 'add field' || classification.taxonomy == 'vulnerable') {
2+
add destination.ip="150.50.50.10"
3+
}

0 commit comments

Comments
 (0)