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

时间:2020-06-02 15:19:24

标签: splunk splunk-query

我使用报告查询重新创建了仪表板,并让搜索返回了所有表结果。我有一个参考数字输入作为文本框。令牌名称为: purchCostReferenceToken

我想基于此令牌限制表结果。这是查询:

<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-参数无效

我想在几个表列中添加过滤器。 purchCostReference值是使用 xmlkv

在查询中提取的字段

1 个答案:

答案 0 :(得分:1)

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

如果标记引用的字段是自动提取的,那么通常最好将标记放入基本搜索中。这里不是这种情况。

您应该使用searchwhere命令根据令牌值过滤事件。像xmlkv | search purchCostReference=$purchCostReferenceToken$之类的东西。