Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new filter template function, and fix if inside map #3426

Merged
merged 7 commits into from Oct 1, 2020

Conversation

furiel
Copy link
Collaborator

@furiel furiel commented Sep 11, 2020

Feature

A new filter template function is introduced in syslog-ng. Given a list, it executes a filter expression on each element, keeping only those that satisfy the filter expression. You can use macros, logical expressions, template functions inside the expression.

The current value is referred by $_, similarly to the map template function.

Syntax:

$(filter filter-expression list)

Example

Filtering even numbers:

log {
  source { example-msg-generator(num(1) values(INPUT => "0,1,2,3")); };
  destination {
     file("/dev/stdout"
           template("$(filter ('$(% $_ 2)' eq '0') $INPUT)\n)")
     );
  };
};

results in 0,2.

Bugfix

As context_id-s weren't passed when evaluating FilterExprNodes, if template function could not use $_: it received NULL ("") instead.

For example, these configurations will work after this PR:

log {
  source { example-msg-generator(num(1) values(INPUT => "0,1,2,3")); };
  destination {
     file("/dev/stdout"
           template("$(map $(if ('$(% $_ 2)' eq '0') 'even' 'odd') $INPUT)'\n)")
     );
  };
};

with result: even,odd,even,odd.

Referring: #2926

CC: @jszigetvari

@furiel furiel changed the title new filter template function, and fix if inside map new filter template function, and fix if inside map Sep 11, 2020
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@furiel furiel added the user-visible-feature User visible feature label Sep 14, 2020
lib/filter/filter-expr.c Outdated Show resolved Hide resolved
@furiel furiel changed the title new filter template function, and fix if inside map [WIP] new filter template function, and fix if inside map Sep 17, 2020
@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@kira-syslogng
Copy link
Contributor

Build FAILURE

@furiel furiel force-pushed the filter-function branch 2 times, most recently from a696158 to fe8ac83 Compare September 18, 2020 10:13
@kira-syslogng
Copy link
Contributor

Build SUCCESS

Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
Signed-off-by: Balazs Scheidler <bazsi77@gmail.com>
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@furiel furiel changed the title [WIP] new filter template function, and fix if inside map new filter template function, and fix if inside map Sep 18, 2020
@furiel furiel changed the title new filter template function, and fix if inside map [WIPnew filter template function, and fix if inside map Sep 22, 2020
@furiel furiel changed the title [WIPnew filter template function, and fix if inside map [WIP] new filter template function, and fix if inside map Sep 22, 2020
Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
Signed-off-by: Balazs Scheidler <bazsi77@gmail.com>
Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
Signed-off-by: Balazs Scheidler <bazsi77@gmail.com>
That way if template function can work inside map.

See unit tests.

Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
Signed-off-by: Antal Nemes <antal.nemes.hu@gmail.com>
@furiel furiel changed the title [WIP] new filter template function, and fix if inside map new filter template function, and fix if inside map Sep 22, 2020
@kira-syslogng
Copy link
Contributor

Build SUCCESS

@alltilla alltilla merged commit a744645 into syslog-ng:master Oct 1, 2020
@furiel furiel deleted the filter-function branch October 1, 2020 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user-visible-feature User visible feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants