Splunk Search

Use field as _time for Timechart and timepicker

Kieffer87
Communicator

I'm trying to chart some phishing logs over time which contain 3 time values:
_time - The time when an analyst processed the phishing request.
email_received - The time the user received the email
time_reported - The time the user reported the email as fishing.

I've put together the following search string to change email_received to _time and chart using timechart. The problem is now timepicker doesn't work as expected because it's still using the original _time from the event and not the email_received value. How can I change _time for both the search and the timechart?

index=phishme sourcetype=phishme:data | eval _time=strptime(email_received,"%b %d %Y %H:%M:%S") | timechart span=1d count as Reports

I've confirmed my eval command is working as expected and email_received is being converted to epoch.

somesoni2
SplunkTrust
SplunkTrust

The time range picker uses _time field that's available in the base search, no the calculated _time afterwards. The workaround is not very optimal as it has to query either all times or sufficiently large time range where you know logs you want to query exist. Try like this

index=phishme sourcetype=phishme:data earliest=0 | eval _time=strptime(email_received,"%b %d %Y %H:%M:%S")
| where _time>=[| gentimes start=-1 | addinfo | table info_min_time | rename info_min_time as search ] AND _time<[| gentimes start=-1 | addinfo | table info_max_time | rename info_max_time as search]
| timechart span=1d count as Reports

Here we're overriding the timerange of base search to "All times" so all data is selected. The subsearches in where clause will still use the time range picker values and thus allowing filter based on new _time values.

Kieffer87
Communicator

I seem to have spoke too soon. This seems to work fine when the latest event is now (last 7 days), but as soon as you use a latest date in the past (March 5-March10), the count for each day changes drastically.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...