Splunk Search

Set Custom time as _time

kpavan
Path Finder

Hi All,

I have requirement like we have custom time field ALERTDATETIME i want to display graph where my custom time field should be primary time field. This could have been easy if they asked just display ALERTDATETIME stats but they want time filter in graph where if they select last 7days or expanding to 30 days the data should be displayed based on ALERTDATETIME not the _time field. So am stuck here how to set custom time field as _time when user filtering date.

The date format of ALERTDATETIME is "%Y-%m-%d %H:%M:%S", need to convert only %Y-%m-%d. I tried something like below query but didn't work.

base search
| eval _time=strptime(ALERTDATETIME,"%Y-%m-%d")
| stats count by _time

Thanks!
Pavan

0 Karma

cmerriman
Super Champion

try using this:

base search
| addinfo 
| eval _time=strptime(ALERTDATETIME,"%Y-%m-%d") 
| where _time>=info_min_time AND (info_max_time="+Infinity" OR _time<=info_max_time)
| stats count by _time

that should allow for use of the time picker.

0 Karma

micahkemp
Champion

When the user searches for, say, 7 days, do they expect that search to return results where ALERTDATETIME is within that 7 day window, or do they only want the resulting output to make use of ALERTDATETIME?

0 Karma

kpavan
Path Finder

Hi Micahkemp

Thanks for reply!

They want to When the user searches for, say, 7 days, do they expect that search to return results where ALERTDATETIME is within that 7 day window

Thanks!

0 Karma

micahkemp
Champion

In that case you need to ensure the timepicker range selected encompasses the full time range of the actual _time field that may have events with ALERTDATETIME in the desired range. That may mean users can't select 7 days from the timepicker if they want 7 days based on ALERTDATETIME.

The timepicker will only define your time window based on _time.

0 Karma

p_gurav
Champion

Hi kpavan,

Please try following link:
link text

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Fuel Your Journey: What’s Waiting for You at the .conf26 Acceleration Station

Navigating the show floor at .conf26 isn't just about keynotes and technical breakout sessions; it's also ...

Join the Final Session of the Data Management & Federation Bootcamp Series

Over the past three sessions of the Data Management & Federation Bootcamp Series, we've explored how to build ...

From Data to Insight: Announcing the Winners of the Splunk Dashboard Contest

Hi Splunkers, First off, thank you to everyone who participated in our very first From Data to Insight: The ...