<?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: A search that makes searches and executes them in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286934#M86858</link>
    <description>&lt;P&gt;Hi Martin,&lt;/P&gt;

&lt;P&gt;Thanks for taking some time to review and provide feedback.&lt;/P&gt;

&lt;P&gt;I will edit the search in the question to include the appropriately ordered syntax; I re-ordered the query a bit while I was posting in an attempt to make it a bit more readable and thought through.&lt;/P&gt;

&lt;P&gt;Assembling one large regex, while it would return results, will not reach my end goal which would include the "Comment" field from the lookup.  I assumed that multisearch would allow for transforming commands such as adding a:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(Comment) AS Comment values(uri) AS uri by domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However multisearch will not do that:  Error in 'multisearch' command: Multisearch subsearches may only contain purely streaming operations (subsearch 1 contains a non-streaming command.) &lt;/P&gt;

&lt;P&gt;So I am left with a scenario where I have two columns in a CSV with multiple rows:  RegEx, Comment&lt;/P&gt;

&lt;P&gt;I want to search my proxy logs for matches on each regex in order to return the Comment, domain, and uri by domain.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Apr 2016 17:30:34 GMT</pubDate>
    <dc:creator>rkoster</dc:creator>
    <dc:date>2016-04-12T17:30:34Z</dc:date>
    <item>
      <title>A search that makes searches and executes them</title>
      <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286932#M86856</link>
      <description>&lt;P&gt;So I have this search that I believe makes other searches from a list of regexs that I have stored in a csv.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ | inputlookup regex_test.csv
| eval search_this = "[search sourcetype=proxy | eval Comment=\""+Comment+"\" | regex uri=\""+RegEx+"\"]"
| stats values(search_this) AS all_searches
| eval search="| multisearch "
| eval search=search+mvjoin(all_searches, " ")
| fields search ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The above search fails:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Search process did not exit cleanly, exit_code=0, description="killed by signal 6: Aborted". Please look in search.log for this peer in the Job Inspector for more info.
 This search has encountered a fatal error and has been marked as zombied.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However the search that is created from the query above does not fail when you input into the search bar (yes it returns results on match):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | multisearch [search sourcetype=proxy| eval Comment="EITest v1" | regex uri="^http:\/\/(?:(?!www|authorize|sdranch|azbar|finra|porsche|money|blog|forums?|it)[^\x2e]+\.[^\x2e]+\.com[^\x2f]*|[^\x2e]+\.tk)\/[ik](?=[^\n]{0,500}[a-z\x2d]{17,100})(?=[^\n]{0,500}[a-z\/\x2d]{60,200})(?:[a-z\x2d]+\/){4,32}(?:index\.html)?$"] [search sourcetype=proxy| eval Comment="EITest v2" | regex uri="^http:\/\/[^\x2f]+\.[a-z]{2}\/(?=[^\x3f]+[a-z0-9]{17,}\/)(?:[a-z0-9]+\/){2,}(?:index\.php)?$"] 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Apart from additional caffeine, what am I missing to make this great success? &lt;/P&gt;

&lt;P&gt;Have I chosen the wrong command or the wrong way to go about creating this search of searches?  The goal is to have a list of RegEx,Comment and search for matches against each RegEx in the list.&lt;/P&gt;

&lt;P&gt;Thanks for taking some time to think about this one!&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2016 22:46:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286932#M86856</guid>
      <dc:creator>rkoster</dc:creator>
      <dc:date>2016-04-08T22:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: A search that makes searches and executes them</title>
      <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286933#M86857</link>
      <description>&lt;P&gt;Your search string assembly cannot work like that. After the &lt;CODE&gt;stats&lt;/CODE&gt; you have only one field, &lt;CODE&gt;all_searches&lt;/CODE&gt;. Then you do something with "multisearch", but immediately overwrite that in the final &lt;CODE&gt;eval&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Additionally, the &lt;CODE&gt;multisearch&lt;/CODE&gt; approach is inherently slow if all you want is to test a set of regular expressions. Instead, you could assemble one large regular expression made up of your individual expressions separated with an or'ing pipe.&lt;/P&gt;

&lt;P&gt;Lastly, you mention &lt;CODE&gt;Comment&lt;/CODE&gt; - how does that fit into your search? I can't see that referenced anywhere.&lt;/P&gt;</description>
      <pubDate>Sun, 10 Apr 2016 16:10:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286933#M86857</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-04-10T16:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: A search that makes searches and executes them</title>
      <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286934#M86858</link>
      <description>&lt;P&gt;Hi Martin,&lt;/P&gt;

&lt;P&gt;Thanks for taking some time to review and provide feedback.&lt;/P&gt;

&lt;P&gt;I will edit the search in the question to include the appropriately ordered syntax; I re-ordered the query a bit while I was posting in an attempt to make it a bit more readable and thought through.&lt;/P&gt;

&lt;P&gt;Assembling one large regex, while it would return results, will not reach my end goal which would include the "Comment" field from the lookup.  I assumed that multisearch would allow for transforming commands such as adding a:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats values(Comment) AS Comment values(uri) AS uri by domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However multisearch will not do that:  Error in 'multisearch' command: Multisearch subsearches may only contain purely streaming operations (subsearch 1 contains a non-streaming command.) &lt;/P&gt;

&lt;P&gt;So I am left with a scenario where I have two columns in a CSV with multiple rows:  RegEx, Comment&lt;/P&gt;

&lt;P&gt;I want to search my proxy logs for matches on each regex in order to return the Comment, domain, and uri by domain.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 17:30:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286934#M86858</guid>
      <dc:creator>rkoster</dc:creator>
      <dc:date>2016-04-12T17:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: A search that makes searches and executes them</title>
      <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286935#M86859</link>
      <description>&lt;P&gt;I see... this is slightly hacky, but should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=proxy [inputlookup regex_test.csv | eval search = "| eval Comment = if(match(uri, \"".RegEx."\"), \"".Comment."\", Comment) " | fields search | mvcombine search | nomv search] | stats values(Comment) AS Comment values(uri) AS uri by domain
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Depending on how frequently you update your lookup, you might want to take a look at my Regex IDS app at &lt;A href="https://splunkbase.splunk.com/app/2805/"&gt;https://splunkbase.splunk.com/app/2805/&lt;/A&gt; - I'm sure that approach can be modified to fit your case in a less hacky way.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 19:15:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286935#M86859</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2016-04-12T19:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: A search that makes searches and executes them</title>
      <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286936#M86860</link>
      <description>&lt;P&gt;I think that will work!  Thank you! &lt;/P&gt;

&lt;P&gt;It is important that the Comment field within the CSV has any quotes escaped otherwise the eval command that is created terminates too early.&lt;/P&gt;

&lt;P&gt;To remove the non-matching regexs (to set this up for an alarm) I added this to your query: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where Comment!=""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As implemented here is the full query:&lt;BR /&gt;
     sourcetype=proxy&lt;BR /&gt;
     [ inputlookup regexs.csv &lt;BR /&gt;
     | eval search = "| eval Comment = if(match(uri, \"".RegEx."\"), \"".Comment."\", Comment) " &lt;BR /&gt;
     | fields search &lt;BR /&gt;
     | mvcombine search&lt;BR /&gt;
     | nomv search&lt;BR /&gt;
     ]&lt;BR /&gt;
    | stats values(Comment) AS Comment by uri&lt;BR /&gt;
    | where Comment!=""&lt;/P&gt;</description>
      <pubDate>Tue, 12 Apr 2016 22:42:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286936#M86860</guid>
      <dc:creator>rkoster</dc:creator>
      <dc:date>2016-04-12T22:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: A search that makes searches and executes them</title>
      <link>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286937#M86861</link>
      <description>&lt;P&gt;Take a look at this Q&amp;amp;A for a solution that you should be able to modify to fit:&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/386488/regex-in-lookuptable.html#answer-387536"&gt;https://answers.splunk.com/answers/386488/regex-in-lookuptable.html#answer-387536&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Apr 2016 13:45:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/A-search-that-makes-searches-and-executes-them/m-p/286937#M86861</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2016-04-29T13:45:06Z</dc:date>
    </item>
  </channel>
</rss>

