Logstash 条件输出到 elasticsearch(每个 filebeat 主机名的索引)
Logstash conditional output to elasticsearch (index per filebeat hostname)
我有几个安装了 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"
}
}
}
但是上面的配置结果
The given configuration is invalid. Reason: Expected one of #, => at
line 22, column 6 (byte 346)
这是 if 语句发生的地方。有帮助吗?
我想以嵌套格式将上面的内容设置为
if [beat][hostname] == "lina"
{
index = lina
}
else if [beat][hostname] == "lona"
{
index = lona
}
等有什么帮助吗?
解决方案可以是:
在你的每个filebeat配置文件中定义,在prosperctor部分定义文件类型:
document_type: luna
然后在您的管道配置文件中,检查类型字段
if[type]=="luna"
希望对您有所帮助。
要访问任何内部字段,您必须用 %{} 将其括起来。
试试这个
%{[beat][hostname]}
有关更多说明,请参阅 。
更新:
将 %{[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 的 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"
}
}
}
但是上面的配置结果
The given configuration is invalid. Reason: Expected one of #, => at line 22, column 6 (byte 346)
这是 if 语句发生的地方。有帮助吗?
我想以嵌套格式将上面的内容设置为
if [beat][hostname] == "lina"
{
index = lina
}
else if [beat][hostname] == "lona"
{
index = lona
}
等有什么帮助吗?
解决方案可以是:
在你的每个filebeat配置文件中定义,在prosperctor部分定义文件类型:
document_type: luna
然后在您的管道配置文件中,检查类型字段
if[type]=="luna"
希望对您有所帮助。
要访问任何内部字段,您必须用 %{} 将其括起来。
试试这个
%{[beat][hostname]}
有关更多说明,请参阅
更新:
将 %{[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
}
}
}