<?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: How to create an hourly alert when never seen before with certain unique characteristics appear in an index? in Alerting</title>
    <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144575#M2337</link>
    <description>&lt;P&gt;Here's a suggestion trying to get to the same result though via a different approach and one that would not require to effectively make an all time search every hour.&lt;/P&gt;

&lt;P&gt;To remember already discovered combinations of field1, field2, field2 long term and even exceeding your normal data retention period you could use either a summary index or a lookup table.&lt;BR /&gt;
In general I find working with lookup tables easier so here's an suggestion facilitating one: &lt;/P&gt;

&lt;P&gt;In CSV format the table, I named &lt;EM&gt;discovered_combinations&lt;/EM&gt;, could look like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;discovered_timestamp,field1,field2,field3
1423922204,AAA,"",123
1423923303,"",bbb,435
1423924444,"RRR,bbb,""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The timestamp would provide a return value but might also be used in queries and generally help keep track of when field combinations were discovered. &lt;BR /&gt;
A search scheduled every hour would find events that don't match a field combination in the lookup table, dedup and send the alert so you get the first event for any new combination.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=mydata earliest=-1h@h latest=@h
| dedup field1, field2, field3
| lookup discovered_combinations field1 field2 field2 OUTPUT discovered_timestamp
| where isNull(discovered_timestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A second search scheduled afterwards would then update the lookup table using &lt;CODE&gt;... | outputlookup discovered_combinations append=true&lt;/CODE&gt;.&lt;BR /&gt;
There might be a way of doing this all in a single query which would be neater. &lt;/P&gt;</description>
    <pubDate>Sat, 14 Feb 2015 15:03:23 GMT</pubDate>
    <dc:creator>tpflicke</dc:creator>
    <dc:date>2015-02-14T15:03:23Z</dc:date>
    <item>
      <title>How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144574#M2336</link>
      <description>&lt;P&gt;I need to build an hourly alert when never seen before events (with certain unique characteristics) appear in index.&lt;BR /&gt;
In essence - this is the logic:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Get list of fresh events (with 3 fields of interest: field1,2,3): &lt;CODE&gt;index=mydata earliest=-1h@h | dedup field1, field2, field3&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;For each found event, run this pseudo search: &lt;CODE&gt;index=mydata latest=-1h@h field1 (field2 OR field3) | stats count&lt;/CODE&gt;&lt;/LI&gt;
&lt;LI&gt;Alert if count=0 - in other words - alert if there were no previously seen events with field1 AND (field2 OR field3) found at step #1.&lt;/LI&gt;
&lt;LI&gt;Return original event that generated the alert.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Suggestions are welcome.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Feb 2015 23:22:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144574#M2336</guid>
      <dc:creator>gesman</dc:creator>
      <dc:date>2015-02-13T23:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144575#M2337</link>
      <description>&lt;P&gt;Here's a suggestion trying to get to the same result though via a different approach and one that would not require to effectively make an all time search every hour.&lt;/P&gt;

&lt;P&gt;To remember already discovered combinations of field1, field2, field2 long term and even exceeding your normal data retention period you could use either a summary index or a lookup table.&lt;BR /&gt;
In general I find working with lookup tables easier so here's an suggestion facilitating one: &lt;/P&gt;

&lt;P&gt;In CSV format the table, I named &lt;EM&gt;discovered_combinations&lt;/EM&gt;, could look like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;discovered_timestamp,field1,field2,field3
1423922204,AAA,"",123
1423923303,"",bbb,435
1423924444,"RRR,bbb,""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The timestamp would provide a return value but might also be used in queries and generally help keep track of when field combinations were discovered. &lt;BR /&gt;
A search scheduled every hour would find events that don't match a field combination in the lookup table, dedup and send the alert so you get the first event for any new combination.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=mydata earliest=-1h@h latest=@h
| dedup field1, field2, field3
| lookup discovered_combinations field1 field2 field2 OUTPUT discovered_timestamp
| where isNull(discovered_timestamp)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A second search scheduled afterwards would then update the lookup table using &lt;CODE&gt;... | outputlookup discovered_combinations append=true&lt;/CODE&gt;.&lt;BR /&gt;
There might be a way of doing this all in a single query which would be neater. &lt;/P&gt;</description>
      <pubDate>Sat, 14 Feb 2015 15:03:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144575#M2337</guid>
      <dc:creator>tpflicke</dc:creator>
      <dc:date>2015-02-14T15:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144576#M2338</link>
      <description>&lt;P&gt;Thank you  for your writeup and suggestions.&lt;BR /&gt;
The problem is that in my case lookup table could potentially hold about million of entries and will exceed it's recommended limits as an approach.&lt;BR /&gt;
In my example &lt;CODE&gt;mydata&lt;/CODE&gt; is a summary index already.&lt;/P&gt;

&lt;P&gt;The challenge is to implement "intelligent negative lookbehind" with Splunk.&lt;BR /&gt;
Where &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;intelligent = more complex matching logic than just single AND or OR on all fields.&lt;/LI&gt;
&lt;LI&gt;negative = discovering the fact on non-existence of events matching intelligent query&lt;/LI&gt;
&lt;LI&gt;lookbehind = searching within past data.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Sat, 14 Feb 2015 16:35:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144576#M2338</guid>
      <dc:creator>gesman</dc:creator>
      <dc:date>2015-02-14T16:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144577#M2339</link>
      <description>&lt;P&gt;Following up on @tpflicke's answer, lookups are a good way to go about this.  Really what you need to know are two foundational things.&lt;/P&gt;

&lt;P&gt;[1]  The minimum value of &lt;CODE&gt;_time&lt;/CODE&gt; for events matching a specific set of unique fields.&lt;BR /&gt;
[2]  Is the minimum &lt;CODE&gt;_time&lt;/CODE&gt; for a specific set of unique fields "recent" ?&lt;/P&gt;

&lt;P&gt;So, let's approach something like this.  Start by searching over all time:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=mysourcetype
| stats min(_time) as _time by field1, field2, field3
| outputlookup mysourcetypetracker.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now we should have a simple lookup table with the earliest value of &lt;CODE&gt;_time&lt;/CODE&gt; for combinations of those three fields.  We can incrementally update this with a saved search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=foo sourcetype=mysourcetype
| stats min(_time) as _time by field1, field2, field3
| inputlookup append=true mysourcetypetracker.csv
| stats min(_time) as _time by field1, field2, field3
| outputlookup mysourcetypetracker.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can run this saved search every hour, every 15 minutes - whatever works for you.  Calling &lt;CODE&gt;stats&lt;/CODE&gt; twice here gives us the earliest &lt;CODE&gt;_time&lt;/CODE&gt; for the "current window" as well as the "overall" lowest &lt;CODE&gt;time&lt;/CODE&gt; for all time.  We output this back into our tracker lookup file, which now always has the state of the earliest time seen for combinations of field1, field2, field3.&lt;/P&gt;

&lt;P&gt;Now, it becomes pretty easy to look for "new arrivals".  We can run a search like&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup mysourcetypetracker.csv
| where _time &amp;gt;= (now() - 3600)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;To find any combinations newly appearing in the past hour.  You can probably with a subsearch or two figure out how to use this to come up with the raw events for newly appearing combinations.  I will have to experiment with that a little..&lt;/P&gt;</description>
      <pubDate>Sat, 14 Feb 2015 18:38:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144577#M2339</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2015-02-14T18:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144578#M2340</link>
      <description>&lt;P&gt;Thank you for your comments.&lt;BR /&gt;
The condition #2 in my question states that uniqueness is determined by query &lt;CODE&gt;field1 AND (field2 OR field3)&lt;/CODE&gt;, not by &lt;CODE&gt;field1 AND field2 AND field3&lt;/CODE&gt;. That's important difference that makes task more complicated that just using simple lookup. &lt;BR /&gt;
If lookups would allow for more complex matching logic, that would be great, but i think more work is required to tweak your suggestions.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Feb 2015 20:21:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144578#M2340</guid>
      <dc:creator>gesman</dc:creator>
      <dc:date>2015-02-14T20:21:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144579#M2341</link>
      <description>&lt;P&gt;I missed that detail, so my apologies.  It probably does add a good bit of complexity - I will think about it and maybe come back with an answer.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Feb 2015 23:41:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144579#M2341</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2015-02-14T23:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an hourly alert when never seen before with certain unique characteristics appear in an index?</title>
      <link>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144580#M2342</link>
      <description>&lt;P&gt;I found the solution to the task. &lt;/P&gt;

&lt;P&gt;First, to simplify the task definition: Be able to execute very custom query per each found event and collect the results.&lt;/P&gt;

&lt;P&gt;Lookups allows you to find matches within lookup source based on &lt;CODE&gt;field1 AND field2 AND field3&lt;/CODE&gt; logic.&lt;BR /&gt;
Subsearches allows you to pull subsearch results and then run the outer query either in &lt;CODE&gt;field1 AND field2 AND field3&lt;/CODE&gt; or &lt;CODE&gt;field1 OR field2 OR field3&lt;/CODE&gt; manner. You may control "outer" behavior of subsearch results with &lt;CODE&gt;... | format ...&lt;/CODE&gt; parameter somewhat, but not to the extend of having custom-crafted outer query based on the returned results.&lt;/P&gt;

&lt;P&gt;So the solution to the task is based on the ability to craft &lt;EM&gt;very custom&lt;/EM&gt; search as a string and then return it to the outer search as a single &lt;CODE&gt;search&lt;/CODE&gt; field.&lt;BR /&gt;
Outer search will take it &lt;EM&gt;as is&lt;/EM&gt; and execute it.&lt;/P&gt;

&lt;P&gt;The trick was to prevent Splunk from post-tweaking the search and getting confused by some elements of it.&lt;BR /&gt;
For example Splunk would not allow search string to contain &lt;CODE&gt;...earliest=... latest=...&lt;/CODE&gt; elements. Splunk would get confused if returned search string contained aliases.&lt;BR /&gt;
The solution to both was to code them within macros and then include macro within &lt;CODE&gt;search=&lt;/CODE&gt; string to be returned to the outer search.&lt;/P&gt;

&lt;P&gt;This is the blueprint of the solution. &lt;BR /&gt;
Notes: &lt;CODE&gt;index=NONEXISTENT&lt;/CODE&gt; - again is a trick to prevent Splunk from getting confused. Without it would try to search for &lt;EM&gt;everything&lt;/EM&gt; before main subsearch. &lt;CODE&gt;index=NONEXISTENT&lt;/CODE&gt; will solve it by causing Splunk to quickly return zero results and focus on subsearch business.&lt;/P&gt;

&lt;P&gt;Below you'll notice that per each pre-found event the mind-boggling custom search query is crafted that contains double-nested subsearches by itself. While looking a bit scary - what it does is created an empty event first with &lt;CODE&gt;previous_match_found=0&lt;/CODE&gt;. Then it will run custom search and if any results found (grabs only the first one to save time) - the &lt;CODE&gt;previous_match_found&lt;/CODE&gt; value becomes 1.&lt;/P&gt;

&lt;P&gt;Once the whole monster executes - it's easy to only filter on &lt;CODE&gt;... | where previous_match_found=0 ...&lt;/CODE&gt; to accomplish the final task - finding unique events that never occured  before.&lt;/P&gt;

&lt;P&gt;`index=NONEXISTENT&lt;BR /&gt;
[search ...searching for special events... | fields field1, field2, field3&lt;/P&gt;

&lt;P&gt;| eval COMMENT="Here we got events. Now per each event - craft custom search query:"&lt;/P&gt;

&lt;P&gt;| eval search_this="&lt;BR /&gt;
  | append [|stats count AS previous_match_found | eval _time=\"" + _time + "\" | eval field1 =\"" + field1 + "\" | appendcols override=1 [search index=myindex ... field1=\"" + field1 + "\" (field2=\"" + field2 + "\" OR field3=\"" + field3 + "\" ) | head 1 | eventstats count AS previous_match_found] ]&lt;BR /&gt;
  "&lt;/P&gt;

&lt;P&gt;| eval COMMENT="Glue all queries together into the single one:"&lt;/P&gt;

&lt;P&gt;| stats values(search_this) AS all_searches&lt;BR /&gt;
| eval search=mvjoin(all_searches, " ")&lt;/P&gt;

&lt;P&gt;| eval COMMENT="Finally, return main combined search query back to the outer search :"&lt;/P&gt;

&lt;P&gt;| fields search&lt;BR /&gt;
]&lt;BR /&gt;
| where previous_match_found=0&lt;BR /&gt;
...&lt;BR /&gt;
`&lt;BR /&gt;
On a final note - this search apparently runs pretty fast considering the volume of data.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Alerting/How-to-create-an-hourly-alert-when-never-seen-before-with/m-p/144580#M2342</guid>
      <dc:creator>gesman</dc:creator>
      <dc:date>2020-09-28T19:00:06Z</dc:date>
    </item>
  </channel>
</rss>

