NAME
App::Wubot::Conditions - evaluation conditions on reactor rules
VERSION
version 0.3.8
SYNOPSIS
use App::Wubot::Conditions;
my $cond = App::Wubot::Conditions->new();
# prints 'OK'
print "OK\n" if $cond->istrue( "foo equals 5", { foo => 5 } );
DESCRIPTION
There are a number of conditions that are available for the rules:
- {fieldname} equals {value}
- values of field {fieldname} on the message equals the specified value
- {fieldname} matches {regexp}
- value of field {fieldname} matches specified regexp
- {fieldname} imatches {regexp}
- case insensitve regexp match
- contains {fieldname}
- the message contains the field, the value of the field may be undefined or 0
- {fieldname} is false
- the field has a value that is false according to perl, i.e. undef, 0, or ""
- {fieldname} is true
- the field has a value which is true according to perl, i.e. not undef, 0, or ""
You can also make numeric comparisons between fields and values or fields and other fields.
- operators: <, <=, >, >=,
- {fieldname} {operator} {value}
- {fieldname} {operator} {fieldname}
- examples:
- size > 300
- heatindex > temperature
Any rule can be prefixed by NOT, as in:
- NOT title matches foo
- true unless the title contains 'foo'
You can string together multiple rules using AND and OR. You MUST capitalize the "AND" and "OR" or else the rule will not be parsed properly.
- subject is true AND body is true
- true if the subject and body are populated
- title matches foo OR body matches foo
- true if the title or body contains the string 'foo'
- NOT title matches foo AND NOT body matches foo
- true as long as 'foo' does not occur in either the title or body
SUBROUTINES/METHODS
- istrue( $condition, $message )
-
Process conditions on the specified message. Returns a true value if the message satisfies the condition.
PARENTHESES
You can now use parentheses within conditions. For example:
condition: ( x is false AND y is true ) OR z is true
Note that you must always have at least one space after the opening parenthesis, and at least one space before the close parenthesis. You will also need a space in-between a parentheses and the AND or OR that precedes or follows it.
Another mechanism for nesting conditions is to use rule trees. Child rules are only evaluated if the parent rule matches, so parent and child rules are logically combined by AND. For example, the following condition:
condition: ( x is true OR y is true ) AND ( a is true OR b is true )
is the equivalent of:
rules:
- name: check x and y
condition: x is true OR y is true
rules:
- name: check a and b
condition: a is true OR b is true