分类: LINUX
2015-04-01 20:51:17
需求:
比如 path => /wls/applogs/rtlog/icore-pts2SF2433/icore-pts2SF2433.out
想提取icore-pts 与 icore-pts2SF2433/icore-pts2SF2433.out
第一种方法:用grok 处理
filter {
grok {
match => ["path","/wls/applogs/rtlog/(?
add_field => {
"app_path" => "%{apppath}"
"app_name" => "%{servername}"
}
}
}
|
第二种方法:用Ruby 处理
filter {
ruby {
code=>"
event['app_path']=event['path'].dup.sub!(/\/wls\/applogs\/rtlog/,'')
tmp=event['path'].dup.sub!(/\/wls\/applogs\/rtlog\//,'')
event['app_name']=tmp.sub!(/\d.*/,'')
"
}
}
|
问题:
event['path'].sub!(/\/wls\/applogs\/rtlog/,'')
Exception in filterworker {"exception"=>#
|
原因:
ruby 不允许直接改对象,可以复制 or 克隆一下后再改(加dup)
event['path'].dup.sub!(/\/wls\/applogs\/rtlog\//,'')
|