%{SYNTAX:SEMANTIC}
按照%{SYNTAX:SEMANTIC}
语法进行匹配,将SYNTAX匹配到的内容保存到SEMANTIC字段中
filter{
grok{
match => { "message" => "%{IP:ip} %{NUMBER:number} %{WORD:word} %{URIPATHPARAM:uripathparam}"}
}
}
{
"message": "192.168.10.100 185 grok /index.html",
"word": "grok",
"number": "185",
"ip": "192.168.10.100",
"uripathparam": "/index.html"
}
正常情况下匹配到的数据都是字符类型
目前支持转换int类型和float类型
格式:%{NUMBER:num:int}
filter{
grok{
# 将转换的结果转换为整形
match => {"message" , "%{NUMBER:number:int}"}
}
}
{
"message": "185.76",
"number": 185
}
filter{
grok{
# 如果第一个匹配不成功则匹配下一个
match => [
"message" , "%{IP:ip} %{NUMBER:number} %{WORD:word} %{URIPATHPARAM:uripathparam}",
"message" , "%{IP:ip} %{WORD:word}"
]
}
}
{
"message": "192.168.10.100 185 Jack /index.html",
"word": "Jack",
"number": "185",
"ip": "192.168.10.100",
"uripathparam": "/index.html"
}
{
"word": "Jack",
"message": "192.168.10.100 Jack",
"ip": "192.168.10.100"
}
# ./patterns/extra
TEST_RE [0-9 A-F]{10,11}
filter{
grok{
# 自定义正则表达式路径
patterns_dir => ["./patterns"]
match => { "message" => "%{TEST_RE:test_re}"}
}
}
filter{
grok{
break_on_match => "false"
match => {
"message" => "%{NUMBER:number1} %{WORD:name1}"
}
match => {
"message" => "%{INT:int2} %{WORD:name2}"
}
}
}
{
"message": "173 Jack",
"int2": "173",
"number1": "173",
"name1": "Jack",
"name2": "Jack"
}
filter{
grok{
match => {
"message" => "%{NUMBER:message} %{WORD:name}"
}
overwrite => ["message"]
}
}
{
"message": "173",
"name": "Jack",
"event": {
"original": "173 Jack"
}
}
filter{
grok{
match => {
"message" => "%{NUMBER:number} %{WORD:name}"
}
target => "result"
}
}
{
"result": {
"number": "173",
"name": "Jack"
},
"message": "173 Jack"
}