我有几个安装了filebeat的Web服务器,我希望每个主机有多个索引。
我当前的配置看起来像
input {
beats {
ports => 1337
}
}
filter {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}"}
}
geoip {
source => "clientip"
}
}
output {
elasticsearch {
if [beat][hostname] == "luna"
{
hosts => "10.0.1.1:9200"
manage_template => true
index => "lunaindex-%{+YYYY.MM.dd}"
document_type => "apache"
}
}
}
然而,上述结果导致了
给定的配置无效。原因:在第22行第6列(字节346)中预期#,=>之一
这是if语句发生的地方。有帮助吗?
我想以嵌套格式将上述内容作为
if [beat][hostname] == "lina"
{
index = lina
}
else if [beat][hostname] == "lona"
{
index = lona
}
等任何帮助吗?
要访问任何内部字段,您必须使用%{}将其括起来。
试试这个
%{[beat][hostname]}
有关更多解释,请参阅this。
更新:
使用带有==的%{[beat] [hostname]}将无效,请尝试
if "lina" in [beat][hostname]{
index = lina
}
线程很旧但希望有人会觉得这很有用。插件定义不允许其中包含条件,因此也不允许出现错误。条件必须包括如下的整个定义。另外,请参阅documentation了解详情。
output {
if [beat][hostname] == "luna" {
elasticsearch {
hosts => "10.0.1.1:9200"
manage_template => true
index => "lunaindex-%{+YYYY.MM.dd}"
document_type => "apache"
}
} else{
elasticsearch {
// alternate configuration
}
}
}
解决方案可以是:
在每个filebeat配置文件中定义,在prosperctor部分中定义文档类型:
document_type:luna
在您的管道配置文件中,检查类型字段
如果[式] ==“露娜”
希望这有帮助。