Grok 过滤器无法正常工作

Grok 过滤器无法正常工作

我在 Debian 服务器上安装了 Filebeat-7.1,这个 Filebeat 会将数据从这个 Debian 服务器中的文件发送到带有 Logstash 7.6 的服务器,以下是文件配置

Filebeat.yml:

#=========================== Filebeat inputs =============================

filebeat.inputs:

type: log

Change to true to enable this input configuration.
enabled: true
paths:

/root/code/cigol/logs/server.log
json.keys_under_root: true
json.overwrite_keys: true
json.add_error_key: true
force_close_files: true
fields:
env: dev
type: voiceserver.log

type: log
enabled: true
paths:
- /usr/local/freeswitch/log/freeswitch.log
force_close_files: true
fields:
env: dev
type: freeswitch.log

processors:

drop_fields:
fields: ["agent.ephemeral_id", "time", "agent.hostname", "agent.id", "agent.type", "agent.version", "ecs.version", "input.type", "log.offset", "@version", "fields.env", "tags"]
#----------------------------- Logstash output --------------------------------
output.logstash:

hosts: ["35.171.202.75:5044"]

--------------------------------logstash.conf----------------------------------------------------------------------------------------- 输入.conf

input {
beats {
port => 5044
}
}

过滤器配置文件

filter{
if [fields][env] == "dev" {
if [source] == "/root/code/cigol/logs/server.log" {
json {
source => "message"
}
}
} else
if [source] == "/usr/local/freeswitch/log/freeswitch.log" {
grok {
match => { "message" => "%{NOTSPACE:uuid} %{TIMESTAMP_ISO8601:date} [%{LOGLEVEL:loglevel}] %{GREEDYDATA:message}" }
remove_field => ["message"]
}
}
}

输出配置文件

output {

elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "%{[fields][type]}-%{+YYYY.MM.dd}"
}
stdout { codec => rubydebug }
}

应用程序日志格式

79110982-6d35-4b80-9be7-6ec9772313f9 2020-04-21 14:25:55.001130 [DEBUG] switch_core_state_machine.c:749 (sofia/3clogic_external/[email protected]:5505) State DESTROY

Kibana 输出

message 79110982-6d35-4b80-9be7-6ec9772313f9 2020-04-21 14:25:55.001130 [DEBUG] mod_sofia.c:364 sofia/3clogic_external/[email protected]:5505 SOFIA DESTROY

我想将消息分为以下几种

"UUID" = 79110982-6d35-4b80-9be7-6ec9772313f9
"date" = 2020-04-21 14:25:55.001130
"loglevel" = DEBUG
"message" = switch_core_state_machine.c:749 (sofia/3clogic_external/[email protected]:5505) State DESTROY

答案1

您只需要转义特殊字符:

[%{LOGLEVEL:loglevel}]

应该

\[%{LOGLEVEL:loglevel}\]

工作模式如下:

%{NOTSPACE:uuid} %{TIMESTAMP_ISO8601:date} \[%{LOGLEVEL:loglevel}\] %{GREEDYDATA:message}

相关内容