Whats's wrong with conditional? How can I separate logs - my goal is send several types of logs (apache, mysql, some other software) by one filebeat with different fields.type option and filtering in logstash pipeline with input - beats
I expect "true" in conditional, then grok "message" + retrieve timestamp with data + adding tag with mutate. And for all cases delete standart tag. Now it only delete standart tag. If i delete IF statement, it works fine.
@Tek_Chand, where is "application_log" in my message from filebeat? I should replace fields.type in filebeat config from "apache_access" to "apache_log"?
application_log is just for reference you can change it as per your settings.
In your logstash configuration you have used if condition but didn't used else. But you need to use else also.
Your configuration should be look like below:
input {
beats {
port => 5044
}
}
filter {
if [type] == "apache_access" {
grok {
match => { "message" => ["%{HTTPD_COMMONLOG}", "%{HTTPD_COMBINEDLOG}"] ] }
}
date {
date {
match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
}
mutate {
add_tag => ["apache_access"]
}
}
else {
grok {
match => { "message" => [ "(?<date-time>[\w\s\d\:]+)\s(?<IP>192.168.50.1)\s(?<port>582)\:\s(?<message>.*)" ] }
}
}
}
output {
if [type] == "apache_access"
elasticsearch {
hosts => ["10.133.58.12:9200"]
sniffing => true
manage_template => false
# index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
# index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
index => "application-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
else
{
elasticsearch {
hosts => ["10.133.58.12:9200"]
sniffing => true
manage_template => false
# index => "%{[@metadata][beat]}-%{+YYYY.MM.dd}"
index => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"
document_type => "%{[@metadata][type]}"
}
}
}
Above configuration is for your help it may will not work at your end. You may need to make changes at your end as per your detail and configuration like index name, IPs etc.
Thanks.
Ok. I think found solution - adding "fields_under_root: true" option to filebeat let me use "if [type] == "application_log"" conditional. Maybe using sub-dictionary fields in conditionals is forbidden?
No, it is not forbidden, but the syntax to reference a sub-field in logstash is [fields][type]. [fields.type] would reference a field that contains a period in its name.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.