如何在Splunk中的仪表盘查询中添加令牌?

问题描述 投票:0回答:1

我使用报表查询重新创建了仪表板,并让搜索返回所有的表结果。 我有一个输入参考号的文本框。 令牌名称是 采购成本参考标记

我想根据这个标记来限制表的结果。这就是查询。

<form>
  <label>Thru Train Dashboard</label>
  <fieldset submitButton="false" autoRun="true">
    <input type="text" token="purchCostReferenceToken" searchWhenChanged="true">
      <label>Enter a TMS Reference Number to Filter Table</label>
      <default>*</default>
      <initialValue>*</initialValue>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>Thru Train Data</title>
      <table>
        <search>
          <query>index=... "&lt;billingMethod&gt;RULE&lt;/billingMethod&gt;" "createMessage MsgSource" | xmlkv | rex max_match=0 "\&lt;purchasedCostTripSegment\&gt;(?P&lt;segment&gt;[^\&lt;]+)" |eval Segments =  mvrange(1,mvcount(mvindex(segment, 0, 2))+1,1) | rex max_match=0 "\&lt;carrier\&gt;(?P&lt;Carriers&gt;[^\&lt;]+)" | rex max_match=0 "\&lt;billingMethod\&gt;(?P&lt;BillingMethod&gt;[^\&lt;]+)" | rex max_match=0 "&lt;purchasedCostTripSegment&gt;[\s\S]*?&lt;origin&gt;\s*&lt;ns2:numberCode&gt;(?P&lt;Origin&gt;\d+)"  | rex max_match=0 "&lt;purchasedCostTripSegment&gt;[\s\S]*?&lt;destination&gt;\s*&lt;ns2:numberCode&gt;(?P&lt;Destination&gt;\d+)" | rex max_match=0 "&lt;purchasedCostTripSegment&gt;[\s\S]*?&lt;stopOff&gt;\s*&lt;ns2:stopOffLocation&gt;\s*&lt;ns2:numberCode&gt;(?P&lt;StopOffLocation&gt;\d+)" | eval Time =_time | convert timeformat="%m-%d-%Y %H:%M:%S" ctime(Time) | table purchCostReference, eventType, Time, Segments, Carriers, BillingMethod, Origin, Destination, StopOffLocation | sort Time</query>
          <earliest>-30d@d</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
      </table>
    </panel>
  </row>
</form>

我在哪里添加标记来限制搜索? 我试着在查询结束后,在表命令之前添加这个标记。

...   | eval Time =_time | convert timeformat="%m-%d-%Y %H:%M:%S" ctime(Time) purchCostReference=$purchCostReferenceToken$ | table purchCostReference, eventType, Time, Segments, Carriers, BillingMethod, Origin, Destination, StopOffLocation | sort Time

我得到一个错误...在转换命令中出错:参数purchCostReference-无效。

我想在表中的几个列中添加过滤器。 采购成本参考值是在查询中提取的字段,使用 xmlkv

splunk splunk-query
1个回答
0
投票

从技术上讲,令牌可以放在查询中的任何地方,但当令牌被替换为其值时,查询必须是有效的。 convert timeformat="%m-%d-%Y %H:%M:%S" ctime(Time) purchCostReference=4 是无效的SPL。

如果token引用的字段是自动提取的,那么通常最好把token放在基础搜索中。 但这里的情况并非如此。

您应该使用 searchwhere 命令,根据标记值过滤事件。 类似于 xmlkv | search purchCostReference=$purchCostReferenceToken$.

© www.soinside.com 2019 - 2024. All rights reserved.