I use grok
and date
filter to set correct @timestamp
. It works in simple case. But when I added if condition @timestamp
no longer installed from the message.
filter {
if 'backend.info.log' in [log][file][path] {
grok {
match => [
"message", '(?m)%{LOGLEVEL:log-level} %{TIMESTAMP_ISO8601:timestamp}.*Пользователь - (?<user>[^;]+).*id - (?<user-id>[^;]+).*email - (?<email>[^;]+).*Агент клиента -(?<useragent>[^;]+).*ip - %{IP:client-ip}.*token: (?<token>[^\n|^\s]+).*Запрос: \"(?<request>[^\s^\"]+).*Метод: \"(?<method>[\w]+).*Параметры: (?<params>\{.*\}).*Модуль: (?<module>[^;]+).*Функция: (?<func>[^;]+), # backend.info.log
#### Other regexe #####
]
}
} else {
grok {
match => [
"message", "(?m)%{TIMESTAMP_ISO8601:timestamp} \[%{LOGLEVEL:log-level}\]%{GREEDYDATA:message}", # rabbitmq.info
"message", "%{LOGLEVEL:log-level} %{TIMESTAMP_ISO8601:timestamp}", # gunicorn.error
#### Other regexe #####
]
}
}
date {
match => ["message", "yyyy-MM-dd HH:mm:ss,SSS", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.SSS", "ISO8601"]
timezone => "Europe/Moscow"
}
}
I know about multiple regex inside the match, but I have a legacy logs in various formats and and I want to optimize logstash
work time by using if condition.