Splunk Search

Difference between time fields in different events based off of the value of another field

fmatera
Explorer

I would like to find the difference of time where based on the value of field "disposion", I choose the time value form another field.
for start idisposion="ANSWERED", I use field answer
for stop disposion="NO ANSWER", I use field cr-date

I have tried this:

based search | eval start =
if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d
%H:%M:%S"),0) |eval stop =
if(disposion="NO
ANSWER",strptime(cr_date,"%Y-%m-%d
%H:%M:%S"),0) |eval results =
stop-start |table results

And this:

base search | dedup disposion | eval
start = strptime(answer,"%Y-%m-%d
%H:%M:%S") | where
disposion="ANSWERED" |eval stop =
strptime(cr_date,"%Y-%m-%d %H:%M:%S")
|where disposion="NO ANSWER" |eval
results = stop-start |table results

Any ideas? Thanks

Tags (2)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@fmatera

Can you please try below search?

based search | eval start = if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d %H:%M:%S"),NULL) 
| eval stop = if(disposion="NO ANSWER",strptime(cr_date,"%Y-%m-%d %H:%M:%S"),NULL) 
| stats values(start) as start values(stop) as stop 
| eval results = stop - start 
| table results

If you have any unique id in event, like UNIQUE_ID then

based search | eval start = if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d %H:%M:%S"),NULL) 
| eval stop = if(disposion="NO ANSWER",strptime(cr_date,"%Y-%m-%d %H:%M:%S"),NULL) 
| stats values(start) as start values(stop) as stop by UNIQUE_ID  
| eval results = stop - start 
| table UNIQUE_ID  results

My Sample Search:

| makeresults 
| eval disposion="ANSWERED",answer="2019-01-01 00:00:00" 
| append 
    [| makeresults 
    | eval disposion="NO ANSWER",cr_date="2019-01-01 00:05:00" ] 
| eval start = if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d %H:%M:%S"),NULL) 
| eval stop = if(disposion="NO ANSWER",strptime(cr_date,"%Y-%m-%d %H:%M:%S"),NULL) 
| stats values(start) as start values(stop) as stop 
| eval results = stop - start 
| table results

Thanks

View solution in original post

arkadyz1
Builder

It's not clear - do you want to have both start and stop calculated within the same event, or do you group your events somehow and then one of the events in the group should provide a 'start' while another yields 'stop'? Can you show at least a small extract of the relevant fields of your data and explain what you are trying to achieve?

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@fmatera

Can you please try below search?

based search | eval start = if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d %H:%M:%S"),NULL) 
| eval stop = if(disposion="NO ANSWER",strptime(cr_date,"%Y-%m-%d %H:%M:%S"),NULL) 
| stats values(start) as start values(stop) as stop 
| eval results = stop - start 
| table results

If you have any unique id in event, like UNIQUE_ID then

based search | eval start = if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d %H:%M:%S"),NULL) 
| eval stop = if(disposion="NO ANSWER",strptime(cr_date,"%Y-%m-%d %H:%M:%S"),NULL) 
| stats values(start) as start values(stop) as stop by UNIQUE_ID  
| eval results = stop - start 
| table UNIQUE_ID  results

My Sample Search:

| makeresults 
| eval disposion="ANSWERED",answer="2019-01-01 00:00:00" 
| append 
    [| makeresults 
    | eval disposion="NO ANSWER",cr_date="2019-01-01 00:05:00" ] 
| eval start = if(disposion="ANSWERED",strptime(answer,"%Y-%m-%d %H:%M:%S"),NULL) 
| eval stop = if(disposion="NO ANSWER",strptime(cr_date,"%Y-%m-%d %H:%M:%S"),NULL) 
| stats values(start) as start values(stop) as stop 
| eval results = stop - start 
| table results

Thanks

fmatera
Explorer

Thanks. Worked perfectly!

0 Karma

p_gurav
Champion

Can you please provide sample data?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Value Insights: Now Generally Available in the CMC

Organizations are under pressure to move faster, control cost, expand AI adoption, and prove value with more ...

What’s New in Splunk AI: Volume 02

Welcome to the second edition of “What’s New in Splunk AI” where we look at the latest and greatest updates, ...

Splunk App Dev Quarterly Roundup: AI, Agents, and Innovation!

Another quarter, another wave of innovation. From complex integrations to pushing the limits ...