<?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 Can you help me with my query within a query? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447177#M126786</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to see if this type of query is possible&lt;/P&gt;

&lt;P&gt;I am creating an alert base on 2 conditions.&lt;/P&gt;

&lt;P&gt;The first condition must be met and then check the second condition&lt;/P&gt;

&lt;P&gt;First Condition:  tid result be unique and more than 4 results return&lt;BR /&gt;
Second Condition: host must be unique and must be more than 1 hosts&lt;/P&gt;

&lt;P&gt;Query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;("ERROR")|dedup tid|eval hostname=substr(host,1,5)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will return something like this&lt;/P&gt;

&lt;P&gt;Original host name is&lt;/P&gt;

&lt;P&gt;londn1&lt;BR /&gt;
londn2&lt;BR /&gt;
eurpn1&lt;BR /&gt;
eurpn2&lt;/P&gt;

&lt;P&gt;The eval will give me&lt;/P&gt;

&lt;P&gt;londn and eurpn&lt;/P&gt;

&lt;P&gt;I am able to get the first condition working. Once I get the first condition met, I will need to check the result to make sure it comes from more than 1 host (without the 1 and 2 in the hostname).&lt;/P&gt;

&lt;P&gt;How should I go about this?&lt;/P&gt;</description>
    <pubDate>Fri, 26 Oct 2018 16:06:28 GMT</pubDate>
    <dc:creator>mansinchu</dc:creator>
    <dc:date>2018-10-26T16:06:28Z</dc:date>
    <item>
      <title>Can you help me with my query within a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447177#M126786</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to see if this type of query is possible&lt;/P&gt;

&lt;P&gt;I am creating an alert base on 2 conditions.&lt;/P&gt;

&lt;P&gt;The first condition must be met and then check the second condition&lt;/P&gt;

&lt;P&gt;First Condition:  tid result be unique and more than 4 results return&lt;BR /&gt;
Second Condition: host must be unique and must be more than 1 hosts&lt;/P&gt;

&lt;P&gt;Query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;("ERROR")|dedup tid|eval hostname=substr(host,1,5)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will return something like this&lt;/P&gt;

&lt;P&gt;Original host name is&lt;/P&gt;

&lt;P&gt;londn1&lt;BR /&gt;
londn2&lt;BR /&gt;
eurpn1&lt;BR /&gt;
eurpn2&lt;/P&gt;

&lt;P&gt;The eval will give me&lt;/P&gt;

&lt;P&gt;londn and eurpn&lt;/P&gt;

&lt;P&gt;I am able to get the first condition working. Once I get the first condition met, I will need to check the result to make sure it comes from more than 1 host (without the 1 and 2 in the hostname).&lt;/P&gt;

&lt;P&gt;How should I go about this?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Oct 2018 16:06:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447177#M126786</guid>
      <dc:creator>mansinchu</dc:creator>
      <dc:date>2018-10-26T16:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me with my query within a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447178#M126787</link>
      <description>&lt;P&gt;You don't need to overcomplicate your query.  you are just pulling additional information out of what you have already done, not doing another query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search
| stats values(host) as host by tid
| where mvcount(host)&amp;gt;3
| mvexpand host
| eval shost=substr(host,1,5)
| stats values(host) as host values(shost) as shost by tid
| where mvcount(shost) &amp;gt; 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Of course, once you review that code, you really don't need to put it together, pull it all apart and put it back together again.&lt;/P&gt;

&lt;P&gt;Just do it this way... &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search
| eval shost=substr(host,1,5)
| stats values(host) as host values(shost) as shost by tid
| where mvcount(shost) &amp;gt; 1 AND mvcount(host)&amp;gt;3
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Oct 2018 22:19:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447178#M126787</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2018-10-26T22:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me with my query within a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447179#M126788</link>
      <description>&lt;P&gt;@DalJeanis &lt;/P&gt;

&lt;P&gt;Can we use mvcount  to get result requested in the question?&lt;BR /&gt;
Let's say we have multi-valued field like cve&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;cve
CVE-2011-0653;CVE-2011-1252;CVE-2011-1890;CVE-2011-1891;CVE-2011-1892;CVE-2011-1893
CVE-2011-0653;CVE-2011-1252;CVE-2011-1890;CVE-2011-1891;CVE-2011-1892
CVE-2011-0653;CVE-2011-1252;CVE-2011-1890
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then we can apply &lt;BR /&gt;
...|eval cvecount=mvcount(split(cve,";)) &lt;/P&gt;

&lt;P&gt;That will give us result &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;cvecount cve
6               CVE-2011-0653;CVE-2011-1252;CVE-2011-1890;CVE-2011-1891;CVE-2011-1892;CVE-2011-1893
5               CVE-2011-0653;CVE-2011-1252;CVE-2011-1890;CVE-2011-1891;CVE-2011-1892
3               CVE-2011-0653;CVE-2011-1252;CVE-2011-1890
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;@mansinchu  , I believe, wants to accomplish the following :&lt;/P&gt;

&lt;P&gt;Alert needs to be triggered when number of unique tid values is more than 4 with numbers of unique host values more than one&lt;/P&gt;

&lt;P&gt;For example:&lt;BR /&gt;
These results should trigger the alert  : 5 unique tid  with  2  unique hosts (londn and eurpn)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host        tid
londn       123
londn        456
eurpn        786
eurpn        910
eurpn        135
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;These results should not trigger the alert: 4 unique tid values but with just one unique host londh&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host        tid
londn       123
londn        456
londn       786
londn        910
londn        135
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Oct 2018 03:07:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447179#M126788</guid>
      <dc:creator>mlevsh</dc:creator>
      <dc:date>2018-10-27T03:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can you help me with my query within a query?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447180#M126789</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Oct 2018 13:50:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-you-help-me-with-my-query-within-a-query/m-p/447180#M126789</guid>
      <dc:creator>mansinchu</dc:creator>
      <dc:date>2018-10-29T13:50:29Z</dc:date>
    </item>
  </channel>
</rss>

