Splunk Search

How to use a dashboard time range picker to reference a time column in a CSV file generated by an inputcsv search?

ishaanshekhar
Communicator

I have a csv file that I have not indexed and am using it directly through the inputcsv command. The problem is that since it is not indexed, it does not have a _time value by default. I want the dashboard to have a time range picker that would reference a column in the csv file as the _time.

I tried this search below, but that says no results found.

| inputcsv file.csv | eval _time=strptime(Ticket_Reported_Date,"%Y/%m/%d %H:%M:%S") | search earliest=$time_tok.earliest$ latest=$time_tok.latest$ | timechart span=1mon count

Please help!!! Thanks in advance!

1 Solution

martin_mueller
SplunkTrust
SplunkTrust

Replace your search with this:

... | where _time >="$time_tok.earliest$" AND _time < if("$time_tok.latest$"=="now", now(), "$time_tok.latest$") | ...

Make sure all the special cases such as all time are handled properly, add similar if() expressions if they aren't.

View solution in original post

cspires64
Path Finder

This also works . . .
|inputlookup Example.csv | addinfo |eval et=round(info_min_time, 0) | eval lt=if(info_max_time='+Infinity', 'now', round(info_max_time, 0)) | convert timeformat="%Y/%m/%d %H:%M:%S" ctime(et), ctime(lt)| where DateField>=et AND DateField

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Replace your search with this:

... | where _time >="$time_tok.earliest$" AND _time < if("$time_tok.latest$"=="now", now(), "$time_tok.latest$") | ...

Make sure all the special cases such as all time are handled properly, add similar if() expressions if they aren't.

ishaanshekhar
Communicator

Thank you Martin! The search did indeed work... and as you said, would require all the special cases of time format. Is there a list that I could refer to include in my conditions... I guess relative dates could be anything so it may be difficult to maintain huge list of conditions.

Is it possible to use the time range picker as is, and directly use the token value without multiple conditions check?

If it is not possible, then I would try changing the time range view to include only fixed date range option and disable the rest.

Thank you!

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

I'd approach this with a small case() - one branch deals with "now", another with numbers for epoch timestamps, and another uses relative_time(now(), ) to deal with "-5m" and the like.

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