<?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: Reuse search query, but conditionally in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665985#M228479</link>
    <description>&lt;P&gt;Technically the search msg="*firewall off*" will not match&amp;nbsp;&lt;STRONG&gt;the firewall has been turned off&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;but assuming that's understood, then this may work for you&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc msg="*firewall off*" OR msg="*system updated*"
| streamstats time_window=30s dc(msg) as msgTypes count by hostname 
| where (match(msg, "firewall off") AND count=1) OR (count&amp;gt;1 AND msgTypes=1)
| table _time, hostname, msg&lt;/LI-CODE&gt;&lt;P&gt;It uses streamstats to combine events within a 30 second time window - set that to your expected range.&lt;/P&gt;&lt;P&gt;The where clause filters only those events where it just contains firewall off OR there are multiple firewall off messages, but no system updated message.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Oct 2023 10:35:02 GMT</pubDate>
    <dc:creator>bowesmana</dc:creator>
    <dc:date>2023-10-24T10:35:02Z</dc:date>
    <item>
      <title>Reuse search query, but conditionally</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665982#M228478</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I have a 'complex' (for me at least) question.&amp;nbsp; What I want to achieve is the following:&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=abc msg="*firewall off*" |table _time,hostname,msg&lt;/LI-CODE&gt;
&lt;P&gt;&amp;gt;this will give me, for example:&lt;BR /&gt;hostname = machine1&lt;BR /&gt;msg = "the firewall has been turned off"&lt;BR /&gt;&amp;gt;&amp;gt; I want to be triggered if someone turns off the firewall&lt;/P&gt;
&lt;P&gt;Now, the actual issue I have now is the following:&amp;nbsp; A few seconds before this event, I might get a "system update event" that updates the firewall (agent update), which is OK, and I do NOT want this event.&lt;BR /&gt;I would need to combine both queries into 1 alert.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;2)&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=abc hostname=machine1 NOT msg="*system updated*"&lt;/LI-CODE&gt;
&lt;P&gt;I want to see the result of 1, but only if it was not preceeded by 2.&lt;/P&gt;
&lt;P&gt;I hope this makes sense.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 16:10:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665982#M228478</guid>
      <dc:creator>bitnoise</dc:creator>
      <dc:date>2023-10-24T16:10:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reuse search query, but conditionally</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665985#M228479</link>
      <description>&lt;P&gt;Technically the search msg="*firewall off*" will not match&amp;nbsp;&lt;STRONG&gt;the firewall has been turned off&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;but assuming that's understood, then this may work for you&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=abc msg="*firewall off*" OR msg="*system updated*"
| streamstats time_window=30s dc(msg) as msgTypes count by hostname 
| where (match(msg, "firewall off") AND count=1) OR (count&amp;gt;1 AND msgTypes=1)
| table _time, hostname, msg&lt;/LI-CODE&gt;&lt;P&gt;It uses streamstats to combine events within a 30 second time window - set that to your expected range.&lt;/P&gt;&lt;P&gt;The where clause filters only those events where it just contains firewall off OR there are multiple firewall off messages, but no system updated message.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 10:35:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665985#M228479</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-10-24T10:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: Reuse search query, but conditionally</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665995#M228480</link>
      <description>&lt;P&gt;Cool, never saw that streamstats thingy, I'll test it and let you know &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 12:51:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/665995#M228480</guid>
      <dc:creator>bitnoise</dc:creator>
      <dc:date>2023-10-24T12:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reuse search query, but conditionally</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/666096#M228511</link>
      <description>&lt;P&gt;I was fighting with the query, as it kept on giving me results, but seems I overlooked the fact that the "off" trigger happend twice and the other only once &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Great! Thanks a lot&lt;/P&gt;</description>
      <pubDate>Wed, 25 Oct 2023 07:18:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Reuse-search-query-but-conditionally/m-p/666096#M228511</guid>
      <dc:creator>bitnoise</dc:creator>
      <dc:date>2023-10-25T07:18:43Z</dc:date>
    </item>
  </channel>
</rss>

