Splunk Search

How to extract values "good" and "bad" from my sample data into a new field named STATUS?

roopeshetty
Path Finder

Hi

I have a log file in which all the events has this below lines as common;

04:03:28 04/12/2016 good    201961028   1456 - Validation_Competed - ProductCode_3446565    0.133 sec, 1 row, 0 5:75127 200

04:03:32 04/12/2016 bad  201961028  1456 - Validation_Competed - ProductCode_3446569    0.133 sec, 1 row, 0 5:75127 200

Here in the above 2 events we have the words "good" and "bad" and I need to a create a new field by name "STATUS" for them which should have its values as either "good" or "bad".

Can some one please advise me the right REX command to execute here?

Thanks
Roopesh

0 Karma

badrinath_itrs
Communicator

This is a simple log format and rex should be fairly easy to extract the field you are interested and as suggested above.
If you not comfortable with rex , I would suggest to use the splunk field extractor utility and create the required field first during search time and then you can use the newly created field in your search .

See below documentation for more details .

http://docs.splunk.com/Documentation/Splunk/latest/Knowledge/ExtractfieldsinteractivelywithIFX

0 Karma

acharlieh
Influencer

So the simplest answer of course is ... | rex "(?<STATUS>good|bad)" this assumes however that neither good nor bad show up in your events other than the status field and your status field only takes the values of good and bad.

You could anchor the regular expression based on the date format outside of the capturing group. You'd want to play with samples of your data and a site like regex101.com to develop expressions. Eventually you could build a field extraction for your sourcetype and not need the Rex command in your search.

raj_mpl
Path Finder

... | rex "(?<STATUS>good|bad)" will help you

0 Karma

apurva1707
New Member

Hi,
This regex should work for you : \d\s(\w+)\s\d

Hope this is what you are looking for. 🙂

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...