Splunk Search

How to extract fields from two separate events into two separate fields, not one single field?

email2vamsi
Explorer

The following block shows two events with their headers.
The first event has four fields. The second event has five fields.
When I am doing the field extraction using the Field Extractor, Script field in event one and Script_1 field in event two are getting extracted into the same field. I am doing it on comma delimiter basis. This is happening because both Script and Script_1 fields are have 4th place in the order of events.

I do not want both these fields to be in one field. I want them as Script="Script /test.sh ran" and Script_1="Test Script".

EventID, Date_Time , Server , Script
15391 , Dec 06 15:46:22 , TestServer , Script /test.sh ran

EventID, Date_Time_1 , Server_1 , Script_1 , Status_1
15391 , Dec 06 15:47:12 , TestServer , Test Script, State : failed.

0 Karma
1 Solution

sundareshr
Legend

You should be able to create a calculated field with the following eval

eval script_1=if(isnotnull(status_1), script, null())

http://docs.splunk.com/Documentation/Splunk/6.5.0/Knowledge/definecalcfields

View solution in original post

0 Karma

sundareshr
Legend

You should be able to create a calculated field with the following eval

eval script_1=if(isnotnull(status_1), script, null())

http://docs.splunk.com/Documentation/Splunk/6.5.0/Knowledge/definecalcfields

0 Karma

email2vamsi
Explorer

Thank you.I could not relate from your given eval.
I would like to explain the problem again.

When i make the FX for first event using the fields mentioned in the header, the second event is getting extracted as well. Now Script field has both the values "Test Script" and "Script /test.sh ran"
I want Script="Test Script" and Script_1="Script /test.sh ran".

EventID, Date_Time , Server , Script , Status
15391 , Dec 06 15:47:12 , TestServer , Test Script , State : failed.
15391 , Dec 06 15:46:22 , TestServer , Script /test.sh ran

0 Karma

sundareshr
Legend

Did this work> If not, can you share the results you're getting

0 Karma

jmallorquin
Builder

Hi,

You should use different sourcetypes for each output of the scripts, in that way you will be able to address what you want.

Hope i help you

0 Karma

email2vamsi
Explorer

Thank you.
But both the events are coming from the same log file. Is there a way to divide them into two sourcetypes?

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

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...