Conjunction (AND), disjunction (OR), and multiple subconditions

When you define a condition, you can create an expression that combines multiple subcondition expressions using the operators AND, OR, and parenthesis.

The condition function returns true if the combination of the subconditions is true.

Operator precedence:

  1. Parenthesis operator: ()

  2. AND operator

  3. OR operator

For example, consider the following expression:

SubCondition1 AND SubCondition2 OR Subcondition3

Because there are no parentheses in this expression, the AND operation is evaluated first. The result of that evaluation is then evaluated against Subcondition3 using the OR operator. The condition function returns the result of the second evaluation. The following table shows the results according to the evaluation of each subcondition:

Subcondition1 Subcondition2 Subcondition3 Result
true true false true
true false false false
false true false false
false false false false
true true true true
true false true true
false true true true
false false true true

The following example shows a condition with three different subconditions:

  1. Resource Utilization Poll Interval > 50

  2. Spanning tree hello time > 5

  3. VLAN admin status = down

Example:

uri1 = '/rest/v1/system?attributes=resource_utilization_poll_interval'
self.m1 = Monitor(uri1, name='Resource Utilization Poll Interval')

uri2 = '/rest/v1/system?attributes=stp_config.hello_time'
self.m2 = Monitor(uri2, name='Spanning tree hello time')

uri3 = '/rest/v1/system/vlans/{}?attributes=admin'
self.m3 = Monitor(uri3, 'Vlan admin status', [self.params['vlan_id']])

self.r1 = Rule("Rule 1")
self.r1.condition('({} > 50 AND {} > 5) OR {} == "down"', [self.m1, self.m2, self.m3])
self.r1.action(self.action_callback1)