Splunk Search

Using a different value for _time

williamsmew
New Member

index=av sourcetype=BobsCutRateAV category="BadStuffHappening"
| eval date_hour=strftime(_time, "%H")
| eval date_wday = strftime(_time, "%w")
| search (date_hour>18 OR date_hour<6) OR (date_wday=0 OR date_wday=6)
| timechart count

This works. The problem is that _time reflects when the event is reported not when it was detected. The field I need is detected_timestamp which is formatted as detected_timestamp="2019-04-11 02:31:52.0"

I did not create this but have been tasked with modifying it. I have looked at documentation and the many things I have tried do not work. Your help is appreciated.

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Assuming you always want to use detected_timetamp and never what is now _time, I'd recommend changing the timestamp extraction for that sourcetype. See https://docs.splunk.com/Documentation/Splunk/7.2.6/Data/Configuretimestamprecognition for how, and open new questions with any issues you might have.

If you want to do this in some search without changing the data getting indexed because most of the time what is now _time is the right time and only this time you want detected_timestamp, you can do something like this:

... | eval _time = strptime(detected_timestamp, "%F %T.%N") | eval date_hour = ...

XOR

... | eval date_hour ... | eval date_wday = ... | search ... | eval _time = strptime(detected_timestamp, "%F %T.%N") | timechart count

depending on whether the date_hour/date_wday filters you have right now should be applied to _time or detected_timestamp.

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Assuming you always want to use detected_timetamp and never what is now _time, I'd recommend changing the timestamp extraction for that sourcetype. See https://docs.splunk.com/Documentation/Splunk/7.2.6/Data/Configuretimestamprecognition for how, and open new questions with any issues you might have.

If you want to do this in some search without changing the data getting indexed because most of the time what is now _time is the right time and only this time you want detected_timestamp, you can do something like this:

... | eval _time = strptime(detected_timestamp, "%F %T.%N") | eval date_hour = ...

XOR

... | eval date_hour ... | eval date_wday = ... | search ... | eval _time = strptime(detected_timestamp, "%F %T.%N") | timechart count

depending on whether the date_hour/date_wday filters you have right now should be applied to _time or detected_timestamp.

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Does this work in an empty search bar?

| makeresults | eval detected_timestamp="2019-04-11 02:31:52.5" | eval _time = strptime(detected_timestamp, "%Y-%m-%d %H:%M:%S.%N")
0 Karma

williamsmew
New Member

Yes it does

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

%F is short for %Y-%m-%d, %T is short for %H:%M:%S - see http://www.strftime.net/ for an easy to use reference.

0 Karma

williamsmew
New Member

Yup, finally found that under Date and time variables. What perplexes me is why eval _time = strptime(detected_timestamp, "%Y-%m-%d %H:%M:%S.%N") does not work since it seems to be the the same as the F T N

0 Karma

williamsmew
New Member

Thanks for the response

Im confused where the "%F %T.%N" is from and how %H and %w is extracted, from what I can find I was using "%Y-%m-%d %H:%M:%S.%1n"

I dont have much in the way of resources to pull from here, these forums will be about it, so thank you.

0 Karma

williamsmew
New Member

And yes this is for a search being piped into a dashboard

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...