jonrust
(Jon Rust)
May 3, 2018, 4:43pm
1
Oracle alert logs contain multiple ORA- codes. I can't figure how to tell grok to match all and return an array of the matches.
if [msg] =~ /ORA-/ {
grok {
match => [ "msg","(?<ora_code>ORA-[0-9]+)" ]
}
}
Log example might have:
ORA-12345: some message ORA-45678: some other message
Is it possible?
yaauie
(Ry Biesemeyer)
May 3, 2018, 4:49pm
2
jonrust
(Jon Rust)
May 3, 2018, 4:51pm
3
That didn't do the trick. Tried this:
if [msg] =~ /ORA-/ {
grok {
break_on_match => false
match => [ "msg","(?<ora_code>ORA-[0-9]+)" ]
}
}
yaauie
(Ry Biesemeyer)
May 3, 2018, 5:13pm
4
d'oh! that flag will keep looking at patterns but not at the input after a match. I think I can whip up something quick with a ruby script for you though.
Use ruby.
code => "
s = event.get('message')
r = s.scan(/(ORA-[0-9]{5})/)
r = r.flatten
event.set('OracleErrors', r.join('/'))
"
Actually, if you want an array, do not do the join, just set OracleErrors to r.
jonrust
(Jon Rust)
May 3, 2018, 5:36pm
6
That did the trick. Thanks.
if [msg] =~ /ORA-/ {
ruby {
code => "
mat = event.get('msg').scan(/(ORA-[0-9]+)/)
event.set('ora_code', mat.flatten)
"
}
yaauie
(Ry Biesemeyer)
May 3, 2018, 6:11pm
7
I whipped up a quick ruby filter with tests that capture edge-cases (such as the event not having a value at msg
, or the string containing no matches):
capture-filter.rb
# Copyright 2018 Ry Biesemeyer (@yaauie)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
This file has been truncated. show original
1 Like
system
(system)
Closed
May 31, 2018, 6:11pm
8
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.