<?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: Join Ip with a subnet in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46135#M11021</link>
    <description>&lt;P&gt;See update above with a complete example.  Just as advice, I would not call this a "JOIN" - you are thinking too much in SQL terms.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Aug 2012 04:49:39 GMT</pubDate>
    <dc:creator>dwaddle</dc:creator>
    <dc:date>2012-08-31T04:49:39Z</dc:date>
    <item>
      <title>Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46129#M11015</link>
      <description>&lt;P&gt;I am trying to search from source A that contains IP and trying to lookup IP location from source B where source B contains location and subnet information.&lt;/P&gt;

&lt;P&gt;Example:&lt;/P&gt;

&lt;P&gt;source="A" ip="192.168.0.23"&lt;BR /&gt;
source="B" iprange="192.168.0.0/16" location="building_a"&lt;/P&gt;

&lt;P&gt;Example Result: ( table ip, location )&lt;BR /&gt;
ip                  location&lt;BR /&gt;
192.168.0.23        building_a&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2012 22:15:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46129#M11015</guid>
      <dc:creator>kjiwatrakan</dc:creator>
      <dc:date>2012-08-28T22:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46130#M11016</link>
      <description>&lt;P&gt;You will probably need to use the &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;cidrmatch&lt;/A&gt; function for eval/where.&lt;/P&gt;

&lt;P&gt;To get you started...&lt;/P&gt;</description>
      <pubDate>Tue, 28 Aug 2012 22:36:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46130#M11016</guid>
      <dc:creator>MHibbin</dc:creator>
      <dc:date>2012-08-28T22:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46131#M11017</link>
      <description>&lt;P&gt;It sounds like your "source B" should be a lookup table instead of indexed data.  You can define a lookup with a &lt;CODE&gt;match_type&lt;/CODE&gt; for a given field of &lt;CODE&gt;CIDR&lt;/CODE&gt;, which should let you maintain your source B as a simple CSV file that is used by Splunk to update your events.&lt;/P&gt;

&lt;P&gt;A good starting point is at &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/User/CreateAndConfigureFieldLookups"&gt;http://docs.splunk.com/Documentation/Splunk/latest/User/CreateAndConfigureFieldLookups&lt;/A&gt;&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Update:  A working example&lt;/P&gt;

&lt;P&gt;Put into &lt;CODE&gt;$SPLUNK_HOME/etc/system/lookups/ip_lookup.csv&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;ip,location
1.2.3.0/24,site_1
4.0.0.0/8,site_2
11.2.2.0/24,site_3_floor_1_zone_1
11.2.0.0/16,site_3_floor_1
11.0.0.0/8,site_3
0.0.0.0/0,internet
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Put into &lt;CODE&gt;$SPLUNK_HOME/etc/system/default/transforms.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ip_lookup]
filename = ip_lookup.csv
match_type = CIDR(ip)
max_matches = 1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Using these sample events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Thu Aug 30 23:31:27 CDT 2012 ip=1.2.3.4
Thu Aug 30 23:31:35 CDT 2012 ip=4.5.6.7
Thu Aug 30 23:31:43 CDT 2012 ip=192.168.1.1
Thu Aug 30 23:31:56 CDT 2012 ip=11.2.2.2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;A search of the form:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=foo ip=* 
| lookup ip_lookup ip OUTPUT location 
| table ip,location
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Produces these results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ip            location
----------- ---------------------
11.2.2.2    site_3_floor_1_zone_1
192.168.1.1 internet
4.5.6.7     site_2
1.2.3.4     site_1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note that Splunk's CIDR matching rules are on the first matching CIDR entry in the lookup table, so I had to put more specific subnets of &lt;CODE&gt;11.0.0.0/8&lt;/CODE&gt; first in the file, and I had to put &lt;CODE&gt;0.0.0.0/0&lt;/CODE&gt; last in the file for it to work right.&lt;/P&gt;

&lt;P&gt;UPDATE 09 Sept:  Like any other lookup, you can enable this lookup to fire automatically for a &lt;CODE&gt;sourcetype&lt;/CODE&gt;, &lt;CODE&gt;source&lt;/CODE&gt;, or &lt;CODE&gt;host&lt;/CODE&gt;.  This is easily done via an update to &lt;CODE&gt;props.conf&lt;/CODE&gt;.  To enable this lookup for a &lt;CODE&gt;sourcetype&lt;/CODE&gt; of &lt;CODE&gt;foo&lt;/CODE&gt;, add to &lt;CODE&gt;props.conf&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[foo]
LOOKUP-iplookup = ip_lookup ip OUTPUTNEW location
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, I can run the search above without the explicit &lt;CODE&gt;lookup&lt;/CODE&gt; command:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=foo ip=* 
| table ip,location
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And I get the same results as before:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ip            location
----------- ---------------------
11.2.2.2    site_3_floor_1_zone_1
192.168.1.1 internet
4.5.6.7     site_2
1.2.3.4     site_1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Aug 2012 22:49:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46131#M11017</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2012-08-28T22:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46132#M11018</link>
      <description>&lt;P&gt;You can use scheduled searches to maintain such a lookup table from your indexed data (&lt;CODE&gt;outputlookup&lt;/CODE&gt;). If this information changes over time, you can create and maintain a time-based lookup to get accurate results for events from the past.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2012 07:18:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46132#M11018</guid>
      <dc:creator>ziegfried</dc:creator>
      <dc:date>2012-08-29T07:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46133#M11019</link>
      <description>&lt;P&gt;Can you please provide an example on how to use lookup as part of the search if my lookup source is iprangeLocation.csv.  The file contains iprange and location column.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2012 18:17:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46133#M11019</guid>
      <dc:creator>kjiwatrakan</dc:creator>
      <dc:date>2012-08-29T18:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46134#M11020</link>
      <description>&lt;P&gt;Can anyone please help me write a sample query to join data from logs to the lookup table match by cidr to get location? &lt;/P&gt;

&lt;P&gt;Thank you,&lt;/P&gt;</description>
      <pubDate>Thu, 30 Aug 2012 14:43:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46134#M11020</guid>
      <dc:creator>kjiwatrakan</dc:creator>
      <dc:date>2012-08-30T14:43:52Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46135#M11021</link>
      <description>&lt;P&gt;See update above with a complete example.  Just as advice, I would not call this a "JOIN" - you are thinking too much in SQL terms.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Aug 2012 04:49:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46135#M11021</guid>
      <dc:creator>dwaddle</dc:creator>
      <dc:date>2012-08-31T04:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46136#M11022</link>
      <description>&lt;P&gt;Awesome and double awesome.  This is a perfect example.  I guess this answer would be ideal for a lot of problems that a lot of people are facing. +1 in my book.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2012 16:45:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46136#M11022</guid>
      <dc:creator>kjiwatrakan</dc:creator>
      <dc:date>2012-09-04T16:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Join Ip with a subnet</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46137#M11023</link>
      <description>&lt;P&gt;Amazing - thank you !&lt;/P&gt;</description>
      <pubDate>Wed, 16 Mar 2016 11:15:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Join-Ip-with-a-subnet/m-p/46137#M11023</guid>
      <dc:creator>rusty009</dc:creator>
      <dc:date>2016-03-16T11:15:02Z</dc:date>
    </item>
  </channel>
</rss>

