<?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: Matching rex-defined fields against a csv file containing subnets in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39987#M7435</link>
    <description>&lt;P&gt;You supply &lt;CODE&gt;cidrmatch&lt;/CODE&gt; with a string, &lt;CODE&gt;"[|inputcsv networks.csv | fields network]"&lt;/CODE&gt;. &lt;CODE&gt;cidrmatch&lt;/CODE&gt; doesn't find your IP in that string. So to be clear, that will NOT interpreted as a subsearch. Even if it did, it wouldn't work unfortunately - the default output from a subsearch is formatted to be understood by the &lt;CODE&gt;search&lt;/CODE&gt; command. You could reformat it, but it wouldn't help since &lt;CODE&gt;cidrmatch&lt;/CODE&gt; takes &lt;EM&gt;one&lt;/EM&gt; subnet to match an IP against, not multiple subnets.&lt;/P&gt;

&lt;P&gt;My suggestion is that, because the &lt;CODE&gt;search&lt;/CODE&gt; command itself handles CIDR matching just fine, you could just use your subsearch with that instead.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"DHCPREQUEST for" | rex field=_raw "DHCPREQUEST for (?&amp;lt;ip&amp;gt;\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)" | search [|inputcsv networks.csv | rename network as ip | fields ip]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should expand to something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | search ((ip="123.123.123.0/24") OR (ip="123.123.124.0/24") OR (ip="123.123.125.0/24"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which is a format that the search command understands.&lt;/P&gt;</description>
    <pubDate>Tue, 21 Aug 2012 08:57:55 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2012-08-21T08:57:55Z</dc:date>
    <item>
      <title>Matching rex-defined fields against a csv file containing subnets</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39986#M7434</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I've RTFM many times but can't seem to figure this out.. I am creating a new field ("ip") based on a simple search for Servers requesting an IP via DHCP:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DHCPREQUEST for" | rex field=_raw "DHCPREQUEST for (?ip\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;this returns a few thousand lines and polulates the field "ip".&lt;/P&gt;

&lt;P&gt;Now I create a networks.csv in the following format:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;network
123.123.123.0/24
123.123.124.0/24
123.123.125.0/24
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I am trying to only display hosts that match one of the networks in the .csv file:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"DHCPREQUEST for" | rex field=_raw "DHCPREQUEST for (?ip\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)" | where cidrmatch("[|inputcsv networks.csv | fields network]",ip)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which returns zero results. Running only the subsearch returns the list of networks as expected.&lt;/P&gt;

&lt;P&gt;What am I doing wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 08:32:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39986#M7434</guid>
      <dc:creator>sthomas</dc:creator>
      <dc:date>2012-08-21T08:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rex-defined fields against a csv file containing subnets</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39987#M7435</link>
      <description>&lt;P&gt;You supply &lt;CODE&gt;cidrmatch&lt;/CODE&gt; with a string, &lt;CODE&gt;"[|inputcsv networks.csv | fields network]"&lt;/CODE&gt;. &lt;CODE&gt;cidrmatch&lt;/CODE&gt; doesn't find your IP in that string. So to be clear, that will NOT interpreted as a subsearch. Even if it did, it wouldn't work unfortunately - the default output from a subsearch is formatted to be understood by the &lt;CODE&gt;search&lt;/CODE&gt; command. You could reformat it, but it wouldn't help since &lt;CODE&gt;cidrmatch&lt;/CODE&gt; takes &lt;EM&gt;one&lt;/EM&gt; subnet to match an IP against, not multiple subnets.&lt;/P&gt;

&lt;P&gt;My suggestion is that, because the &lt;CODE&gt;search&lt;/CODE&gt; command itself handles CIDR matching just fine, you could just use your subsearch with that instead.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"DHCPREQUEST for" | rex field=_raw "DHCPREQUEST for (?&amp;lt;ip&amp;gt;\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)" | search [|inputcsv networks.csv | rename network as ip | fields ip]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should expand to something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | search ((ip="123.123.123.0/24") OR (ip="123.123.124.0/24") OR (ip="123.123.125.0/24"))
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which is a format that the search command understands.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 08:57:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39987#M7435</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-08-21T08:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rex-defined fields against a csv file containing subnets</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39988#M7436</link>
      <description>&lt;P&gt;This works, thanks. I wasnt aware of the different formatting within a subsearch. Not having to use cidrmatch makes it a lot easier too. ty!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 09:28:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39988#M7436</guid>
      <dc:creator>sthomas</dc:creator>
      <dc:date>2012-08-21T09:28:54Z</dc:date>
    </item>
    <item>
      <title>Re: Matching rex-defined fields against a csv file containing subnets</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39989#M7437</link>
      <description>&lt;P&gt;You can see exactly what a search will return if run as a subsearch by just running it on its own and appending ´| format&lt;CODE&gt;at the end. The&lt;/CODE&gt;format` command is run implicitly by subsearches.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 09:30:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Matching-rex-defined-fields-against-a-csv-file-containing/m-p/39989#M7437</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-08-21T09:30:44Z</dc:date>
    </item>
  </channel>
</rss>

