Getting Data In

creating a time delta field

NeharikaVats
Loves-to-Learn

The requirement is to create a time delta field which has the value of time difference between the 2 time fields. Basically the difference between start time & receive time should populate under new field name called timediff.

 

I have created eval conditions, can anyone help me with a props config based on that.

index=XXX sourcetype IN(xx:xxx, xxx:xxxxx)
| eval indextime=strftime(_indextime,"%Y-%m-%d %H:%M:%S")
| eval it = strptime(start_time, "%Y/%m/%d %H:%M:%S")
| eval ot = strptime(receive_time, "%Y/%m/%d %H:%M:%S")
| eval diff = tostring((ot - it), "duration")
| table start_time, receive_time,indextime,_time, diff
Labels (1)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

You should be able to create a calculated field called diff with the following value

tostring(strptime(receive_time, "%Y/%m/%d %H:%M:%S") - strptime(start_time, "%Y/%m/%d %H:%M:%S"), "duration")

 

NeharikaVats
Loves-to-Learn

what if i want to get the difference between _indextime & start_time, i am trying with this :

tostring(strftime(_indextime, "%Y/%m/%d %H:%M:%S") - strptime(start_time, "%Y/%m/%d %H:%M:%S"), "duration")

but getting error like- Encountered the following error while trying to save: Operator requires numeric types

My search is:

index=xxx_xxx_firewall sourcetype IN(xxx:xxxxx, xxx:xxxxx)
| eval indextime=strftime(_indextime,"%Y-%m-%d %H:%M:%S")
| eval it = strptime(start_time, "%Y/%m/%d %H:%M:%S")
| eval ot = strptime(receive_time, "%Y/%m/%d %H:%M:%S")
| eval diff = tostring((ot - it), "duration")
| table start_time, receive_time,indextime,_time, diff

 

Can you please help if you have some insights on this.

Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

_indextime is already an epoch time - try this

tostring(_indextime - strptime(start_time, "%Y/%m/%d %H:%M:%S"), "duration")

 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

My two cents - as I always say - leave the time related values as numbers until you need to finally render them to string for presentation. That way it's easier to manipulate them  (sort, offset and so on).

So I'd do just

_indextime - strptime(start_time, "%Y/%m/%d %H:%M:%S")
0 Karma
Get Updates on the Splunk Community!

Splunk Platform | Upgrading your Splunk Deployment to Python 3.9

Splunk initially announced the removal of Python 2 during the release of Splunk Enterprise 8.0.0, aiming to ...

From Product Design to User Insights: Boosting App Developer Identity on Splunkbase

co-authored by Yiyun Zhu & Dan Hosaka Engaging with the Community at .conf24 At .conf24, we revitalized the ...

Detect and Resolve Issues in a Kubernetes Environment

We’ve gone through common problems one can encounter in a Kubernetes environment, their impacts, and the ...