【问题标题】:Elastic Filebeat does not index into custom indices with mappingsElastic Filebeat 不会索引到带有映射的自定义索引
【发布时间】:2021-11-06 14:01:28
【问题描述】:

我正在尝试将 Filebeats 配置为将事件索引到自定义命名的索引中,并为某些字段提供自定义映射。 问题是 Filebeat 不会将事件发送到我的索引,而是尝试将它们发送到默认的 'filebeats-xxx' 索引,并且由于事件不符合默认的 filebeat 事件格式(这就是我想使用自己的映射的原因)。

请参阅下面的详细信息。

2021 年 9 月 10 日更新: 在发现此处报告/讨论的类似问题后:https://github.com/elastic/beats/issues/11866 我尝试遵循解决方法并将以下参数添加到 filebeats.yml 以禁用 ES 中的 ILM:

setup.ilm.enabled: false

这并没有太大帮助 - filebeat 日志显示 ILM 已设置。 所以我又添加了一个参数:

setup.ilm.overwrite: true

在此之后 - 错误停止了,但是当我尝试推送事件时 - filebeat 似乎在以下日志之后挂起:

    2021-09-09T21:42:58.057-0400    INFO    [publisher_pipeline_output] pipeline/output.go:143  Connecting to backoff(elasticsearch(https://testbeats1.es.us-central1.gcp.cloud.es.io:9243))
    2021-09-09T21:42:58.391-0400    INFO    [esclientleg]   eslegclient/connection.go:273   Attempting to connect to Elasticsearch version 7.14.1
    2021-09-09T21:42:58.495-0400    INFO    [publisher_pipeline_output] pipeline/output.go:151  Connection to backoff(elasticsearch(https://testbeats1.es.us-central1.gcp.cloud.es.io:9243)) established

我认为这不是连接问题,因为日志显示连接已建立...。知道如何进一步调试它吗?

更新结束

以下是详细信息:

我正在使用 gcp-pubsub 输入类型从 GCP PubSup 主题获取事件。事件已成功接收(通过使用控制台输出确认) - 包含在许多 GCP/filebeat 特定元信息中。如果我向 PubSub 主题发送这样的事件:

{
    "referer": "https://blog.zoom.us/",
    "activity_ip": "1.1.1.1",
    "activity_date": "2021-09-08",
    "logstash_id": "m_id_1",
    "event_timestamp_millis": "1631126426000",
    "cid": "1234567",
    "ref_param": "https://www.yahoo.com",
    "user_agent": "Mozilla/5.0 (X11; CrOS aarch64 13421.102.0) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/86.0.4240.199 Safari/537.36"
  }

Filebeats 接收到的实际事件(并在使用控制台输出时打印在控制台上)如下所示:

{
  "@timestamp": "2021-09-09T15:49:52.948Z",
  "@metadata": {
    "beat": "filebeat",
    "type": "_doc",
    "version": "7.14.1",
    "_id": "59279bf715-2924539382735950"
  },
  "message": {
    "referer": "https://blog.zoom.us/",
    "activity_ip": "1.1.1.1",
    "activity_date": "2021-09-08",
    "logstash_id": "m_id_1",
    "event_timestamp_millis": "1631126426000",
    "cid": "1234567",
    "ref_param": "https://www.yahoo.com",
    "user_agent": "Mozilla/5.0 (X11; CrOS aarch64 13421.102.0) AppleWebKit/537.36 (KHTML, like Gecko)Chrome/86.0.4240.199 Safari/537.36"
  },
  "input": {
    "type": "gcp-pubsub"
  },
  "ecs": {
    "version": "1.10.0"
  },
  "host": {
    "ip": [
      "xxxx", ...
    ],
    "mac": [
      "...", ...
    ],
    "hostname": "xxx.home",
    "architecture": "x86_64",
    "os": {
      "platform": "darwin",
      "version": "10.16",
      "family": "darwin",
      "name": "Mac OS X",
      "kernel": "20.2.0",
      "build": "20C69",
      "type": "macos"
    },
    "name": "xxx",
    "id": "AB905FFC-D83C-5512-B33A-AA1286026867"
  },
  "agent": {
    "name": "xxx,
    "type": "filebeat",
    "version": "7.14.1",
    "hostname": "xxx",...
  },
  "event": {
    "id": "59279bf715-2924539382735950",
    "created": "2021-09-09T15:49:52.936Z"
  }
}

我发送的实际事件存储在“message”元素中。默认情况下,它以字符串形式出现,但由于我发送 JSON 并希望将其视为带有字段/值的 JSON 文档 - 我已将以下 Filebeats 处理器添加到 filebeats.yml:

- decode_json_fields:
      fields: ["message"]

(请参阅下面的完整 filebeat.yml 配置)

我还想对事件字段使用我自己的类型 - 例如,对 ip 字段使用“ip”类型,对所有特定日期字段使用日期类型等。这就是我想要的原因为这些事件使用我自己的映射,并将它们发送到具有我选择的名称的索引中 - 例如仅用于测试,它是'ma​​rina-xxx':

我想出的完整映射/模板如下所示。 起初,我尝试将其作为 'ma​​rina_es_template.json' 文件放入 filebeat 根目录并让 Filebeat 上传此映射 - 所以我尝试了以下配置:

setup.template.name: "marina"
setup.template.pattern: "marina-*"
setup.template.json.enabled: true
setup.template.json.path: "marina_es_template.json"
setup.template.json.name: "marina"
setup.template.enabled: true

这不起作用 - filebeat 没有正确上传模板 - 我在我的 ES 中找不到它(使用 GET _template/marina* 命令)。所以我已经手动将它加载到我的 ES 中,使用 PUT 命令 - 它工作正常,我可以看到 ES 中列出的模板,并且模板的内容是正确的。

所以,我试图解决的最后一个问题是让 Filebeat 真正将事件发送到“marina-test1”索引,并将映射正确应用于该索引 - 通过匹配索引名称模式

我已经为 ES 输出添加了这个配置:

output.elasticsearch:
  enabled: true
  index: "marina-test2"

并使用此模板设置:

setup.template.name: "marina"
setup.template.pattern: "marina-*"
setup.template.json.enabled: false 

Fielbeat 仍然尝试将传入事件发送到“filebeat-xxx”索引,但失败并出现以下错误:

{"type":"mapper_parsing_exception","reason":"failed to parse field [message] of type [text] in document with id '59279bf715-2924626396675533'. ....}

这是正确的,因为在 'filebeat' 映射中,字段 'message' 应该是文本,而不是对象...

所以,问题是:如何强制 Filebeat 将事件发送到我的“marina-xxx”索引,而不是“filebeat-xxx”索引???

谢谢!

这是我的 filebeat.yml:(为了清楚起见,删除了 cmets/未使用的字段

# ============================== Filebeat inputs ===============================

filebeat.inputs:
- type: gcp-pubsub
  enabled: true
  project_id: my-project
  topic: logs-for-es-marina
  subscription.name: logs-for-es-marina-sub
  credentials_file: /mydir/.config/gcloud/application_default_credentials.json
  fields_under_root: true

# ======================= Elasticsearch template setting =======================
setup.template.name: "marina"
setup.template.pattern: "marina-*"
setup.template.enabled: false

## also tried this - but did not help:
#setup.template.json.enabled: true
#setup.template.json.path: "marina_es_template.json"
#setup.template.json.name: "marina"

# ---------------------------- Elasticsearch Output ----------------------------
output.elasticsearch:
  enabled: true
  index: "marina-test2"

  hosts: ["https://<my_es>:9243"]
  username: "<my-user>"
  password: "<my-pwd>"
  
# ================================= Processors =================================
processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
  - add_cloud_metadata: ~
  - add_docker_metadata: ~
  - add_kubernetes_metadata: ~
  - decode_json_fields:
      fields: ["message"]

完整的 ES 模板映射:

PUT _template/marina 
{
   "index_patterns" :
     ["marina-*"],
     "settings":{
       "index": {
         "number_of_shards":3,
         "number_of_replicas":1
      }
      },
      "mappings":{
          "_source":{
            "enabled":true
         },
              "properties" : {
         "message": {
            "properties":{
            "logstash_id":{
               "type":"keyword"
            },
            "event_timestamp_millis":{
               "type":"date"
            },
            "activity_date":{
               "type":"date",
               "format":"yyyy-MM-dd"
            },
            "cid":{
               "type":"keyword"
            },
            "activity_ip":{
               "type":"ip"
            },
            "ref_param":{
               "type":"text"
            },
            "referer":{
               "type":"keyword"
            },
            "user_agent":{
               "type":"text"
            }
         }
          }
      }
   }
}

【问题讨论】:

    标签: elasticsearch filebeat


    【解决方案1】:

    这是我自己的答案 - 在我开始工作后:

    关键是在 filebeat.yml 中禁用 ILM(索引生命周期管理),如果您之前的实验中有任何挥之不去的模板/索引/别名,请从头开始。

    以下两个操作让我进入了一个正常工作的 Filebeat,将 GCP PubSub 中的数据索引到 ES 中的自定义索引中:

    1. 停止 Filebeat

    2. 清除所有现有的索引/模板(ILM 策略 - 如果您为此索引模式定义了任何内容) - “全部”是指所有相关的,用于您尝试在 ES 中使用的索引和模式;以下命令很有用:

      删除 *

      删除_模板/

    3. filebeat.yml 中禁用 ILM - 在“Elasticsearch 模板设置”组中:

      setup.ilm.enabled: false

    4. 启动 Filebeat

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 2011-09-18
      • 2019-01-14
      • 2018-07-03
      • 2021-02-16
      • 1970-01-01
      • 2015-11-03
      相关资源
      最近更新 更多