Splunk Search

rex extraction of multiple fields from a record (multi-line)

nocostk
Communicator

I'm trying to extract some Oracle audit log fields on the fly. I can't seem to get my regex to match.

Source:

Audit file /u01/app/oracle/admin/prodprt/adump/prodprt2_ora_8944_1.aud
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0.2/prodprt
System name:    Linux
Node name:  prodprtdb02
Release:    2.6.18-164.el5
Version:    #1 SMP Thu Sep 3 04:15:13 EDT 2009
Machine:    x86_64
Instance name: prodprt2
Redo thread mounted by this instance: 2
Oracle process number: 107
Unix process pid: 8944, image: oracle@prodprtdb02 (TNS V1-V3)
Wed Mar 16 09:01:08 2011 -06:00
LENGTH : '155'
ACTION :[7] 'CONNECT'
DATABASE USER:[1] '/'
PRIVILEGE :[6] 'SYSDBA'
CLIENT USER:[6] 'oracle'
CLIENT TERMINAL:[0] ''
STATUS:[1] '0'
DBID:[10] '1941709108'

Search string:

rex field=_raw "DATABASE\s+USER:\[\d\]\s+'(?<db_user>.+)?' PRIVILEGE\s+:\[\d\]\s+'(?<db_privilege>.+)?'"

I'm not sure how to indicate that there are one or more lines between the two.

Tags (1)
1 Solution

Ayn
Legend

You need to use the modifier (?s) at the start in order to have the regex match newlines as whitespace. This should work:

rex field=_raw "(?s)DATABASE\s+USER:\[\d\]\s+'(?<db_user>.+?)'\s+PRIVILEGE\s+:\[\d\]\s+'(?<db_privilege>.+?)'"

View solution in original post

Ayn
Legend

You need to use the modifier (?s) at the start in order to have the regex match newlines as whitespace. This should work:

rex field=_raw "(?s)DATABASE\s+USER:\[\d\]\s+'(?<db_user>.+?)'\s+PRIVILEGE\s+:\[\d\]\s+'(?<db_privilege>.+?)'"

ma_anand1984
Contributor

@gkanapathy

Very good comment. Thank you for leaving such comments

0 Karma

gkanapathy
Splunk Employee
Splunk Employee

Also note that \s will match against newlines, so you can also do (irrespective of the (?s) option) [\s\S] to match any character including newlines. The (?s) option causes . to match newlines, which it typically does not do.

nocostk
Communicator

That did it, thanks!

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...