<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: if statement in search query in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580775#M202325</link>
    <description>&lt;P&gt;The short answer is no - SPL is not a procedural language&lt;/P&gt;&lt;P&gt;The perhaps more helpful answer is, it depends on what you are trying to achieve. The thing to remember is that SPL processes a pipeline of events, each command in the pipeline processes the events and passes the results onto the next command in the pipeline.&lt;/P&gt;&lt;P&gt;Using rex to match against the values in the field can help you do conditional processing e.g. if the field contains "command sent", as in your second example, you could extract the endpoint (you may have to adjust this depending on what your events actually look like)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=msg "Security Agent uninstallation command sent.*,\s+\w+:\s+(?P&amp;lt;endpoint&amp;gt;.+)"&lt;/LI-CODE&gt;&lt;P&gt;Events which don't have a msg field which matches the anchor string will not have the endpoint field added to them, but all the events are passed on to the next command in the pipeline.&lt;/P&gt;&lt;P&gt;Hopefully, that makes sense?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jan 2022 13:19:41 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2022-01-12T13:19:41Z</dc:date>
    <item>
      <title>if statement in search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580769#M202321</link>
      <description>&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;i would like to ask if it is possible to include IF condition in the search query&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if msg="Security Agent uninstallation*"&lt;/P&gt;&lt;P&gt;[perform the below]&lt;/P&gt;&lt;P&gt;| rex field=msg ":\s+\(*(?&amp;lt;result&amp;gt;[^)]+)"&lt;/P&gt;&lt;P&gt;| table _time msg result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if msg="Security Agent uninstallation command sent*"&lt;/P&gt;&lt;P&gt;[perform the below]&lt;/P&gt;&lt;P&gt;| rex field=msg "^[^;\n]*;\s+\w+:\s+(?P&amp;lt;endpoint&amp;gt;.+)"&lt;/P&gt;&lt;P&gt;| table _time msg suser endpoint&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 12:40:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580769#M202321</guid>
      <dc:creator>7ryota</dc:creator>
      <dc:date>2022-01-12T12:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: if statement in search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580773#M202323</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;you cannot use if for perform any flow in SPL. But you can use several rex statements one after another and pick those values based on content of msg. Then just use those values later on or you could use if/case with eval to pick those values to anther filed if those exists e.g. eval foo=if (isnotnull(endpoint), endpoint,"N/A")&lt;/P&gt;&lt;P&gt;r. Ismo&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 13:11:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580773#M202323</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2022-01-12T13:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: if statement in search query</title>
      <link>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580775#M202325</link>
      <description>&lt;P&gt;The short answer is no - SPL is not a procedural language&lt;/P&gt;&lt;P&gt;The perhaps more helpful answer is, it depends on what you are trying to achieve. The thing to remember is that SPL processes a pipeline of events, each command in the pipeline processes the events and passes the results onto the next command in the pipeline.&lt;/P&gt;&lt;P&gt;Using rex to match against the values in the field can help you do conditional processing e.g. if the field contains "command sent", as in your second example, you could extract the endpoint (you may have to adjust this depending on what your events actually look like)&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rex field=msg "Security Agent uninstallation command sent.*,\s+\w+:\s+(?P&amp;lt;endpoint&amp;gt;.+)"&lt;/LI-CODE&gt;&lt;P&gt;Events which don't have a msg field which matches the anchor string will not have the endpoint field added to them, but all the events are passed on to the next command in the pipeline.&lt;/P&gt;&lt;P&gt;Hopefully, that makes sense?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 13:19:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/if-statement-in-search-query/m-p/580775#M202325</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2022-01-12T13:19:41Z</dc:date>
    </item>
  </channel>
</rss>

