<?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 How to save the results of a function and reuse them in a search and have a clause based on count of  &amp;gt;1 in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106514#M27691</link>
    <description>&lt;P&gt;New to splunk but getting somewhere with learning to construct complex searches. The goal of the search below is to look for instances where multiple login credential failures via a central web-based authentication mechanism are associated with one non-U.S. IP address (client) and that these multiple failures involve more than one user-id (field is called webauth_ucinetid). The approach I took was to use the dc() function to get a count of unique user-ids, and the list() function to put them together as multivalues associated with their given, common, IP address. Here is the search:&lt;/P&gt;

&lt;P&gt;index="syslogs_webauth" webauth_action="login" webauth_success="N" &lt;CODE&gt;geoip&lt;/CODE&gt; | search client_country_code!="US" | stats dc(webauth_ucinetid) List(webauth_ucinetid) AS "UCInetID" count by webauth_ip client_country_code| rename client_country_code AS "CC" | sort -dc(webauth_ucinetid) | head 20&lt;/P&gt;

&lt;P&gt;An example of what the search returns is shown here:&lt;/P&gt;

&lt;TABLE border="1"&gt;
  &lt;TBODY&gt;
    &lt;!-- Results table headers --&gt;
    &lt;TR&gt;
      &lt;TH&gt;webauth_ip&lt;/TH&gt;
      &lt;TH&gt;CC&lt;/TH&gt;
      &lt;TH&gt;dc(webauth_ucinetid)&lt;/TH&gt;
      &lt;TH&gt;UCInetID&lt;/TH&gt;
      &lt;TH&gt;Count&lt;/TH&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;114.143.187.210&lt;/TD&gt;
      &lt;TD&gt;CN&lt;/TD&gt;
      &lt;TD&gt;3&lt;/TD&gt;
      &lt;TD&gt;kbaeki&lt;BR /&gt;cseunggyk&lt;BR /&gt;rhsung&lt;/TD&gt;
      &lt;TD&gt;3&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;120.87.95.70&lt;/TD&gt;
      &lt;TD&gt;IN&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;esalvi&lt;BR /&gt;sameshr&lt;BR /&gt;esalvi&lt;/TD&gt;
      &lt;TD&gt;3&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;121.246.27.18&lt;/TD&gt;
      &lt;TD&gt;CN&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;zonglial&lt;BR /&gt;zonglail&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;220.137.253.128&lt;/TD&gt;
      &lt;TD&gt;TW&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;curun&lt;BR /&gt;is\\curun&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;58.186.87.156&lt;/TD&gt;
      &lt;TD&gt;VN&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;echcao&lt;BR /&gt;ecao&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
    &lt;/TR&gt;
  &lt;/TBODY&gt;
&lt;/TABLE&gt;

&lt;P&gt;So the first thing I wonder about is how I could avoid using this dc(webauth_ucinetid) function twice. Is there a way to do the function the first time and save it and reuse it in the sort?&lt;/P&gt;

&lt;P&gt;The second thing I wonder about is that if there are few enough of these that the top 20 will include instances where the dc count is 1, and I don't really want to see anything that is dc count of 1 because it is not interesting. But I can't figure out how to say that! Also, I'd like to turn this into an alert where it only sends an email if there are results and that the results are where dc count is &amp;gt;1. Can't figure-out how to do this.&lt;/P&gt;

&lt;P&gt;the &lt;CODE&gt;geoip&lt;/CODE&gt; is a macro for a lookup using the GeoIP lite database for country codes, etc., and simply uses the lookup command to use a python script to do this and create the client_country_code field you see being used as 'CC'. This macro has a leading pipe in it.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 10:04:21 GMT</pubDate>
    <dc:creator>wrangler2x</dc:creator>
    <dc:date>2020-09-28T10:04:21Z</dc:date>
    <item>
      <title>How to save the results of a function and reuse them in a search and have a clause based on count of  &gt;1</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106514#M27691</link>
      <description>&lt;P&gt;New to splunk but getting somewhere with learning to construct complex searches. The goal of the search below is to look for instances where multiple login credential failures via a central web-based authentication mechanism are associated with one non-U.S. IP address (client) and that these multiple failures involve more than one user-id (field is called webauth_ucinetid). The approach I took was to use the dc() function to get a count of unique user-ids, and the list() function to put them together as multivalues associated with their given, common, IP address. Here is the search:&lt;/P&gt;

&lt;P&gt;index="syslogs_webauth" webauth_action="login" webauth_success="N" &lt;CODE&gt;geoip&lt;/CODE&gt; | search client_country_code!="US" | stats dc(webauth_ucinetid) List(webauth_ucinetid) AS "UCInetID" count by webauth_ip client_country_code| rename client_country_code AS "CC" | sort -dc(webauth_ucinetid) | head 20&lt;/P&gt;

&lt;P&gt;An example of what the search returns is shown here:&lt;/P&gt;

&lt;TABLE border="1"&gt;
  &lt;TBODY&gt;
    &lt;!-- Results table headers --&gt;
    &lt;TR&gt;
      &lt;TH&gt;webauth_ip&lt;/TH&gt;
      &lt;TH&gt;CC&lt;/TH&gt;
      &lt;TH&gt;dc(webauth_ucinetid)&lt;/TH&gt;
      &lt;TH&gt;UCInetID&lt;/TH&gt;
      &lt;TH&gt;Count&lt;/TH&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;114.143.187.210&lt;/TD&gt;
      &lt;TD&gt;CN&lt;/TD&gt;
      &lt;TD&gt;3&lt;/TD&gt;
      &lt;TD&gt;kbaeki&lt;BR /&gt;cseunggyk&lt;BR /&gt;rhsung&lt;/TD&gt;
      &lt;TD&gt;3&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;120.87.95.70&lt;/TD&gt;
      &lt;TD&gt;IN&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;esalvi&lt;BR /&gt;sameshr&lt;BR /&gt;esalvi&lt;/TD&gt;
      &lt;TD&gt;3&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;121.246.27.18&lt;/TD&gt;
      &lt;TD&gt;CN&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;zonglial&lt;BR /&gt;zonglail&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;220.137.253.128&lt;/TD&gt;
      &lt;TD&gt;TW&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;curun&lt;BR /&gt;is\\curun&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
    &lt;/TR&gt;
    &lt;TR&gt;
      &lt;TD&gt;58.186.87.156&lt;/TD&gt;
      &lt;TD&gt;VN&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
      &lt;TD&gt;echcao&lt;BR /&gt;ecao&lt;/TD&gt;
      &lt;TD&gt;2&lt;/TD&gt;
    &lt;/TR&gt;
  &lt;/TBODY&gt;
&lt;/TABLE&gt;

&lt;P&gt;So the first thing I wonder about is how I could avoid using this dc(webauth_ucinetid) function twice. Is there a way to do the function the first time and save it and reuse it in the sort?&lt;/P&gt;

&lt;P&gt;The second thing I wonder about is that if there are few enough of these that the top 20 will include instances where the dc count is 1, and I don't really want to see anything that is dc count of 1 because it is not interesting. But I can't figure out how to say that! Also, I'd like to turn this into an alert where it only sends an email if there are results and that the results are where dc count is &amp;gt;1. Can't figure-out how to do this.&lt;/P&gt;

&lt;P&gt;the &lt;CODE&gt;geoip&lt;/CODE&gt; is a macro for a lookup using the GeoIP lite database for country codes, etc., and simply uses the lookup command to use a python script to do this and create the client_country_code field you see being used as 'CC'. This macro has a leading pipe in it.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:04:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106514#M27691</guid>
      <dc:creator>wrangler2x</dc:creator>
      <dc:date>2020-09-28T10:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to save the results of a function and reuse them in a search and have a clause based on count of  &gt;1</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106515#M27692</link>
      <description>&lt;P&gt;Edit the stats and sort commands as below.  Add the search command.&lt;/P&gt;

&lt;P&gt;| stats dc(webauth_ucinetid) AS DCOUNT List(webauth_ucinetid) AS "UCInetID" count by webauth_ip client_country_code| rename client_country_code AS "CC" | search DCOUNT &amp;gt; 1 | sort -DCOUNT | head 20&lt;/P&gt;

&lt;P&gt;When you create the alert through the Search App, you can trigger on number of events greater than zero.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 10:05:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106515#M27692</guid>
      <dc:creator>eelisio2</dc:creator>
      <dc:date>2020-09-28T10:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to save the results of a function and reuse them in a search and have a clause based on count of  &gt;1</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106516#M27693</link>
      <description>&lt;P&gt;This works great. Thank you for your answer.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2011 21:54:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-save-the-results-of-a-function-and-reuse-them-in-a-search/m-p/106516#M27693</guid>
      <dc:creator>wrangler2x</dc:creator>
      <dc:date>2011-11-14T21:54:04Z</dc:date>
    </item>
  </channel>
</rss>

