问题描述
我有一个 splunk 仪表板,它根据带有开始和结束时间范围的时间选择器返回结果 我希望在仪表板中包含该时间范围,以便生成的 PDF 显示时间范围。
解决方法
您可以添加带有 <panel>
的 <html>
以显示 $date.earliest$
和 $date.latest$
值:
<row>
<panel>
<html>
<h1>Date Range : $date.earliest$ - $date.latest$ </h1>
</html>
</panel>
</row>
您可能希望格式化这些值以反映实际的日期时间值。您可以使用格式化的日期时间值评估字段:
<input type="time" token="date" searchWhenChanged="true">
<label>date</label>
<default>
<earliest>-40m@m</earliest>
<latest>now</latest>
</default>
<change>
<eval token="timelabel_earliest">if(isnum($date.earliest$),strftime($date.earliest$,"%m/%d/%Y %H:%M"),strftime(relative_time(now(),$date.earliest$),"%m/%d/%Y %H:%M") )</eval>
<eval token="timelabel_latest">if(isnum($date.latest$),strftime($date.latest$,$date.latest$),"%m/%d/%Y %H:%M") )</eval>
</change>
</input>
然后使用带有格式化值的字段:
<row>
<panel>
<html>
<h1>$AppEnv$ : $timelabel_earliest$ - $timelabel_latest$ </h1>
</html>
</panel>
</row>
下面是一个完整的仪表板示例,演示了如何同时显示时间选择器值和格式:
<form>
<label>Display Time Picker</label>
<fieldset submitButton="false">
<input type="time" token="field1">
<label></label>
<default>
<earliest>-24h@h</earliest>
<latest>now</latest>
</default>
<change>
<eval token="timelabel_earliest">if(isnum($field1.earliest$),strftime($field1.earliest$,$field1.earliest$),"%m/%d/%Y %H:%M") )</eval>
<eval token="timelabel_latest">if(isnum($field1.latest$),strftime($field1.latest$,$field1.latest$),"%m/%d/%Y %H:%M") )</eval>
</change>
</input>
</fieldset>
<row>
<panel>
<html>
<h1>Date Range: $field1.earliest$ - $field1.latest$ </h1>
<h1>Date Range formatted: $timelabel_earliest$ - $timelabel_latest$ </h1>
</html>
</panel>
</row>
</form>