Skip to content
Sergio Rubio edited this page May 1, 2020 · 5 revisions

What are Filters?

Whenever an Event occurs, all of the Filters you defined in a Chain get executed with the data the Event provided. Only if the Event passes all of the Filters, the configured Actions in this Chain get then executed.

A Simple Filter

Let's assume you want to filter an Event which provides a string parameter called text, and you only want to execute your Chain if it matches the string important. You would define a filter with the following value:

{{test eq .text "important"}}

Simple, right? You call the test method eq (which stands for equals) and give it two values to compare. The first one is the Event parameter text. Note that Event parameters are always prefixed by a dot character. The second value is the string important.

If you'd wanted to check for the opposite, a parameter not matching a certain value, you would use the test method ne (not equals):

{{test ne .text "unimportant"}}

You can also compare other data types, like numbers:

{{test eq .number 42}}

If you want to check for a number parameter being lower than a certain value, there's the lt (lower than) method:

{{test lt .number 42}}

Similarly there are le (lower or equal to), gt (greater than) and ge (greater or equal to) methods.

Advanced Filters

Beehive provides you with a set of Template Helper functions, which you can use on Event parameters. Let's create a Filter that passes, if the lower-case version of the parameter text is equal to important:

{{test eq (ToLower .text) "important"}}

The ToLower method returns the lower-case version of the parameter text, which then gets compared with important. This Filter will pass whether text is important or IMPORTANT (or any other combination of lower- and upper-cases used).

There is also a Contains method, which checks if a string parameter contains a particular value:

{{test Contains .text "abc"}}

With the HasPrefix method you can check if a string parameter starts with a particular value:

{{test HasPrefix .text "abc"}}

Further Examples for string Parameters:

{{test eq .text "abc"}}

This test passes when the Event parameter text is equal to abc.

{{test Contains .text "abc"}}

This test passes when the Event parameter text contains abc.

{{test HasPrefix .text "abc"}}

This test passes when the Event parameter text starts with abc.

{{test HasSuffix .text "abc"}}

This test passes when the Event parameter text ends with abc.

{{test eq (ToLower .text) "abc"}}

This test passes when the Event parameter text in lower-case is equal to abc.

{{test eq (ToUpper .text) "ABC"}}

This test passes when the Event parameter text in upper-case is equal to ABC.

Time filters with TimeNow

{{test eq TimeNow.Year 2020}}

This test passes when the current year is 2020.

{{test eq TimeNow.Weekday 1}}

This test passes every Monday (0 Sunday, 6 Saturday)