Grep

Grep Filter

Overview

The grep filter plugin “greps” events by the values of specified fields.

Configuration

GrepConfig

regexp ([]RegexpSection, optional)

Regexp Directive

Default: -

exclude ([]ExcludeSection, optional)

Exclude Directive

Default: -

or ([]OrSection, optional)

Or Directive

Default: -

and ([]AndSection, optional)

And Directive

Default: -

Regexp Directive

Specify filtering rule (as described in the Fluentd documentation). This directive contains two parameters.

key (string, required)

Specify field name in the record to parse.

Default: -

pattern (string, required)

Pattern expression to evaluate

Default: -

Example Regexp filter configurations

apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
  name: demo-flow
spec:
  filters:
    - grep:
        regexp:
        - key: first
          pattern: /^5\d\d$/
  selectors: {}
  localOutputRefs:
    - demo-output

Fluentd config result:

  <filter **>
    @type grep
    @id demo-flow_1_grep
    <regexp>
      key first
      pattern /^5\d\d$/
    </regexp>
  </filter>

Exclude Directive

Specify filtering rule to reject events (as described in the Fluentd documentation). This directive contains two parameters.

key (string, required)

Specify field name in the record to parse.

Default: -

pattern (string, required)

Pattern expression to evaluate

Default: -

Example Exclude filter configurations

apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
  name: demo-flow
spec:
  filters:
    - grep:
        exclude:
        - key: first
          pattern: /^5\d\d$/
  selectors: {}
  localOutputRefs:
    - demo-output

Fluentd config result:

  <filter **>
    @type grep
    @id demo-flow_0_grep
    <exclude>
      key first
      pattern /^5\d\d$/
    </exclude>
  </filter>

Or Directive

Specify filtering rule (as described in the Fluentd documentation. This directive contains either regexp or exclude directive.

regexp ([]RegexpSection, optional)

Regexp Directive

Default: -

exclude ([]ExcludeSection, optional)

Exclude Directive

Default: -

Example Or filter configurations

apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
  name: demo-flow
spec:
  filters:
    - grep:
        or:
          - exclude:
            - key: first
              pattern: /^5\d\d$/
            - key: second
              pattern: /\.css$/

  selectors: {}
  localOutputRefs:
    - demo-output

Fluentd config result:

    <or>
      <exclude>
        key first
        pattern /^5\d\d$/
      </exclude>
      <exclude>
        key second
        pattern /\.css$/
      </exclude>
    </or>

And Directive

Specify filtering rule (as described in the Fluentd documentation. This directive contains either regexp or exclude directive.

regexp ([]RegexpSection, optional)

Regexp Directive

Default: -

exclude ([]ExcludeSection, optional)

Exclude Directive

Default: -

Example And filter configurations

apiVersion: logging.banzaicloud.io/v1beta1
kind: Flow
metadata:
  name: demo-flow
spec:
  filters:
    - grep:
        and:
          - regexp:
            - key: first
              pattern: /^5\d\d$/
            - key: second
              pattern: /\.css$/

  selectors: {}
  localOutputRefs:
    - demo-output

Fluentd config result:

    <and>
      <regexp>
        key first
        pattern /^5\d\d$/
      </regexp>
      <regexp>
        key second
        pattern /\.css$/
      </regexp>
    </and>

Last modified December 27, 2023: Version number bumps (00b4afd)