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!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...