如果我们可以有一个 api 来配置初始的“配置索引模式”页面以供自动化工具或脚本使用,那将会很有帮助。
同意,这将是很好的。 将映射解析移至服务器端以改进对大型映射的处理也很棒。
我第三个。 在过去的 2 个小时里,我一直在敲击 cURL 请求来执行此操作,但我一无所获。 我会继续尝试……但是从其他语言以编程方式运行的初始索引模式创建方法将非常有益。
是的,我也遇到过这个问题,我的解决方案(解决方法)与您的类似,我直接写入 .kibana index ,本质上,在 Ansible 中,我最终会在部署后任务中执行类似的操作:
curl -XPUT http://<es node>:9200/.kibana/index-pattern/events-* -d '{"title" : "events-*", "timeFieldName": "EventTime"}'
curl -XPUT http://<es node>:9200/.kibana/config/4.1.1 -d '{"defaultIndex" : "events-*"}'
我真的不想写入该索引,但我也不想使用 Kibana HTTP 流......所以我有兴趣以更受支持的方式执行此操作。
如果它以某种方式自动化,那就太好了——我们目前正在使用Elasticdump来实现这一点,这是一个相当好的解决方案,但它需要首先“手动”创建索引,导出,然后添加到我们的木偶代码。
以 #5199 结束
这被关闭以支持 5199,但 5199 被放弃了 - 有没有机会拿回来?
Kibana 5 网页是POST
到
我能够用这个POST
将索引添加到 ES 5
curl -XPOST -H 'Content-Type: application/json' \
'http://localhost:9200/.kibana/index-pattern/filebeat-*' \
-d'{"title":"filebeat-*","timeFieldName":"@timestamp","notExpandable":true}'
但我无法弄清楚 defaultIndex 的存储位置。
POST
到http://localhost :9200/.kibana/config/
您可以将kbn-xsrf
标头设置为任何内容,它似乎没有得到检查:
curl ${KIBANASERVER}/api/kibana/settings/defaultIndex \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/plain, */*" \
-H "kbn-xsrf: anything" -H "Connection: keep-alive" \
--data-binary ${YOURDEFAULTINDEX} -w "\n" --compressed
嗯,希望在 5.x 中对此进行 GET。
$ curl http://localhost:9200/api/kibana/settings/defaultIndex
No handler found for uri [/api/kibana/settings/defaultIndex] and method [GET]
$ curl http://localhost:9200/.kibana/config/
{"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"No endpoint or operation is available at [config]"}],"type":"illegal_argument_exception","reason":"No endpoint or operation is available at [config]"},"status":400}
看起来您在弹性(端口 9200)而不是在 Kibana 触发了您的第一个 GET。
对于使用 curl 和 jq 的 kibana 6.0:
url="http://localhost:5601"
index_pattern="logstash-*"
time_field="@timestamp"
# Create index pattern and get the created id
# curl -f to fail on error
id=$(curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
"$url/api/saved_objects/index-pattern" \
-d"{\"attributes\":{\"title\":\"$index_pattern\",\"timeFieldName\":\"$time_field\"}}" \
| jq -r '.id')
# Create the default index
curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
"$url/api/kibana/settings/defaultIndex" \
-d"{\"value\":\"$id\"}"
谢谢@hobti01 ! 这似乎也适用于 Kibana 5.6.4
我发现在 Kibana 5.0(可能还有 6.0)中,您可以设置一个特定的Index pattern ID
而不是随机生成一个作为@hobti01的脚本存储在id=$(... | jq -r '.id')
中; 这相当于在 UI 中设置以下字段:
设置给定 ID 对于自动 Kibana 部署特别方便,因为您导出的仪表板等将始终引用固定 ID 而不是随机 ID。
您可以通过POST
将该 ID 设置为/api/saved_objects/index-pattern/THE_ID
。
例如:
curl -f -XPOST -H 'Content-Type: application/json' -H 'kbn-xsrf: anything' 'http://localhost:5601/api/saved_objects/index-pattern/logstash-*' '-d{"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}'
@hobti01的脚本调整为使用固定 ID:
#!/usr/bin/env bash
# From https://github.com/elastic/kibana/issues/3709
set -euo pipefail
url="http://localhost:5601"
index_pattern="logstash-*"
id="logstash-*"
time_field="@timestamp"
# Create index pattern
# curl -f to fail on error
curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
"$url/api/saved_objects/index-pattern/$id" \
-d"{\"attributes\":{\"title\":\"$index_pattern\",\"timeFieldName\":\"$time_field\"}}"
# Make it the default index
curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
"$url/api/kibana/settings/defaultIndex" \
-d"{\"value\":\"$id\"}"
当 ID 已经存在时,脚本将失败并显示curl: (22) The requested URL returned error: 409 Conflict
并退出代码 22。
@nh2您可以在使用静态 ID 时将管道移除到 jq - 感谢您的建议!
您可以在使用静态 ID 时将管道移除到 jq
哎呀,对了! 已编辑。
当 ID 已经存在时,脚本将失败并返回
curl: (22) The requested URL returned error: 409 Conflict
并退出代码 22。
如果您不想这样做,而是想要覆盖行为,请使用"$url/api/saved_objects/index-pattern/$id?overwrite=true"
进行第一次 curl 调用。
然后,您将在每次执行此操作时version
计数的地方得到响应,例如:
{"id":"logstash-*","type":"index-pattern","version":2,"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}
{"id":"logstash-*","type":"index-pattern","version":3,"attributes":{"title":"logstash-*","timeFieldName":"@timestamp"}}
我还刚刚为 Kibana 编写了一个export.json
CLI 导入器工具: https ://github.com/nh2/kibana-importer
连同这个和上面的 index-pattern-creation curl,我现在可以以完全声明的方式部署 Kibana,而无需手动加载任何内容。
仅供参考,尝试针对 es 6.2.2 失败:
/ # curl http://es-api.kube-system.svc.cluster.local:9200
{
"name" : "Yw3vJ4X",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "HWh0uIo2Q6uL4LOZXnau5Q",
"version" : {
"number" : "6.2.2",
"build_hash" : "10b1edd",
"build_date" : "2018-02-16T19:01:30.685723Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
/ # curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" 'http://es-api.kube-system.svc.cluster
.local:9200/api/saved_objects/index-pattern/logstash-*' -d'{"attributes":{"title":"logstash-*","timeFieldName":"<strong i="6">@time</strong>
stamp"}}'
curl: (22) The requested URL returned error: 400 Bad Request
有什么建议?
@matthewadams看起来您是在不使用“.kibana”端点的情况下向 elasticsearch 发出请求。 尝试将 POST 直接发送到 kibana。
如果您更喜欢从文件系统加载仪表板和索引模式的方法(用于 Chef、Puppet、Salt 等),请保证: https ://github.com/elastic/kibana/issues/2310
@sandstrom如果通过“担保”,您的意思是对这个问题竖起大拇指,我做到了。 :) 很高兴知道我不是唯一一个。
最有用的评论
对于使用 curl 和 jq 的 kibana 6.0: