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
Revered Legend

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
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!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...