Splunk Search

setting some token based on the result of search query

AKG1_old1
Builder

Hi,

My requirement is to set some token based on the output of search query. my search query return one row and I want to use output of one field as condition.

<search>
    <query>base search | table ID, Host, Log_or_Live </query>
    <done>
        <condition match="$result.Log_or_Live$ == log">
    set some token
          </condition> 
        <condition match="$result.Log_or_Live$ == live">
    set some token
          </condition> 
    <done>
</search>

Thanks

1 Solution

rjthibod
Champion

What you are trying to do should work, but there are some syntax issues you should address.

Try this where you use single quotes instead of the dollar signs around Log_or_Live and you use the html double quote entity &quot; around the matching string values.

 <search>
     <query>base search | table ID, Host, Log_or_Live </query>
     <done>
         <condition match="'result.Log_or_Live' == &quot;log&quot;">
     set some token
           </condition> 
         <condition match="'result.Log_or_Live' == &quot;live&quot;">
     set some token
           </condition> 
     <done>
 </search>

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi
Can you please try this?

<search>
      <query>base search | table ID, Host, Log_or_Live </query>
      <done>
          <condition match="match('result.Log_or_Live',&quot;log&quot;)">
      set some token
            </condition> 
          <condition match="match('result.Log_or_Live',&quot;live&quot;)">
      set some token
            </condition> 
      <done>
  </search>

Thanks

AKG1_old1
Builder

This is working as well. 🙂

rjthibod
Champion

What you are trying to do should work, but there are some syntax issues you should address.

Try this where you use single quotes instead of the dollar signs around Log_or_Live and you use the html double quote entity &quot; around the matching string values.

 <search>
     <query>base search | table ID, Host, Log_or_Live </query>
     <done>
         <condition match="'result.Log_or_Live' == &quot;log&quot;">
     set some token
           </condition> 
         <condition match="'result.Log_or_Live' == &quot;live&quot;">
     set some token
           </condition> 
     <done>
 </search>
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...