【问题标题】:Logstash conditional output to elasticsearch (index per filebeat hostname)Logstash 有条件的输出到 elasticsearch(每个 filebeat 主机名的索引)
【发布时间】:2017-05-11 11:39:20
【问题描述】:

我有几个安装了 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
}

等等。有什么帮助吗?

【问题讨论】:

    标签: elasticsearch logstash logstash-grok logstash-configuration


    【解决方案1】:

    线程很旧,但希望有人会发现它有用。插件定义不允许在其中使用条件,因此会出现错误。条件必须包括整个定义,如下所示。另请参阅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
           }
        }
    }
    

    【讨论】:

      【解决方案2】:

      要访问任何内部字段,您必须用 %{} 将其括起来。

      试试这个

      %{[beat][hostname]}
      

      更多解释请见this

      更新:

      将 %{[beat][hostname]} 与 == 一起使用将不起作用,请尝试

      if "lina" in [beat][hostname]{
          index = lina
      }
      

      【讨论】:

      • 我试过了,但没用 - 我仍然遇到同样的错误
      • 我尝试了以下“输出 { if %{[beat][hostname]} == "test1" { elasticsearch { hosts => "10.0.1.1:9200" manage_template => true index => "testing-%{+YYYY.MM.dd}" document_type => "apache" } } }" if 语句还是有错误
      【解决方案3】:

      解决方案可以是:

      在你的每个filebeat配置文件中定义,在prosperctor部分定义文件类型:

      document_type: 月神

      在你的管道配置文件中,检查类型字段

      如果[type]=="luna"

      希望对您有所帮助。

      【讨论】:

      • 这不起作用,因为在我的情况下两种类型都是'apache'
      • 如果不想更改类型,可以添加如下标签:在filebeat配置文件中,在prospector部分添加:tags: ["luna"]在您的 logstash 管道中检查标签:if "luna" in [tags]
      • 其实这是个好主意——很快就会尝试一下
      • 太棒了!所以有用吗?
      猜你喜欢
      • 1970-01-01
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多