Splunk Search

REGEX match on multiple conditions help

roguepacket
Engager

I need help with a REGEX that needs to match multiple conditions in a log event.

The event looks like this:

02:02:02.000 AM 
Mar 30 02:02:02 servername1 Oracle Audit[2225]: SESSIONID: "123456789" ENTRYID: "*****" USERID: "ABC" USERHOST: "server2"  OBJ$CREATOR: "LMN" OBJ$NAME: "value1" SES$ACTIONS: "--**********-" OS$USERID: "someusername" 

I need to send events to the nullQueue when all of the following conditions are met:

  1. USERHOST: "server2"
  2. OS$USERID: "someusername"
  3. USERID: "ABC"

This is the REGEX that I have in place, but doesn't seem to be working:

REGEX = (?s)(OS\$USERID:\s.someusername.).+?(USERHOST:\s.server2.).+?(USERID:\s.ABC.)

Any ideas on how to correct my failing regex?
THanks

Tags (1)
1 Solution

Ayn
Legend

Well since you put the "OS$USERID" match first of all in regex, but it's the last part of the event you're matching against, the whole regex will fail. You need to put the matching groups in the correct order. In your event, USERID comes first, followed by USERHOST and OS$USERID. So, something like this should work:

REGEX = (?s)(USERID:\s.ABC.).+?(USERHOST:\s.server2.).+?(OS\$USERID:\s.someusername.)

View solution in original post

Ayn
Legend

Well since you put the "OS$USERID" match first of all in regex, but it's the last part of the event you're matching against, the whole regex will fail. You need to put the matching groups in the correct order. In your event, USERID comes first, followed by USERHOST and OS$USERID. So, something like this should work:

REGEX = (?s)(USERID:\s.ABC.).+?(USERHOST:\s.server2.).+?(OS\$USERID:\s.someusername.)

the_wolverine
Champion

What is the purpose of (?s)

The regex did not work for me when I used it. Works fine without it (for me).

0 Karma

landen99
Motivator

"?" changes the "+" from greedy to lazy. Lazy means match as few as possible. Greedy means match as many as possible.

roguepacket
Engager

Worked perfectly! Thanks for your quick answer!

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...