input { #使用beats 收集 日志
beats {
port => "5044"
}
}
filter {
if [fields][logtype] == "access" {
grok {
match => {
"message" => '%{HTTPDATE:logdate}' #得到时间格式 15/May/2019:19:45:31 +0800,时间格式由日志中格式决定
"message" => '%{IP:clientip}'
}
}
#HTTPDATE, IP 规则在https://github.com/logstash-plugins/logstash-patterns-core/blob/master/patterns/grok-patterns , 可以自定义
date {
match => ["logdate", "dd/MMM/yyyy:HH:mm:ss Z"] #匹配日志中的时间 到logdate
}
geoip {
source => "clientip"
target => "geoip"
}
}
if [fields][logtype] == "catalina" {
grok {
match => {
"message" => '%{TIMESTAMP_ISO8601:logdate}' #匹配日志中的时间 到logdate, 得到时间格式 2019-5-16 03:12:40时间格式由日志中格式决定
}
pattern_definitions => {
"MESSAGE" => "[\s\S]*"
}
}
date { #使用logdate到@timestamp l
match => ["logdate", "yyyy-MM-dd HH:mm:ss","dd/MM/yyyy:HH:mm:ss Z"]
locale => en
timezone => "+0800" #由于logdate 没带时区,应用到@timestamp 中会有时区转换, 不加会导致时间戳会+8 小时
}
}
}
output {
if [fields][logtype] == "catalina" {
elasticsearch {
hosts => ["host_IP:9200"]
index => "%{[fields][env]}-catalina-%{+YYYY-MM}" #按月划分index
}
}
if [fields][logtype] == "access" {
elasticsearch {
hosts => ["host_IP:9200"]
index => "%{[fields][env]}-access-%{+YYYY-MM}"
}
}
}
目前使用版本ELKB7.0 详细看官网https://www.elastic.co/guide/en/logstash/current/index.html