<?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: Make map command process values in series in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314893#M94247</link>
    <description>&lt;P&gt;No problem! &lt;/P&gt;</description>
    <pubDate>Fri, 07 Apr 2017 16:05:23 GMT</pubDate>
    <dc:creator>iKate</dc:creator>
    <dc:date>2017-04-07T16:05:23Z</dc:date>
    <item>
      <title>Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314886#M94240</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;

&lt;P&gt;How can I make  &lt;CODE&gt;map&lt;/CODE&gt; command process all the list of submitted to its input values(thousands), not just the number of maxsearches. I don't need to run all the queries simultaniously, it will be ok to run it in series by chunks of maxsearches or even one search at a time.&lt;/P&gt;

&lt;P&gt;What I need to do at the moment is to match clientip (no subnet information) with an integer range of ip-s from lookup file to define ASN of each IP.&lt;/P&gt;

&lt;P&gt;Here is my query, maybe you can suggest how to rewrite it.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| table clientip
| rex field=clientip "(?&amp;lt;o1&amp;gt;(\d)+).(?&amp;lt;o2&amp;gt;(\d)+).(?&amp;lt;o3&amp;gt;(\d)+).(?&amp;lt;o4&amp;gt;(\d)+)"
| eval integer_ip=16777216*o1+65536*o2+256*o3+o4
| map search="| inputlookup GeoIPASNum2.csv | where start&amp;lt;=$integer_ip$ AND end&amp;gt;=$integer_ip$ | eval clientip=$clientip$ | table clientip ASN " maxsearches=10
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Lookup file looks like this and was dowloaded from &lt;A href="http://dev.maxmind.com/geoip/legacy/geolite/"&gt;Maxmind&lt;/A&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ASN                        range_start       range_end  
"AS56203 Big Red Group"       16778240            16779007
...     
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 19:50:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314886#M94240</guid>
      <dc:creator>iKate</dc:creator>
      <dc:date>2017-04-06T19:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314887#M94241</link>
      <description>&lt;P&gt;Here's a run-anywhere proof of concept for turning that lookup table into a big honking case statement at run time.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval test="1 5 11" | makemv test | mvexpand test | rename test as integer_ip
| eval ASN= 
    [
    | makeresults  
    | eval mydata = "1,3,A 4,7,B 8,12,C" 
    | makemv mydata 
    | mvexpand mydata 
    | makemv delim="," mydata 
    | eval XXX1=mvindex(mydata,0),XXX2=mvindex(mydata,1),XXX3=mvindex(mydata,2) 
    | table XXX1 XXX2 XXX3 
    | format "case(" "" AND "," "" "true(),\"unknown\")" 
    | rex field=search mode=sed "s/XXX1=\"/integer_ip&amp;gt;=/g" 
    | rex field=search mode=sed "s/XXX2=\"/integer_ip&amp;lt;=/g"
    | rex field=search mode=sed "s/\" AND/ AND/g"
    | rex field=search mode=sed "s/AND XXX3=/,/g"
    | table search
    ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;so your code would look like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| table clientip
| rex field=clientip "(?&amp;lt;o1&amp;gt;(\d)+).(?&amp;lt;o2&amp;gt;(\d)+).(?&amp;lt;o3&amp;gt;(\d)+).(?&amp;lt;o4&amp;gt;(\d)+)"
| eval integer_ip=16777216*o1+65536*o2+256*o3+o4
| eval ASN= 
    [
    | inputlookup GeoIPASNum2.csv  
    | rename  start as XXX1, end as XXX2, ASN as XXX3     
    | table XXX1 XXX2 XXX3 
    | format "case(" "" AND "," "" "true(),\"unknown\")" 
    | rex field=search mode=sed "s/XXX1=\"/integer_ip&amp;gt;=/g" 
    | rex field=search mode=sed "s/XXX2=\"/integer_ip&amp;lt;=/g"
    | rex field=search mode=sed "s/\" AND/ AND/g"
    | rex field=search mode=sed "s/AND XXX3=/,/g"
    | table search
    ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The renames turned out to be necessary in order to force the sort order of the terms before converting to a case statement.  I just used generic XXX# as the field names, because the order would then be fixed and obvious.&lt;/P&gt;

&lt;P&gt;I do not know whether this method is totally practical, which will depend on the number of IP records and the splunk limits to the size of a final expanded search string, but I thought it would be a fun thing to try.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Apr 2017 22:52:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314887#M94241</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-04-06T22:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314888#M94242</link>
      <description>&lt;P&gt;I would not recommend using the map command for this use case. Map is better for a small number of results, but won't scale to thousands. &lt;/P&gt;

&lt;P&gt;CIDR lookups are designed to do exactly what you're describing. Checkout this post for an example: &lt;A href="https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html"&gt;https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;For the MaxMind GeoLite ASN data, it looks like someone has already built a TA to solve the exact problem you're describing: &lt;A href="https://splunkbase.splunk.com/app/3531/"&gt;https://splunkbase.splunk.com/app/3531/&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;It ships with a CIDR lookup too, so you can simply do this after it's been installed:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...your base search... | lookup asn ip as clientip OUTPUT asn autonomous_system | table clientip asn autonomous_system
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;After you install, make sure you populate the initial asn lookup using the query shown in the TA's screenshot as well.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 00:30:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314888#M94242</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2017-04-07T00:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314889#M94243</link>
      <description>&lt;P&gt;@iKate... I am able to use where with &amp;lt; and &amp;gt; comparison in Splunk search but the same fails in Dashboard with &lt;CODE&gt;&amp;amp;lt;&lt;/CODE&gt; and &lt;CODE&gt;&amp;amp;gt;&lt;/CODE&gt; for map command. Following is run anywhere example (I checked with both where and search command inside map query but both have same behavior).&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults 
 | eval clientip="101.201.100.99"
 | rex field=clientip "(?&amp;lt;o1&amp;gt;(\d)+).(?&amp;lt;o2&amp;gt;(\d)+).(?&amp;lt;o3&amp;gt;(\d)+).(?&amp;lt;o4&amp;gt;(\d)+)"
 | eval integer_ip=16777216*o1+65536*o2+256*o3+o4
 | table integer_ip clientip
 | map search="| makeresults | eval range_start=16778240 | eval range_end=16779007 | eval asn=\"Big Red Group\"| where range_start&amp;lt;=$integer_ip$ AND range_end&amp;lt;=$integer_ip$| eval clientip=$clientip$| eval integer_ip=$integer_ip$| table clientip integer_ip asn range_start range_end"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Apr 2017 09:05:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314889#M94243</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-07T09:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314890#M94244</link>
      <description>&lt;P&gt;Wow! Looks like this app was made exeptionally for me) After installing it I'll write results here.&lt;BR /&gt;
Thank you!  &lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 10:51:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314890#M94244</guid>
      <dc:creator>iKate</dc:creator>
      <dc:date>2017-04-07T10:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314891#M94245</link>
      <description>&lt;P&gt;What a trick!:) I've never used either &lt;CODE&gt;format&lt;/CODE&gt; command or &lt;CODE&gt;sed&lt;/CODE&gt; mode in rex, so after learning their syntax I see it can really work well in cases when you have not that many events. In my situation with several hundreds of thousands rows it won't work well in &lt;CODE&gt;case&lt;/CODE&gt; clause I guess) But anyways this construction can help in other cases when I would try to use map previously. Thanks! Great insight of splunk commands' usage.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 13:00:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314891#M94245</guid>
      <dc:creator>iKate</dc:creator>
      <dc:date>2017-04-07T13:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314892#M94246</link>
      <description>&lt;P&gt;I suspected as much.  &lt;/P&gt;

&lt;P&gt;Upvote answers if you like them or find them useful, even if they didn't completely solve your issue.  &lt;/P&gt;

&lt;P&gt;Accept the best one that actually helped in the solution.  &lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 14:02:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314892#M94246</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-04-07T14:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314893#M94247</link>
      <description>&lt;P&gt;No problem! &lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 16:05:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314893#M94247</guid>
      <dc:creator>iKate</dc:creator>
      <dc:date>2017-04-07T16:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314894#M94248</link>
      <description>&lt;P&gt;This app works exactly how I need!  But first I needed to fix a python code a bit) &lt;/P&gt;

&lt;P&gt;After installing the app and setting proxies an error occured: &lt;BR /&gt;
 NameError at "/opt/splunk/etc/apps/TA-asngen/bin/asngen.py", line 37 : global name 'ProxyHandler' is not defined &lt;BR /&gt;
It was fixed by adding &lt;CODE&gt;import urllib2&lt;/CODE&gt; and putting prefix &lt;CODE&gt;urllib2&lt;/CODE&gt; this part of code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if proxies['http'] is not None or proxies['https'] is not None:
            proxy = urllib2.ProxyHandler(proxies)
            opener = urllib2.build_opener(proxy)
            urllib2.install_opener(opener)

        try:
            url = urllib2.urlopen("https://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2.zip")
        except:
            raise Exception("Please check app proxy settings")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Than created an entry in transforms.conf as described here &lt;A href="https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html"&gt;https://answers.splunk.com/answers/5916/using-cidr-in-a-lookup-table.html&lt;/A&gt;&lt;BR /&gt;
Increased limit for lookup &lt;CODE&gt;max_memtable_bytes=20000000&lt;/CODE&gt;&lt;BR /&gt;
Reloaded configs and done! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 18:33:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314894#M94248</guid>
      <dc:creator>iKate</dc:creator>
      <dc:date>2017-04-07T18:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314895#M94249</link>
      <description>&lt;P&gt;Awesome! Glad this worked for you. I upvoted your comment for sharing that fix too. I am sure it will help others in the future. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Apr 2017 22:47:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314895#M94249</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2017-04-07T22:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314896#M94250</link>
      <description>&lt;P&gt;I think this app just came our (or a new version was recently released) so contact the author so he can fix it.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2017 03:34:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314896#M94250</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-08T03:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314897#M94251</link>
      <description>&lt;P&gt;@DalJeanis, great idea&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2017 06:15:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314897#M94251</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-04-08T06:15:15Z</dc:date>
    </item>
    <item>
      <title>Re: Make map command process values in series</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314898#M94252</link>
      <description>&lt;P&gt;Already. I was even mentioned) &lt;A href="https://splunkbase.splunk.com/app/3531/"&gt;https://splunkbase.splunk.com/app/3531/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Apr 2017 12:20:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Make-map-command-process-values-in-series/m-p/314898#M94252</guid>
      <dc:creator>iKate</dc:creator>
      <dc:date>2017-04-08T12:20:40Z</dc:date>
    </item>
  </channel>
</rss>

