Splunk Enterprise

How to filter interval in log?

quangtran
Explorer

I have a search like this:

sourcetype = Grandstream  | stats count by _time phone starttime answer endtime

result:

_time phone starttime answer endtime count

2022-08-09 14:30:42 xxx39xxxx 2022-08-04 14:33:58 2022-08-04 14:34:02 2022-08-04 14:34:02 1
2022-08-09 14:30:42 xxx394xxxx 2022-08-04 14:34:02 2022-08-04 14:34:02 2022-08-04 14:34:02 1
2022-08-09 14:30:42 xxx1394xxx 2022-08-04 14:34:03 2022-08-04 14:34:03 2022-08-04 14:34:09 1
2022-08-09 14:30:42 xxx1382xx 2022-08-09 14:28:52 2022-08-09 14:28:52 2022-08-09 14:29:25 1

But _time and starttime don't match because the log time is pushed wrong

is there a way to filter the starttime field by its time in a week from 0h Friday to 24h Thursday?

thanks 

0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
| where starttime_epoch >= relative_time(now(), "@w-2d") AND starttime_epoch < relative_time(now(),"@w+5d")

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Regardless of an immediate walkaround (parsing with strptime and filtering on that) I'd do two things:

1) Fix timestamp parsing since apparently it doesn't reflect the "real" timestamp from the event

2) Think which of the timestamps is the one that you need as your _time field (you have at least three different timestamps in your events as we can see) and consider parsing the others into indexed fields - In general indexed fields should not be used very often but in this case it might be worthwhile since datetime parsing is a relatively heavy operation and parsing it once on ingest and storing the parsed indexed values in indexed fields could give you a significant performance boost if you're using those fields often.

0 Karma

quangtran
Explorer

thank you for the very detailed answer, but can't fix the real time problem at the moment

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You should parse the starttime so that it is an epoch time, then you can do comparisons / filtering on it

| eval starttime_epoch=strptime(starttime,"%Y-%m-%d %H:%M:%S")

Which Friday /Thursday do you want to filter by?

0 Karma

quangtran
Explorer

hello, I want to filter the period from last Friday to Thursday this week, thanks you

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| where starttime_epoch >= relative_time(now(), "@w-2d") AND starttime_epoch < relative_time(now(),"@w+5d")
0 Karma

quangtran
Explorer

thanks you very much

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...