我正在尝试配置FileBeats以将事件索引到具有某些字段的定制Map的定制命名索引中。问题是FileBeats不将事件发送到我的索引,而是尝试将它们发送到默认的‘filebeats-xxx’索引,并且失败并出现解析/Map异常,因为事件不符合默认的FileBeats事件格式(这就是我想使用我自己的Map的原因)。
详情见下文。
2021年9月10日更新:在发现此处报告/讨论的类似问题后:https://github.com/elastic/beats/issues/11866我尝试遵循解决方法,并将以下参数添加到文件beats.yml以禁用ES中的ILM:
setup.ilm.enabled: false
这也无济于事--文件节拍日志显示ILM已经设置。因此,我又添加了一个参数:
setup.ilm.overwrite: true
在此之后-错误已停止,但当我尝试推送事件时-在以下日志之后,文件节拍似乎挂起:
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主题获取事件。事件正在被成功接收(通过使用控制台输出确认),并被反 Package 到许多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"]
(请参阅下面的完整文件beat.yml配置)
我还想对事件字段使用我自己的类型-例如,对IP字段使用‘IP’类型,对所有日期特定的字段使用日期类型,等等。这就是为什么我想对这些事件使用我自己的Map。并将它们发送到具有我选择的名称的索引中-例如,仅用于测试,它是‘**marina-**xxx’:
我提出的完整Map/模板如下所示。一开始,我试着把它作为一个‘marina_es_template.json’文件放到文件拍根目录中,并让文件拍上传这个Map--所以我尝试了以下配置:
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
这不起作用-文件节拍没有正确上传模板-我在ES中找不到它(使用GET_TEMPLATE/marina命令)。因此,我使用PUT命令手动将其加载到ES中-它工作得很好,我可以看到ES中列出的模板,并且模板的内容是正确的。
因此,我试图解决的最后一个问题是让FileBeat真正将事件发送到‘marina-test1’索引中,并通过匹配索引名称模式将Map正确地应用于该索引
我为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'. ....}
这是正确的,因为在‘文件节拍’Map中,字段‘消息’应该是一个文本,而不是一个对象……
因此,问题是:我如何强制FileBeat将事件发送到我的‘marina-xxx’索引中,而不是‘filebeat-xxx’索引中?
谢谢!
以下是我的filebeat.yml:(为清楚起见,删除了注解/未使用的字段
# ============================== 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模板Map:
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"
}
}
}
}
}
}
2条答案
按热度按时间gwo2fgha1#
以下是我自己的答案--在我解决了这个问题之后:
关键是禁用文件beat.yml中的ILM(索引生命周期管理),如果您在以前的实验中有任何挥之不去的模板/索引/别名,请从头开始。
以下两个操作将我带到一个工作FileBeat,将GCP PubSub中的数据索引到ES中的定制索引中:
1.停止文件节拍
1.清除所有现有索引/模板(ILM策略--如果您为该索引模式定义了任何策略)-“所有”,我指的是您试图在ES中使用的索引和模式的所有相关索引/模板;以下命令非常有用:
删除*
删除模板/<模板名称>
1.关闭Elasticearch模板设置组中filebeat.yml中的ILM:
setup.ilm.enabled: false
1.启动文件节拍
4dbbbstv2#
正如elastic documentation所述:
如果启用了索引生命周期管理(这通常是默认设置),则将忽略setup.template.name和setup.template.Pattern。
设置
setup.ilm.enabled: false
就可以了!