Logstash 条件输出到 elasticsearch(每个 filebeat 主机名的索引)

use*_*171 2 elasticsearch logstash logstash-grok logstash-configuration

我有几个安装了 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"
  }
  }
}
Run Code Online (Sandbox Code Playgroud)

然而上面的conf结果是

给定的配置无效。原因:第 22 行第 6 列(字节 346)需要 #、=> 之一

这是 if 语句发生的地方。有什么帮助吗?

我希望将以上内容采用嵌套格式

if [beat][hostname] == "lina"
{
index = lina
}
else if [beat][hostname] == "lona"
{
index = lona
}
Run Code Online (Sandbox Code Playgroud)

等等。请问有什么帮助吗?

sha*_*608 6

该线程很旧,但希望有人会发现它有用。插件定义不允许在其中使用条件,因此会出现错误。条件必须包含整个定义,如下所示。另外,请参阅文档了解详细信息。

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
       }
    }
}
Run Code Online (Sandbox Code Playgroud)