filebeat定义处理器

定义处理器

在filebeat将数据发送到配置的输出之前,可以使用处理器来过滤和增强数据。要定义处理器,需要制定处理器名称,可选条件和一组参数:

processors:
- <processor_name>:           ##指定执行某种操作的处理器
    when:
      <condition>             ##指定可选条件,如果条件成立则执行
    <parameters>              ##是传递给处理器的参数列表

- <processor_name>:
    when:
      <condition>
    <parameters>

处理器再哪里有效?

处理器所处位置:

1)在配置的顶层,处理器应用于filebeat收集的所有数据

2)在具体的输入下,处理器应用于为该输入收集的数据,example:

-  type:<input_type> 
  processor:
  -  <processor_name>:
      when:
        <condition> 
      <parameters>

同样,对于filebeat模块,可以在input下定义处理器模块。

支持的处理器:

①add_cloud_metadata

②add_locale  

③decode_json_fields

④drop_event

  删除事件,如果处理器下关联的条件被满足则删除整个事件,条件时强制性的:

processors:
 - drop_event:
     when:
       condition

⑤drop_fields

  指定哪些字段如果特定条件被满足下降,条件时可选的。如果缺少,则始终删除指定的指定。@timestamp和type字段不能被drop,即使它们显示在drop_fields列表中。

processors:
 - drop_fields:
     when:
        condition
     fields: ["field1", "field2", ...]

⑥include_fields

  处理器指定哪些字段满足条件到出口。条件时可选的,如果缺少,则始终导出到出口。@timestamp和type始终被导出。

processors:
 - include_fields:
     when:
        condition
     fields: ["field1", "field2", ...]

⑦rename

  处理器指定字段命名列表;类似一个key对,每个key对包含一个old-key和一个new-key,form是源名,to是目标名。

  在字段名称导致冲突的情况下,重命名字段非常有用;重命名字段不能用于覆盖字段,要覆盖字段,请先重命名目标字段,或使用drop_fields处理器删除字段,然后重新命名字段:

processors:
- rename:
    fields:
     - from: "a.g"
       to: "e.d"
    ignore_missing: false    ##(可选)如果设置为true,则在缺少重命名的键的情况下不会记录错误,默认是false。
    fail_on_error: true      ##(可选)如果设置为true,则在发生错误时停止重命名字段并返回原始事件。如果设置为false,则在重命名期间发生错误时,重命名也会继续,默认是true。

⑧add_kubernetes_metadata

⑨add_docker_metadata

⑩dissect

  使用定义的模式对传入的字符串进行标记。

processors:
- dissect:
    tokenizer: "%{key1} %{key2}"
    field: "message"      ##(可选),要标记的事件字段,默认是message
    target_prefix: "dissect"   ##(可选)提取字段名称,处理器将在事件的根目录中创建密钥。默认是dissect

条件

每个条件都要接收一个要比较的字段,支持的条件有:

①equals

  使用equals条件,可以比较字段是否具有特定值,条件仅接受整数或字符串。

  example,以下条件检查http事务的响应代码是否为200:

equals:
  http.response.code: 200

②contains

  所述contains条件检查如果一个值是一个字段的一部分。该字段可以是字符串或字符串属组,条件仅接受字符串值。

  example,以下条件检查错误时否是事务状态的一部分:

contains:
  status: "Specific error"

③regexp

  regxep以正则表达式来核对条件,条件只能是字符串。

  example,以下条件检查进程名是否以foo开头:

regexp:
  system.process.name: "foo.*"

④range

  range条件检查字段是在一定范围内的值,支持条件lt、lte、gt和gte。条件仅接受整数或浮点数。

  example,以下通过http.response.code字段与400进行比较来检查失败的http事务:

range:
    http.response.code:
        gte: 400
##or can be written as:
range:
    http.response.code.gte: 400
##The following condition checks if the CPU usage in percentage has a value between 0.5 and 0.8.
range:
    system.cpu.user.pct.gte: 0.5
    system.cpu.user.pct.lt: 0.8

⑤has_fields

  has_fields检查是否给定的fields存在于事件中,条件接受表示字段名称和字符串列表。

  example,以下条件检查http.response.code事件中是否存在该字段:

has_fields:['http.response.code']

⑥or

  操作者接收的条件列表:

or:
  - <condition1>
  - <condition2>
  - <condition3>
  ...

  example,要配置条件http.response.code = 304 或者 http.response.code = 404:

or:
  -  equals:
      http.response.code:304 
  -  equals:
      http.response.code:404

⑦and

  操作接收的条件列表,格式同or相同。也可以同or配合使用:

  example:

or:
 - <condition1>
 - and:
    - <condition2>
    - <condition3>

⑧not

  操作接收否定的条件:

not:
  <condition>

  example,配置条件NOT status = ok

not:
  equals:
    status: OK

可以在相同条件下使用and指定多个字段,(如:field1 AND fields)

猜你喜欢

转载自www.cnblogs.com/qinwengang/p/10980149.html
今日推荐