我正在进行ELK堆栈配置 . logstash-forwarder用作日志托运者,每种类型的日志都标记有type-tag:
{
"network": {
"servers": [ "___:___" ],
"ssl ca": "___",
"timeout": 15
},
"files": [
{
"paths": [
"/var/log/secure"
],
"fields": {
"type": "syslog"
}
}
]
}
那部分工作正常......现在,我希望logstash将消息字符串拆分为其部分;幸运的是,这已经在默认的grok模式中实现了,所以到目前为止logstash.conf仍然很简单:
input {
lumberjack {
port => 6782
ssl_certificate => "___" ssl_key => "___"
}
}
filter {
if [type] == "syslog" {
grok {
match => [ "message", "%{SYSLOGLINE}" ]
}
}
}
output {
elasticsearch {
cluster => "___"
template => "___"
template_overwrite => true
node_name => "logstash-___"
bind_host => "___"
}
}
我在这里遇到的问题是,elasticsearch收到的文档仍然保留了消息字段中的整行(包括时间戳等) . 此外,@ timestamp仍然显示logstash收到消息的日期,这使得搜索不好,因为kibana确实在查询@timestamp以便按日期过滤...任何想法我做错了什么?
谢谢,丹尼尔
2 回答
"message"字段包含原始日志行(包括时间戳等)的原因是默认情况下grok过滤器不允许覆盖现有字段 . 换句话说,即使SYSLOGLINE pattern,
将消息捕获到"message"字段中,它不会覆盖当前字段值 . 解决方案是设置grok filter's "overwrite" parameter .
要填充"@timestamp"字段,请使用date filter . 这可能对你有用:
如果没有看到导致问题的示例事件,很难知道问题 . 我建议你尝试使用grok debugger来验证模式是否正确,并在看到问题后根据需要进行调整 .