Dashboards & Visualizations

Dashboard TimePicker using always the UTC

damucka
Builder

Hello,

I need the dashboard time picker to use always the UTC time independent on the user TZ. 

How would I do this?

Could someone paste the corresponding code?

I was trying to copy paste some code that I found in the google, see below, but I am failing on the translation of the SPL into the dashboard XML commands. Like e.g. the below would not execute the regex properly - I mean I would not know how to do this. Then the UTCtime does not get set and the following commands are not working.

Any ideas?

Kind Regards,

Kamil

 

 

    <input type="time" token="date_time" searchWhenChanged="true">
      <label>Time</label>
      <default>
        <earliest>-24h@h</earliest>
        <latest>now</latest>
      </default>
      <change>
        <eval token="MYtime">strftime(now(), "%m/%d/%Y %H:%M:%S %Z")</eval>
        <eval token="UTCtime">MYtime</eval>
        <eval token="UTCtime">rex field=UTCtime mode=sed "s/\s+\S+$/ UTC/"</eval>
        <eval token="UTC_time">strptime(UTCtime, "%m/%d/%Y %H:%M:%S %Z")</eval>
        <eval token="TZdelta">round(_time - UTC_time, 0)</eval>
        <eval token="earliestUTC">'earliest' + $TZdelta$</eval>
        <eval token="latestUTC">'latest' + $TZdelta$</eval>
        <eval token="form.from">strftime(relative_time(now(),'earliest'), "%F %T")</eval>
        <eval token="form.to">strftime(relative_time(now(),'latest'), "%F %T")</eval>
        <eval token="stop_ts_from">relative_time(now(),'earliest')*1000</eval>
        <eval token="stop_ts_to">relative_time(now(),'latest')*1000</eval>
        <eval token="curr_date_from">strftime($stop_ts_from$/1000,"%Y%m%d")</eval>
        <eval token="curr_date_to">strftime($stop_ts_to$/1000,"%Y%m%d")</eval>
        <eval token="timediff">strptime($form.to$, "%Y-%m-%d %H:%M:%S")  - strptime($form.from$, "%Y-%m-%d %H:%M:%S")</eval>
        <eval token="secbetween">$timediff$/1800</eval>
        <eval token="timegran">case($secbetween$ &lt; 60, 1,$secbetween$ &lt; 300,5, $secbetween$ &lt; 600,10,$secbetween$&lt;1800,30,$secbetween$&lt;3600,60,$secbetween$&lt;7200,120,$secbetween$&lt;10800,180,$secbetween$&lt;21600,360$secbetween$&lt;43200,720,$secbetween$&lt;86400,1440,$secbetween$&gt;86400,1440)</eval>

 

 

 

Labels (1)
Tags (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

It looks like you are missing some $s around token names - I don't know if the following will work, but you could try using replace instead of rex?

        <eval token="UTCtime">$MYtime$</eval>
        <eval token="UTCtime">replace($UTCtime$,"\s+\S+$"," UTC")</eval>
        <eval token="UTC_time">strptime($UTCtime$, "%m/%d/%Y %H:%M:%S %Z")</eval>
        <eval token="TZdelta">round(now() - $UTC_time$, 0)</eval>
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!

A Four-Part Event Series: Full Stack Observability For the AI Era

As AI reshapes applications, infrastructure, and the way teams operate, the traditional boundaries of ...

SOC4Kafka - New Kafka Connector Powered by OpenTelemetry

The new SOC4Kafka connector, built on OpenTelemetry, enables the collection of Kafka messages and forwards ...

Event Series: Level up your SOC: Advancing with Splunk Enterprise Security

AI has fundamentally raised the stakes for security operations, and this three-part series is your guide to ...