We have a data source that has a default _time variable indexed correctly on UPDATE_TIME, which we can't change, but we have some searches where we want to filter and count by OPEN_TIME. As a result, I want to set up a timerange picker that will produce an epoch value for the token value, so I can compare OPEN_TIME to the token directly. For example here's what I want to do, which would work if all time token values were returned as epoch values:
index=sm9 source=incident
| eval _time = strptime(OPEN_TIME,"%Y-%m-%d %H:%M:%S")
| where _time>$time.earliest$ AND _time<$time.latest$
This above doesn't work because not all timerange picker values return the epoch time, they could be in the form of epoch value (e.g. 1484063893), string representation (e.g., -7d@h), or 'now'. As a result, and based on other Splunk Answers posts, I tried to catch these options with logical statements (if, case), but those approaches did not work. For example:
index=sm9_us source=incident
| eval _time = strptime(OPEN_TIME,"%Y-%m-%d %H:%M:%S"),
earlytime=tonumber(if(isnum($time.earliest$), "$time.earliest$", relative_time(now(), "$time.earliest$"))),
lasttime = tonumber(case(isnum($time.latest$), "$time.latest$", "$time.latest$"="now", now(), 1=1, relative_time(now(), "$time.latest$")))
| where _time>earlytime AND _time<lasttime
The problem is that the isnum() command will throw a malformed error if the token is a preset string representation (e.g., -7d@h):
Error in 'eval' command: The expression is malformed. Expected ).
However, if you put quotes around the token (isnum("token")) so it runs, then any token as an epoch number (e.g., 1484067160) will always return FALSE since it'll be a string.
Note: I also tried 'addinfo' command to get epoch-based fields (info_min_time, info_max_time), but that only works if you're also filtering the events based on the default indexed _time variable (which I am not; in fact that will return potentially wrong results).
So my question: how can I make a time token always return as an epoch-based variable or convert the token to an epoch?
Thanks
... View more