Splunk Search

Extract a number from event message field

codebased
Explorer

Hi Guys,

I have been trying to extract the number at the end of EVENT_MESSAGE field.

Text sample:
SERVER=SERVERNAME; EVENT_MESSAGE=Number of Offers ready to send: 6

I am using the following query:

rex field=EVENT_MESSAGE "Number of Offers ready to send: (?<offercount>\d+$)" | table offercount

However I am not getting any result; the offercount result is empty.

Tags (1)
0 Karma
1 Solution

DalJeanis
Legend

Just for grins, try this -

| rex field=_raw "Number of Offers ready to send: (?<offercount>\d+)"

If it works, then EVENT_MESSAGE is probably somehow not an extracted field.

View solution in original post

DalJeanis
Legend

Just for grins, try this -

| rex field=_raw "Number of Offers ready to send: (?<offercount>\d+)"

If it works, then EVENT_MESSAGE is probably somehow not an extracted field.

yuanliu
SplunkTrust
SplunkTrust

Unless you have some customised field extraction for EVENT_MESSAGE, Splunk will automatically assign "Number" to EVENT_MESSAGE instead of "Number of Offers ready to send: 6" that @codebased seems to expect. The above should work. (field=_raw is assumed by default so no need to specify.)

codebased
Explorer

Indeed it is not a field!

0 Karma

DalJeanis
Legend

@codebased - I suspected so.

@yuanliu is correct that field=_raw is default, but on these forums I like to be explicit, in case a reader doesn't understand that the rex is operating on some specific field... like the one that in this case didn't exist...

0 Karma

dineshraj9
Builder

Try this

rex field=EVENT_MESSAGE "Number of Offers ready to send: (?<offercount>\d+)" | table offercount

codebased
Explorer

Thank you @dineshraj9. I was actually using ? but somehow it got removed from my original question. I have copied your snippet as it is but it is not working :(. The offercount is all empty.

0 Karma

codebased
Explorer

Thank you so much for your help. It is resolved. I had to use _raw.

0 Karma

dineshraj9
Builder

Can you paste the exact value in the EVENT_MESSAGE field? when I tested with the sample provided by you it worked.

| makeresults | eval EVENT_MESSAGE="Number of Offers ready to send: 6" | rex field=EVENT_MESSAGE "\D+(?<offercount>\d+)" | table offercount

You could also try -

<your search> | rex field=EVENT_MESSAGE "\D+(?<offercount>\d+)" | table offercount
0 Karma

codebased
Explorer

This is what I have tried:
APP_PATH="/Apiv0" EVENT_MESSAGE=Number of Offers ready to send | rex field=EVENT_MESSAGE "\D+(?\d+)" | table offercount

My splunk log is:

2017-06-15 03:00:12.8818; LOG_LEVEL=Info; SOURCE=JobRepository; APP_PATH=/Apiv0; VERSION=0.1.0.90; CORRELATION_IDENTIFIER=fe800697-df6a-4ce6-9438-27d106ab0005; SERVER=XXXX; EVENT_MESSAGE=Number of Offers ready to send: 6

The result is:

Events (14)
- ...
Statistics (14)
- Empty List

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...