【问题标题】:Creating index name from field value in filebeat configuration从 filebeat 配置中的字段值创建索引名称
【发布时间】:2021-11-05 23:07:42
【问题描述】:

这是我的 filebeat.yml 文件:

filebeat.config:
    modules:
        path: ${path.config}/modules.d/*.yml
        reload.enabled: false

processors:
    - add_cloud_metadata: ~
    - add_docker_metadata: ~
    - add_kubernetes_metadata: ~

output.elasticsearch:
    hosts: '${ELASTICSEARCH_HOSTS:elasticsearch:9200}'
    username: '${ELASTICSEARCH_USERNAME:}'
    password: '${ELASTICSEARCH_PASSWORD:}'

setup.kibana:
    host: '${KIBANA_HOST}'
    ssl.enabled: false

filebeat.modules:
    - module: kibana
    - module: elasticsearch

fields_under_root: true
json.keys_under_root: true

filebeat.inputs:
    - type: log
      enabled: true
      fields:
          my_type: 'inventory'
      index: 'test-%{[fields.my_type]}-%{+yyyy.MM.dd}'
      paths:
          - /var/log/kibana/kibana.log

setup.ilm.overwrite: true
setup.ilm.enabled: false
setup.template.name: 'test-%{[fields.my_type]}-%{+yyyy.MM.dd}'
setup.template.pattern: 'test-%{[fields.my_type]}-*'

我想从我的字段值创建索引名称(特别是日志文件名) 当我尝试使用诸如

之类的代理字段时,它会起作用
%{[agent.version]}

但是当我尝试从我的自定义字段或其他可用字段中命名时出错

%{[file.name]} or %{[fields.my_type]}

这是来自 filebeat 日志的错误:

ERROR [publisher] pipeline/client.go:106 Failed to publish event: key not found

感谢任何提示

【问题讨论】:

  • 你试过%{[my_type]}吗?
  • @Filip 是的,我做到了。

标签: elasticsearch elastic-stack filebeat


【解决方案1】:

根据您发布的内容,您的 index 声明似乎在错误的位置,因为它在输入而不是输出中

https://www.elastic.co/guide/en/beats/filebeat/current/elasticsearch-output.html#index-option-es 描述了你想做什么,但试试这个;

output.elasticsearch:
  hosts: ["http://eshost:9200"]
  index: "%{[fields.my_type]}-%{[agent.version]}-%{+yyyy.MM.dd}" 

并将其从输入中删除

【讨论】:

  • 感谢您的评论。我也尝试将其放入输出,但结果相同 - 错误:找不到密钥。对于配置而言,放置它的位置并不重要,我想专门为每个输入创建索引名称。
猜你喜欢
  • 2021-01-10
  • 2020-05-01
  • 2022-01-18
  • 1970-01-01
  • 2019-02-04
  • 2023-01-03
  • 2020-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多