02/07/2017 - ELASTICSEARCH, LINUX
Bu örneğimizde, Filebeat ile iki ayrı log dosyasındaki içerikleri Logstash'a ileteceğiz ve bu içerikler kendileri ile alakalı olan Elasticsearch indexlerine kaydedilecekler.
filebeat:
prospectors:
-
paths:
- /var/log/apache2/access.log
input_type: log
document_type: apache-access
-
paths:
- /var/log/symfony/dev.log
input_type: log
document_type: symfony-dev
Gördüğümüz gibi mutate
bloğunu kullanarak, "output" bloğunda kullanmak için bir tane Elasticsearch değişkeni yaratıyoruz. Eğer isterseniz mutate
bloğunu "if" ve "else" blokları içine taşıyabilirsiniz.
input {
beats {
port => 5044
}
}
filter {
if [type] == "apache-access" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
} else if [type] == "symfony-dev" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
}
mutate {
add_field => { "index_name" => "web-%{type}" }
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
sniffing => true
manage_template => false
index => "%{index_name}"
}
}
Gördüğümüz gibi "if" kondisyonu kullanmadan "output" bloğu içinde type
kullanıyoruz.
input {
beats {
port => 5044
}
}
filter {
if [type] == "apache-access" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
} else if [type] == "symfony-dev" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
sniffing => true
manage_template => false
index => "web-%{type}"
}
}
Gördüğümüz gibi "if" kondisyonu kullanarak "output" bloğu içinde type
kullanıyoruz. Burada aynı satırları bilerek iki kere yazdım.
input {
beats {
port => 5044
}
}
filter {
if [type] == "apache-access" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
} else if [type] == "symfony-dev" {
grok {
match => { "message" => "%{COMBINEDAPACHELOG}" }
}
}
}
output {
if [type] == "apache-access" {
elasticsearch {
hosts => ["localhost:9200"]
sniffing => true
manage_template => false
index => "web-%{type}"
}
} else if [type] == "symfony-dev" {
elasticsearch {
hosts => ["localhost:9200"]
sniffing => true
manage_template => false
index => "web-%{type}"
}
}
}