Splunk Search

Rex with optional end of message

splunksogetiht
Explorer

Hi

I have a log like that :

2014-29-08 08:28:45,817.366  - INFO - message1
2014-29-08 08:28:45,817.366  - WARN - message2 ID = 458315
2014-29-08 08:28:45,817.366  - DEBUG- message3 ID = 8
2014-29-08 08:28:45,817.366  - INFO - message4

I want to extract message1, message2, message3 and message4 in the same field "App_message".

I try this but it's not working :

rex "\s-\s+(?<App_level>[A-Z]+)\s*-\s+(?<App_message>.+)(?:ID\s=\s[0-9]+)?"

Help pls 🙂

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Assuming the message actually is longer than just a word, you can do this based off your original regex:

 rex "\s-\s+(?<App_level>[A-Z]+)\s*-\s+(?<App_message>.+?)(?:\s*ID\s=\s[0-9]+)?"

All I did was make the .+ non-greedy and added a \s* to the start of the optional end.

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Assuming the message actually is longer than just a word, you can do this based off your original regex:

 rex "\s-\s+(?<App_level>[A-Z]+)\s*-\s+(?<App_message>.+?)(?:\s*ID\s=\s[0-9]+)?"

All I did was make the .+ non-greedy and added a \s* to the start of the optional end.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Ah yeah, adding the end-of-line anchor is necessary.

0 Karma

splunksogetiht
Explorer

The message can be something like :

cCMSyncManager::LCRRerunperARNThread::Send ABDCng Requestfor ARN = F-WWTF, with TransactionID = 1857182350

or

cCMSyncManager::UpdateDatabaseThreshold::Data is pushed for deleting ARN::F-WWTF, TLM = WIREDand StreamID = 12

I just want extract the message without the "ID= ..." sequence.

I did a mistake in my original post : there is no space between "App_message" and the "ID = ..."

0 Karma

aweitzman
Motivator

You should take @martin_mueller's rex, remove the \s he added (since you've since stated it's not really there), and then instead of making the ID part optional with ?, make that clause something that either matches the ID part or the end of the line:

rex "\s-\s+(?<App_level>[A-Z]+)\s*-\s+(?<App_message>.+?)((?:ID\s=\s\d+)|$)"

splunksogetiht
Explorer

Ohhhh nice, it's working now ! 🙂

Really thank you !

0 Karma

aweitzman
Motivator

Replacing

(?<App_message>.+)

with

(?<App_message>\w+)

should help.

0 Karma

splunksogetiht
Explorer

But "App_message" can contain many caracters and not only alphanumeric :
( : ; - \ [ " ' $ ....

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 ...